Anatomy of a chart

Helm · Essentials · 8 min

You need to read charts you install and write charts for your own services.

helm create shop scaffolds a working chart:

  • Chart.yaml: metadata. apiVersion: v2, name, version (the chart's SemVer version, bump it on every chart change) and appVersion (the version of the app it deploys, informational). Also type (application or library), dependencies, kubeVersion constraints.
  • values.yaml: defaults, documented with comments. This is the chart's public interface.
  • templates/: manifests with Go template expressions. Every file is rendered; files starting with _ (like _helpers.tpl) are not output and hold named templates.
  • templates/NOTES.txt: rendered and printed after install, used for usage hints.
  • charts/: packaged dependencies.
  • values.schema.json (optional): JSON Schema that validates values.
  • .helmignore: files to leave out of the package.

helm template shop ./shop -f prod.yaml renders locally so you can read the YAML that would be applied, without a cluster. helm package ./shop creates shop-1.4.0.tgz.

Keep the chart close to the code it deploys (a chart/ or deploy/ directory) unless several services share a generic chart. Delete the scaffold's parts you don't use; a smaller chart is easier to maintain.

Example

helm create shop
tree shop
# shop/
#   Chart.yaml  values.yaml  .helmignore  charts/
#   templates/  _helpers.tpl  deployment.yaml  service.yaml  ingress.yaml
#               hpa.yaml  serviceaccount.yaml  NOTES.txt  tests/

cat shop/Chart.yaml
# apiVersion: v2
# name: shop
# type: application
# version: 0.1.0
# appVersion: "1.16.0"

helm template shop ./shop --set replicaCount=2 | grep -A2 'kind: Deployment'

Remember

  • version = chart version (bump on every change); appVersion = the app's
  • Files starting with _ hold helpers and aren't rendered as manifests
  • helm template renders locally for review

Watch out for

  • Changing templates without bumping the chart version, so two different packages share one version.

Check yourself

  1. Which field must change when you modify a chart's templates and publish it?

Sign in to answer, see the explanations, and get this lesson back as a quick review later.

Official docs: helm.sh/docs/topics/charts/