The problem

One copy of what is the same; write down only what differs

Settingdevstagingproductionreplicas126image tag1.5.0-rc11.4.21.4.2hostnamedev.shop.examplestaging.shop.exampleshop.examplememory limit256Mi512Mi512Mieverything else212 lines of YAMLthe same 212 linesthe same 212 linesKept as three full copies, that is 636 lines to maintain, for 4 real differences.Keep one copy of what is the same, and write down only what differs.An application is a dozen manifests, and every environment needs them with a few values changed.Copying the files is how environments drift apart: a fix reaches two copies and misses the third.Helm and Kustomize are two ways to keep a single source and vary it.

Four differences, and 212 lines that are identical.

Helm

A chart is manifests with blanks, and values to fill them

templates/deployment.yamlkind: Deploymentspec: replicas: {{ .Values.replicas }} ... image: web:{{ .Values.tag }}values-prod.yamlreplicas: 6tag: 1.4.2helmfills the blanksWhat the cluster receiveskind: Deploymentspec: replicas: 6 ... image: web:1.4.2Installed as a release, revision 1.Each upgrade is a new revision you can roll back to.A Helm chart is manifests with blanks, plus a file of values to fill them.A chart packages a whole application, with sensible defaults, so that others can install it withone command and their own values. Most third-party software for Kubernetes is shipped as a chart.

A template plus values gives the finished manifest.

Helm · Going deeper · 1 of 2

Lab: install, upgrade and roll back a chart

TypeLook forhelm create demohelm install demo ./demohelm upgrade demo ./demo --set replicaCount=3kubectl get podshelm history demohelm rollback demo 1Creating demo: a folder with a small chartSTATUS: deployed, REVISION: 1REVISION: 2three pods named demo-...two revisions; the first is supersededRollback was a successLab: install a chart, upgrade it, and roll it back.You need the helm command. Look inside demo/templates and demo/values.yaml to see the blanks and the defaults."helm template ./demo" prints the finished manifests without installing. "helm uninstall demo" removes it all.

Install a chart, upgrade it with a new value, roll back.

Value precedence · Going deeper · 2 of 2

Values are layered: chart defaults, then -f files, then --set

1. values.yaml, in the chart2. -f values-prod.yaml3. --set tag=1.4.3What the templates receivereplicas: 1tag: 1.4.2memory: 256Mireplicas: 6memory: 512Mitag: 1.4.3replicas: 6 from 2tag: 1.4.3 from 3memory: 512Mi from 2The commands$ helm upgrade --install shop ./chart -n shop --create-namespace -f values-prod.yaml --set tag=1.4.3$ helm template shop ./chart -f values-prod.yaml # print the finished manifests; send nothing$ helm get values shop -n shop # the values you supplied for this release$ kubectl get secrets -n shop # sh.helm.release.v1.shop.v1, .v2: one per revisionValues are laid over each other: the chart's defaults, then each -f file in order, then --set. The last one wins.upgrade --install installs the release if it is missing and upgrades it if not, so one command serves every run of a pipeline.Helm keeps each revision as a Secret in the release's own namespace, which is where helm history and helm rollback read from.In Chart.yaml, version is the version of the chart, and appVersion is the version of the application inside it.

The last source wins. helm template shows the result.

Kustomize

Kustomize lays small patches over plain manifests

base/deployment.yamlkind: Deploymentmetadata: name: webspec: replicas: 1overlays/prod/patch.yamlmetadata: { name: web }spec: replicas: 6kustomizeapplies the patchWhat the cluster receiveskind: Deploymentmetadata: name: webspec: replicas: 6kubectl apply -k overlays/prodKustomize keeps plain manifests and lays small patches over them.There is no template language: the base is ordinary YAML that works on its own, and eachenvironment is a folder of differences. It is built into kubectl. Many teams use both tools.

A base of plain YAML, and an overlay of differences.

kustomization.yaml · Going deeper

The overlay file as written: start, rename, retag, patch, generate

# overlays/prod/kustomization.yamlapiVersion: kustomize.config.k8s.io/v1beta1kind: Kustomizationresources:- ../../basenamespace: shop-prodnamePrefix: prod-images:- name: web newTag: 1.4.2patches:- path: patch.yamlconfigMapGenerator:- name: web-config literals: [LOG_LEVEL=warn]start from the base folder, which has a kustomization.yaml tooput every object in this namespaceweb becomes prod-webset the tag wherever the image web is usedlay this patch over the object it namesmake a ConfigMap named web-config-<hash of its content>One small file per environment: where to start, then what to rename, retag, patch and generate.The generator adds a hash of the content to the ConfigMap's name and rewrites every reference to it. Change a value and thename changes, so the Deployment's pod template changes, so the pods roll: the cure for settings that pods never pick up.Print the result without applying it: kubectl kustomize overlays/prod. Apply it: kubectl apply -k overlays/prod.

resources, images, patches and a configMapGenerator.

GitOps

Git holds the truth; the cluster pulls itself into line

Engineeredits a fileGit repositorythe state you wantThe clusterArgo CDwatches Git123Deployment webnow 6 replicas41an engineer changes 3 to 6 and merges it2Argo CD sees that Git and the cluster now differ3it applies the difference to the cluster4the cluster matches Git againWith GitOps, Git holds the truth and the cluster pulls itself into line.Nobody runs kubectl apply. Every change is a commit: reviewed, recorded and undone by a revert.If someone edits the cluster by hand, Argo CD shows the drift and can put it back.

A commit is the deployment. Argo CD makes the cluster match.

The Application · Going deeper

An Argo CD Application: a repository, a path, a cluster and a policy

apiVersion: argoproj.io/v1alpha1kind: Applicationmetadata: name: shop namespace: argocdspec: project: default source: repoURL: https://github.com/acme/shop-config.git targetRevision: main path: overlays/prod destination: server: https://kubernetes.default.svc namespace: shop syncPolicy: automated: { prune: true, selfHeal: true }Applications live in the namespace of Argo CD itselfthe repository to watch (an example address)a branch, a tag or one committhe folder to render: plain YAML, Kustomize or Helmthe cluster Argo CD runs inwhere the objects gowithout this line it only reports the differenceAn Application ties one folder in Git to one namespace in one cluster, and says how far Argo CD may act alone.prune deletes what was removed from Git. selfHeal undoes changes made by hand in the cluster. Both are off unless you ask.Each Application reports two things: sync (Synced or OutOfSync) and health (Healthy, Progressing or Degraded). Git is polledabout every three minutes. Flux does the same job with two objects, a GitRepository and a Kustomization.

source is Git. destination is the cluster. syncPolicy says how far to go alone.

The landscape

Kubernetes is one project among many, each with one job

The jobA graduated CNCF projectThe jobA graduated CNCF projectRun containerscontainerdOrchestrate themKubernetesKeep the cluster's stateetcdPod networkingCiliumService meshIstio, LinkerdPackage applicationsHelmDeliver from GitArgo, FluxMetrics and alertsPrometheusLogsFluentdTracesJaegerPolicyOpen Policy AgentRegistryHarborMaturity:SandboxIncubatingGraduatedKubernetes is one project among many, each doing one job.The Cloud Native Computing Foundation hosts these projects and grades their maturity. Graduatedmeans widely used in production, security-audited and run by more than one company.

A project for each job, graded sandbox to graduated.

Lesson complete

You finished “Packaging and delivery”

Nicely done.

Open in a new tab