Kubernetes Tutorial · Operating Kubernetes · Lesson 25 of 26
Packaging with Helm and Kustomize
Template and customise manifests per environment: Helm charts and Kustomize overlays.
Kustomize
Built into kubectl (kubectl apply -k dir/). A base holds plain manifests; overlays patch them per
environment (replicas, images, labels) without templates.
Helm
A chart is a package of templated manifests plus values.yaml. helm install renders templates with your
values and tracks a release you can upgrade and roll back. Charts are how most third-party software
(ingress controllers, databases, monitoring) is distributed.
Both render plain YAML in the end: kubectl kustomize dir/ and helm template show exactly what will be
applied, which is worth reviewing in CI.
mkdir -p base overlays/prod
cat > base/deployment.yaml <<'EOF'
apiVersion: apps/v1
kind: Deployment
metadata: {name: api}
spec:
replicas: 1
selector: {matchLabels: {app: api}}
template:
metadata: {labels: {app: api}}
spec:
containers: [{name: api, image: example/api:1.0.0}]
EOF
printf 'resources:\n - deployment.yaml\n' > base/kustomization.yaml
cat > overlays/prod/kustomization.yaml <<'EOF'
resources: [../../base]
namespace: prod
images:
- name: example/api
newTag: 1.4.2
patches:
- target: {kind: Deployment, name: api}
patch: |
- op: replace
path: /spec/replicas
value: 3
EOF
kubectl kustomize overlays/prod | grep -E 'namespace:|replicas:|image:'
Output
namespace: prod
replicas: 3
- image: example/api:1.4.2Run this on your computer — see “Get Started” for setup.
See Kustomize and Helm docs. The course Helm, Kustomize and GitOps with Argo CD goes further.
Test yourself
How can you see exactly what a Helm chart or Kustomize overlay will apply?
You can'tRender it: helm template or kubectl kustomizeApply it to production and checkRead values.yaml only
Show answer
Answer: Render it: helm template or kubectl kustomize
Both tools produce plain manifests you can review and diff.