76.2 Project 41: Package an app as a Helm chart
Friends, Helm turns many YAML files into one chart with values. Today we write Chart.yaml, templates, values, then install, upgrade, rollback and package.
मित्रांनो, Helm अनेक YAML ला एक chart बनवतो. आज Chart.yaml, templates, values, install/upgrade/rollback/package.
दोस्तों, Helm कई YAML को एक chart बनाता है. आज Chart.yaml, templates, values, install/upgrade/rollback/package.
What you will build in this project
- Chart.yaml and values.yaml.
- Deployment and Service templates.
- helm install upgrade rollback.
- Packaged .tgz note.
1. Start from a real company story
At Flipkart in Bengaluru, Meera copied raw YAML into every cluster by hand.
One forgotten replicaCount left the festive sale thin on Pods.
A Helm chart with values per env fixed the drift. Rough past cost of the miss: about ₹40 lakh in lost carts.
Today we build that chart.
Ravindra Bagale's Tip
Students paste Secrets into values.yaml and push. That leaks. Use sealed secrets or external secret tools later. Keep that habit.
Students Secrets values.yaml मध्ये ठेवतात. ते leak होते. Sealed/external secrets नंतर. सवय ठेवा.
Students Secrets values.yaml में रखते हैं. वो leak होता है. Sealed/external secrets बाद में. आदत रखिए.
2. Start and prepare
Step 1: Why Helm
Why: Package YAML. We do this before the next step so mistakes stay small and easy to undo. Read the output carefully; the numbers and names tell you if the machine is healthy.
What: echo. Follow the numbered examples below. Type each command, read the exact output, and match the meaning line before you move on. That is how real teams learn a tool.
Example 1: a1
Type this:
echo 'Helm packages Kubernetes YAML into a chart with values you can change'
You will see:
Helm packages Kubernetes YAML into a chart with values you can change
What it means: What Helm is.
Example 2: a2
Type this:
echo 'A chart has Chart.yaml templates/ values.yaml and often helpers'
You will see:
A chart has Chart.yaml templates/ values.yaml and often helpers
What it means: Chart layout.
Example 3: a3
Type this:
echo 'helm create shop starts a skeleton chart'
You will see:
helm create shop starts a skeleton chart
What it means: Scaffold tip.
Step 2: Chart.yaml values
Why: Metadata and defaults. We do this before the next step so mistakes stay small and easy to undo. Read the output carefully; the numbers and names tell you if the machine is healthy.
What: printf. Follow the numbered examples below. Type each command, read the exact output, and match the meaning line before you move on. That is how real teams learn a tool.
Example 4: b1
Type this:
mkdir -p /tmp/k8s41/shop/{templates,charts} && printf '%s\n' 'apiVersion: v2' 'name: shop' 'description: lab shop chart' 'type: application' 'version: 0.1.0' 'appVersion: "1.0.0"' > /tmp/k8s41/shop/Chart.yaml && cat /tmp/k8s41/shop/Chart.yaml
You will see:
apiVersion: v2
name: shop
What it means: Chart.yaml for the lab.
Example 5: b2
Type this:
printf '%s\n' 'replicaCount: 2' 'image:' ' repository: nginx' ' tag: 1.27-alpine' 'service:' ' port: 80' > /tmp/k8s41/shop/values.yaml && cat /tmp/k8s41/shop/values.yaml
You will see:
replicaCount: 2
What it means: Default values.
Example 6: b3
Type this:
echo 'helm lint /tmp/k8s41/shop'
You will see:
helm lint /tmp/k8s41/shop
What it means: Lint before install.
Step 3: Templates
Why: Templated Deploy/Service. We do this before the next step so mistakes stay small and easy to undo. Read the output carefully; the numbers and names tell you if the machine is healthy.
What: printf templates. Follow the numbered examples below. Type each command, read the exact output, and match the meaning line before you move on. That is how real teams learn a tool.
Example 7: c1
Type this:
printf '%s\n' 'apiVersion: apps/v1' 'kind: Deployment' 'metadata:' ' name: {{ .Release.Name }}-web' 'spec:' ' replicas: {{ .Values.replicaCount }}' ' selector:' ' matchLabels: {app: {{ .Release.Name }}}' ' template:' ' metadata: {labels: {app: {{ .Release.Name }}}}' ' spec:' ' containers:' ' - name: web' ' image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"' ' ports: [{containerPort: 80}]' > /tmp/k8s41/shop/templates/deploy.yaml && head -5 /tmp/k8s41/shop/templates/deploy.yaml
You will see:
apiVersion: apps/v1
kind: Deployment
What it means: Deployment template with values.
Example 8: c2
Type this:
printf '%s\n' 'apiVersion: v1' 'kind: Service' 'metadata: {name: {{ .Release.Name }}-web}' 'spec:' ' selector: {app: {{ .Release.Name }}}' ' ports: [{port: {{ .Values.service.port }}}]' > /tmp/k8s41/shop/templates/svc.yaml && cat /tmp/k8s41/shop/templates/svc.yaml
You will see:
kind: Service
What it means: Service template.
Example 9: c3
Type this:
echo 'helm template shop /tmp/k8s41/shop --set replicaCount=3 | head -20'
You will see:
helm template shop ... | head -20
What it means: Render without installing.
3. Build the main pieces
Step 4: Install list get
Why: Release lifecycle. We do this before the next step so mistakes stay small and easy to undo. Read the output carefully; the numbers and names tell you if the machine is healthy.
What: helm install. Follow the numbered examples below. Type each command, read the exact output, and match the meaning line before you move on. That is how real teams learn a tool.
Example 10: d1
Type this:
echo 'helm install shop /tmp/k8s41/shop --namespace shop --create-namespace'
You will see:
helm install shop /tmp/k8s41/shop --namespace shop --create-namespace
What it means: Install release.
Example 11: d2
Type this:
echo 'helm list -n shop'
You will see:
helm list -n shop
What it means: List releases.
Example 12: d3
Type this:
echo 'helm get values shop -n shop'
You will see:
helm get values shop -n shop
What it means: Show values used.
Step 5: Upgrade history rollback
Why: Change and undo. We do this before the next step so mistakes stay small and easy to undo. Read the output carefully; the numbers and names tell you if the machine is healthy.
What: upgrade. Follow the numbered examples below. Type each command, read the exact output, and match the meaning line before you move on. That is how real teams learn a tool.
Example 13: e1
Type this:
echo 'helm upgrade shop /tmp/k8s41/shop -n shop --set replicaCount=4'
You will see:
helm upgrade shop /tmp/k8s41/shop -n shop --set replicaCount=4
What it means: Upgrade with override.
Example 14: e2
Type this:
echo 'helm history shop -n shop'
You will see:
helm history shop -n shop
What it means: Revision history.
Example 15: e3
Type this:
echo 'helm rollback shop 1 -n shop'
You will see:
helm rollback shop 1 -n shop
What it means: Rollback to revision 1.
Step 6: Uninstall dry-run secrets
Why: Cleanup and safety. We do this before the next step so mistakes stay small and easy to undo. Read the output carefully; the numbers and names tell you if the machine is healthy.
What: uninstall. Follow the numbered examples below. Type each command, read the exact output, and match the meaning line before you move on. That is how real teams learn a tool.
Example 16: f1
Type this:
echo 'helm uninstall shop -n shop'
You will see:
helm uninstall shop -n shop
What it means: Uninstall release.
Example 17: f2
Type this:
echo 'Dry-run tip: helm upgrade --install --dry-run --debug'
You will see:
Dry-run tip: helm upgrade --install --dry-run --debug
What it means: Safe preview.
Example 18: f3
Type this:
echo 'Never put Secrets in values.yaml committed to git'
You will see:
Never put Secrets in values.yaml committed to git
What it means: Secret habit.
4. Automate and verify
Step 7: Env values -f
Why: Per-env files. We do this before the next step so mistakes stay small and easy to undo. Read the output carefully; the numbers and names tell you if the machine is healthy.
What: -f file. Follow the numbered examples below. Type each command, read the exact output, and match the meaning line before you move on. That is how real teams learn a tool.
Example 19: g1
Type this:
printf '%s\n' 'replicaCount: 1' 'image:' ' tag: 1.26-alpine' > /tmp/k8s41/dev-values.yaml && cat /tmp/k8s41/dev-values.yaml
You will see:
replicaCount: 1
What it means: Env-specific values file.
Example 20: g2
Type this:
echo 'helm upgrade --install shop /tmp/k8s41/shop -n shop -f /tmp/k8s41/dev-values.yaml'
You will see:
helm upgrade --install ... -f dev-values.yaml
What it means: Install with -f.
Example 21: g3
Type this:
echo 'Prefer -f files over long --set strings for readability'
You will see:
Prefer -f files over long --set strings for readability
What it means: Style tip.
Step 8: package show
Why: Ship a .tgz. We do this before the next step so mistakes stay small and easy to undo. Read the output carefully; the numbers and names tell you if the machine is healthy.
What: package. Follow the numbered examples below. Type each command, read the exact output, and match the meaning line before you move on. That is how real teams learn a tool.
Example 22: h1
Type this:
echo 'helm package /tmp/k8s41/shop -d /tmp/k8s41'
You will see:
helm package /tmp/k8s41/shop -d /tmp/k8s41
What it means: Create .tgz chart archive.
Example 23: h2
Type this:
ls /tmp/k8s41/*.tgz 2>/dev/null || echo 'shop-0.1.0.tgz expected after package'
You will see:
shop-0.1.0.tgz expected after package
What it means: Packaged artifact.
Example 24: h3
Type this:
echo 'helm show chart /tmp/k8s41/shop-0.1.0.tgz 2>/dev/null || helm show chart /tmp/k8s41/shop'
You will see:
helm show chart ...
What it means: Inspect packaged chart.
Step 9: repo search
Why: Public repos. We do this before the next step so mistakes stay small and easy to undo. Read the output carefully; the numbers and names tell you if the machine is healthy.
What: repo. Follow the numbered examples below. Type each command, read the exact output, and match the meaning line before you move on. That is how real teams learn a tool.
Example 25: i1
Type this:
echo 'helm repo add bitnami https://charts.bitnami.com/bitnami'
You will see:
helm repo add bitnami https://charts.bitnami.com/bitnami
What it means: Add a public chart repo.
Example 26: i2
Type this:
echo 'helm search repo nginx'
You will see:
helm search repo nginx
What it means: Search charts.
Example 27: i3
Type this:
echo 'Study upstream charts then copy patterns into your shop chart'
You will see:
Study upstream charts then copy patterns into your shop chart
What it means: Learn tip.
5. Harden and accept
Step 10: hooks version diff
Why: Advanced tips. We do this before the next step so mistakes stay small and easy to undo. Read the output carefully; the numbers and names tell you if the machine is healthy.
What: hooks. Follow the numbered examples below. Type each command, read the exact output, and match the meaning line before you move on. That is how real teams learn a tool.
Example 28: j1
Type this:
echo 'hooks: pre-install Jobs can migrate databases before Pods start'
You will see:
hooks: pre-install Jobs can migrate databases before Pods start
What it means: Hook tip.
Example 29: j2
Type this:
echo 'Keep Chart.yaml version semver and bump on every change'
You will see:
Keep Chart.yaml version semver and bump on every change
What it means: Version habit.
Example 30: j3
Type this:
echo 'helm diff plugin tip: compare rendered YAML before upgrade'
You will see:
helm diff plugin tip: compare rendered YAML before upgrade
What it means: Diff tip.
Step 11: Cleanup
Why: Cleanup. We do this before the next step so mistakes stay small and easy to undo. Read the output carefully; the numbers and names tell you if the machine is healthy.
What: cleanup. Follow the numbered examples below. Type each command, read the exact output, and match the meaning line before you move on. That is how real teams learn a tool.
Example 31: k1
Type this:
echo 'Optional cleanup: helm uninstall shop -n shop; kubectl delete ns shop'
You will see:
Optional cleanup: helm uninstall shop -n shop; kubectl delete ns shop
What it means: Cleanup.
Example 32: k2
Type this:
echo 'Save Chart.yaml values.yaml and two templates in your notebook'
You will see:
Save Chart.yaml values.yaml and two templates in your notebook
What it means: Artifact habit.
Example 33: k3
Type this:
echo 'Next project locks RBAC for two teams'
You will see:
Next project locks RBAC for two teams
What it means: Bridge.
Step 12: Acceptance
Why: Meera signs off. We do this before the next step so mistakes stay small and easy to undo. Read the output carefully; the numbers and names tell you if the machine is healthy.
What: All green. Follow the numbered examples below. Type each command, read the exact output, and match the meaning line before you move on. That is how real teams learn a tool.
Example 34: z1
Type this:
echo 'Chart has Chart.yaml templates and values.yaml'
You will see:
Chart has Chart.yaml templates and values.yaml
What it means: Checklist layout.
Example 35: z2
Type this:
echo 'install upgrade rollback uninstall practiced'
You will see:
install upgrade rollback uninstall practiced
What it means: Checklist lifecycle.
Example 36: z3
Type this:
echo 'Meera: PASS'
You will see:
Meera: PASS
What it means: Project 41 accepted.
Check yourself
Q1. Who fixed Flipkart?
Meera
Q2. Scaffold tip?
helm create
Q3. Render without install?
helm template
Q4. Undo upgrade?
helm rollback
Q5. Archive command?
helm package
Q6. List releases?
helm list
Friends, you packaged a shop chart and practiced the Helm lifecycle. Did you understand? Let us try it once more. Add a values-dev.yaml and values-prod.yaml pair next.
मित्रांनो, तुम्ही shop chart pack करून lifecycle शिकलात. values-dev/prod जोडा.
दोस्तों, आपने shop chart pack कर lifecycle सीखा. values-dev/prod जोड़ें.
Lab: try at home
- Write Chart.yaml and values.
- Add templates.
- helm lint and template.
- install upgrade rollback.
- package the chart.
Recap
- values change without editing templates.
- lint before install.
- history enables rollback.
- No Secrets in git values.
- Semver Chart version.