Does helm upgrade on a configmap automatically inject new data into running pod?

10,453

Solution 1

No, pods do not automatically become aware of the contents of a config map change.

In the case of a helm upgrade, that’s why you need to use helm template syntax to add the config map file’s hash value to the pod (or pod template) metadata. This creates a link between the config and pod.

If you do that, the pod (or pod template) is updated even if only the config map is changed. Then, no manual intervention is required.

Solution 2

If your Helm chart creates a ConfigMap, and that ConfigMap is mounted as a volume into a pod, then when the ConfigMap updates, the container filesystem also updates. It's then up to the application to notice that the files have changed.

Tricks like setting a hash of the file contents as a pod annotation are specifically there to cause a Deployment to update in a way that will delete and recreate existing Pods. This is okay! Pods in Kubernetes are very disposable, and if you delete a Pod managed by a Deployment it will get automatically recreated. If your application only reads the ConfigMap contents at startup time (this is very typical) then you need to do something like this to cause the Pod to restart on its own (copied out of the linked documentation):

kind: Deployment
spec:
  template:
    metadata:
      annotations:
        checksum/config: {{ include (print $.Template.BasePath "/configmap.yaml") . | sha256sum }}

Solution 3

Using helm:

spec:
  strategy:
    type: "Recreate"
  replicas: {{ .Values.replicaCount }}
  selector:
    matchLabels:
      {{- include "dmi.selectorLabels" . | nindent 6 }}
  template:
    metadata:
      {{- with .Values.podAnnotations }}
      annotations:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      labels:
        checksum/config: {{ include (print $.Template.BasePath "/configmap.yaml") . | sha256sum | trunc 10}}

As long your configmap will change the pod will recreate cause the checksum will be changed. I did use the strategy: Recreate cause my solution does not need rolling-update. But this should work with rolling-update too.

Share:
10,453
texasdave
Author by

texasdave

Updated on June 26, 2022

Comments

  • texasdave
    texasdave almost 2 years

    When issuing a helm upgrade on a running pod, my configmap is updated, but will the pod know about the configmap updated values automatically or is there another step that I need to take to inject new configmap values into the pod?

    My overall goal is to avoid having to interact with the running pod such as a delete or restart / reinstall.

    I've seen a lot of info about changing sha1sum and doing some workarounds, but my question is more basic - do pods automatically become aware of new configmap items?

    ---- UPDATE --- so what we ended up doing was:

    helm upgrade -n release -f release/values.yaml --recreate-pods

    although this terminates the existing pod, another one is instantly started upon issuing the command, meaning "near zero" downtime.