Docker & Kubernetes
Putting it together - production
Apply all resources to deploy the production app.
Putting it together: the production rollout
In the last step the chart is deployed to production with a single command and the deployment is verified end to end. A safe CI step does the following: lints the chart, shows the difference, upgrades with --atomic (rolls back on failure) and tests the external address:
helm lint ./magaza -f values-prod.yaml
helm upgrade --install magaza ./magaza -n magaza -f values-prod.yaml \
--set image.tag=$GIT_SHA --atomic --timeout 10m
kubectl get all,ing,hpa,pvc -n magaza
curl -fsS https://magaza.example.com/api/saglik
The rollback plan
Every production deployment must have a rollback path. Helm revisions bring the application version back; but database migrations may not be reversible; that's why migrations are written backward-compatibly (first add the column, then use it, finally remove the old one):
helm history magaza -n magaza
REVISION STATUS APP VERSION DESCRIPTION
11 superseded 1.4.2 Upgrade complete
12 deployed 1.5.0 Upgrade complete
helm rollback magaza 11 -n magaza --wait
Exercise Deploy to production
Write four commands: lint ./magaza with values-prod.yaml; upgrade the magaza release in the magaza namespace, installing it if missing, with values-prod.yaml, --set image.tag=$GIT_SHA, --atomic and --timeout 10m; list the all,ing,hpa,pvc objects in magaza; test with curl -fsS https://magaza.example.com/api/saglik.
Show example solution
helm lint ./magaza -f values-prod.yaml
helm upgrade --install magaza ./magaza -n magaza -f values-prod.yaml --set image.tag=$GIT_SHA --atomic --timeout 10m
kubectl get all,ing,hpa,pvc -n magaza
curl -fsS https://magaza.example.com/api/saglik
Test yourself
-
Why is the Git commit hash (GIT_SHA) used for image.tag?
- Because it equals latest
- Because Helm requires it
- Each deployment shows exactly which code version runs, and it can be rolled back
- Because it's shorter
Show answer
Each deployment shows exactly which code version runs, and it can be rolled back — Immutable tags are the basis of reproducible deployments.
-
Automatically roll back a failed upgrade.
helm upgrade --install magaza ./magaza -n magaza -f values-prod.yaml ____ --timeout 10m
Show answer
helm upgrade --install magaza ./magaza -n magaza -f values-prod.yaml --atomic --timeout 10m
-
Match.
- helm lint
- Check first
- --atomic
- Roll back on failure
- GIT_SHA etiketi
- Exact version
- curl -fsS
- External test
Next lesson: Challenge - Ingress