CodeBlanks Logo Icon CodeBlanks

Production design

Design the architecture of a production app.

Project: a production-ready deployment

You'll make the shop application from the intermediate project production-ready. To be added:

  1. Database: a StatefulSet with a persistent disk and a headless service
  2. External access: an Ingress with a domain name and HTTPS
  3. Load: an HPA for the API
  4. Security: an application-specific ServiceAccount and least privilege
  5. Packaging: all the parts in a single Helm chart
magaza/
  Chart.yaml
  values.yaml
  values-prod.yaml
  templates/
    db-statefulset.yaml   db-service.yaml
    api-deployment.yaml   api-service.yaml   api-hpa.yaml
    web-deployment.yaml   web-service.yaml
    ingress.yaml          serviceaccount.yaml

Designing the values

A good values.yaml exposes everything likely to change and gives safe defaults for development; the production file only contains the differences:

# values.yaml
image:
  api: ghcr.io/ali/magaza-api
  tag: ""              # if empty, Chart.appVersion
api:
  replicas: 1
  autoscaling: {enabled: false, min: 2, max: 10, cpu: 70}
ingress:
  enabled: false
  host: magaza.local

# values-prod.yaml
api:
  autoscaling: {enabled: true}
ingress:
  enabled: true
  host: magaza.example.com

Practice Production values

Write the contents of values-prod.yaml: api.autoscaling.enabled: true; under ingress, enabled: true and host: magaza.example.com; db.storage: 20Gi.

Starter code

terminal
# values-prod.yaml
# buraya yaz

Sample solution

terminal
# values-prod.yaml
api:
  autoscaling:
    enabled: true
ingress:
  enabled: true
  host: magaza.example.com
db:
  storage: 20Gi

Expected output

$ helm template magaza ./magaza -f values-prod.yaml | grep -c "^kind:"
10

Questions and answers

Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.

1 Where is it best to keep environment-specific differences (replica count, domain name)?

  • In separate chart copies
  • By entering the pods by hand
  • In environment-specific values files (values-prod.yaml) Correct answer
  • Hard-coded inside the templates

Explanation: The templates stay the same; only the values change.

2 Create the chart skeleton.

Question
helm ____ magaza
Answer
helm create magaza

Explanation: helm create produces a sample chart.

3 Match.

Term Meaning
StatefulSet Database
Ingress HTTPS and domain
HPA API scaling
values-prod.yaml Production differences

All lessons in Advanced