Pods and PodTemplates

This part of the Best Practices Guide discusses formatting the Pod andPodTemplate portions in chart manifests.

The following (non-exhaustive) list of resources use PodTemplates:

  • Deployment
  • ReplicationController
  • ReplicaSet
  • DaemonSet
  • StatefulSet

Images

A container image should use a fixed tag or the SHA of the image. It should notuse the tags latest, head, canary, or other tags that are designed to be“floating”.

Images may be defined in the values.yaml file to make it easy to swap outimages.

  1. image: {{ .Values.redisImage | quote }}

An image and a tag may be defined in values.yaml as two separate fields:

  1. image: "{{ .Values.redisImage }}:{{ .Values.redisTag }}"

ImagePullPolicy

helm create sets the imagePullPolicy to IfNotPresent by default by doingthe following in your deployment.yaml:

  1. imagePullPolicy: {{ .Values.image.pullPolicy }}

And values.yaml:

  1. pullPolicy: IfNotPresent

Similarly, Kubernetes defaults the imagePullPolicy to IfNotPresent if it isnot defined at all. If you want a value other than IfNotPresent, simply updatethe value in values.yaml to your desired value.

PodTemplates Should Declare Selectors

All PodTemplate sections should specify a selector. For example:

  1. selector:
  2. matchLabels:
  3. app.kubernetes.io/name: MyName
  4. template:
  5. metadata:
  6. labels:
  7. app.kubernetes.io/name: MyName

This is a good practice because it makes the relationship between the set andthe pod.

But this is even more important for sets like Deployment. Without this, theentire set of labels is used to select matching pods, and this will break ifyou use labels that change, like version or release date.