Kubernetes Cheatsheet

Helm

Use this Kubernetes reference while you build software engineering projects, review code for technical interview prep, or polish examples for a software engineer resume.

Core Concepts

TermWhat it is
ChartPackage of Kubernetes manifests + templates
ReleaseA deployed instance of a chart (can deploy the same chart multiple times)
RepositoryCollection of charts (like npm registry)
ValuesYAML config that parameterizes a chart
RevisionEach update to a release creates a new numbered revision

Install and Setup

# install (macOS)
brew install helm

# verify
helm version

# add popular repos
helm repo add stable https://charts.helm.sh/stable
helm repo add bitnami https://charts.bitnami.com/bitnami
helm repo add ingress-nginx https://kubernetes.github.io/ingress-nginx
helm repo add cert-manager https://charts.jetstack.io

# update repo cache
helm repo update

# list repos
helm repo list

Finding and Inspecting Charts

helm search hub nginx                          # search Artifact Hub
helm search repo bitnami                       # search local repos
helm search repo bitnami/postgresql --versions # all versions

helm show chart bitnami/postgresql             # chart metadata
helm show values bitnami/postgresql            # default values (long!)
helm show values bitnami/postgresql > values.yaml  # save defaults to edit
helm show readme bitnami/postgresql
helm show all bitnami/postgresql               # everything

Installing a Release

# basic install
helm install my-release bitnami/postgresql

# specify namespace (create if missing)
helm install my-release bitnami/postgresql \
  --namespace db \
  --create-namespace

# override values inline
helm install my-release bitnami/postgresql \
  --set auth.postgresPassword=secret \
  --set primary.persistence.size=20Gi

# override values from file
helm install my-release bitnami/postgresql \
  -f custom-values.yaml

# multiple value files (later files take precedence)
helm install my-release bitnami/postgresql \
  -f base.yaml -f prod.yaml

# dry run (render templates, don't apply)
helm install my-release bitnami/postgresql --dry-run --debug

# install specific version
helm install my-release bitnami/postgresql --version 13.2.3

# install from local chart directory
helm install my-release ./my-chart/

# install from URL
helm install my-release https://example.com/charts/my-chart-1.0.0.tgz

Upgrading

helm upgrade my-release bitnami/postgresql -f custom-values.yaml

# install if not exists, upgrade if it does
helm upgrade --install my-release bitnami/postgresql -f custom-values.yaml

# rollback if upgrade fails
helm upgrade my-release bitnami/postgresql \
  --atomic \
  --timeout 5m

# reuse previous values, only override what changed
helm upgrade my-release bitnami/postgresql \
  --reuse-values \
  --set primary.persistence.size=30Gi

Rollback

helm history my-release              # list revisions
helm rollback my-release 2           # roll back to revision 2
helm rollback my-release             # roll back to previous revision

Listing and Status

helm list                            # releases in current namespace
helm list -A                         # all namespaces
helm list --failed                   # only failed releases
helm status my-release               # notes, last deployed, resources
helm get values my-release           # values used for current release
helm get values my-release --all     # all values (user + defaults)
helm get manifest my-release         # rendered YAML that was applied
helm get notes my-release            # post-install notes

Uninstalling

helm uninstall my-release
helm uninstall my-release --keep-history    # keep history for rollback
helm uninstall my-release -n db             # specify namespace

Creating a Chart

helm create my-chart           # scaffold a chart

Generated structure:

my-chart/
├── Chart.yaml           # name, version, appVersion, dependencies
├── values.yaml          # default values
├── templates/           # Go-templated Kubernetes manifests
│   ├── deployment.yaml
│   ├── service.yaml
│   ├── ingress.yaml
│   ├── _helpers.tpl     # named templates (partials)
│   └── NOTES.txt        # printed after install
├── charts/              # dependency charts (vendored)
└── .helmignore

Chart.yaml

apiVersion: v2
name: my-app
description: My application
type: application        # application | library
version: 1.0.0           # chart version
appVersion: "2.3.1"      # app version (informational)
dependencies:
- name: postgresql
  version: ">=13.0.0"
  repository: https://charts.bitnami.com/bitnami
  condition: postgresql.enabled
helm dependency update   # download/vendor dependencies into charts/

Template Syntax

# values.yaml
replicaCount: 2
image:
  repository: myrepo/api
  tag: "2.1"
service:
  port: 80
# templates/deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ include "my-app.fullname" . }}
  labels:
    {{- include "my-app.labels" . | nindent 4 }}
spec:
  replicas: {{ .Values.replicaCount }}
  template:
    spec:
      containers:
      - name: {{ .Chart.Name }}
        image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
        ports:
        - containerPort: {{ .Values.service.port }}

Template Functions

{{ .Values.name | default "default-name" }}
{{ .Values.name | upper | quote }}
{{ .Values.name | trunc 63 | trimSuffix "-" }}
{{ if .Values.ingress.enabled }} ... {{ end }}
{{ range .Values.ingress.hosts }} ... {{ end }}
{{ include "chart.name" . | nindent 2 }}

Linting and Debugging

helm lint ./my-chart                          # lint for errors
helm template my-release ./my-chart           # render templates locally
helm template my-release ./my-chart -f prod.yaml | kubectl apply --dry-run=client -f -
helm install --dry-run --debug my-release ./my-chart

Helm Secrets / OCI Registries

# push chart to OCI registry (Helm 3.8+)
helm registry login registry.example.com
helm push my-chart-1.0.0.tgz oci://registry.example.com/charts
helm install my-release oci://registry.example.com/charts/my-chart --version 1.0.0