10
votes

I am trying to restart the pods when there is a confimap or secret change. I have tried the same piece of code as described in: https://github.com/helm/helm/blob/master/docs/charts_tips_and_tricks.md#automatically-roll-deployments-when-configmaps-or-secrets-change However, after updating the configmap, my pod does not get restarted. Would you have any idea what could has been done wrong here?

apiVersion: apps/v1beta2
kind: Deployment
metadata:
  name: {{ template "app.fullname" . }}
  labels:
    app: {{ template "app.name" . }}
    {{- include "global_labels" . | indent 4 }}
spec:
  replicas: {{ .Values.replicaCount }}
  selector:
    matchLabels:
      app: {{ template "app.name" . }}
      release: {{ .Release.Name }}
  template:
    metadata:
      annotations:
        checksum/config: {{ include (print $.Template.BasePath "/configmap.yml") . | sha256sum }}
        checksum/secret: {{ include (print $.Template.BasePath "/secret.yml") . | sha256sum }}
4

4 Answers

12
votes

Neither Helm nor Kubernetes provide a specific rolling update for a ConfigMap change. The workaround has been for a while is to just patch the deployment which triggers the rolling update:

kubectl patch deployment your-deployment -n your-namespace -p '{"spec":{"template":{"metadata":{"annotations":{"date":"$(date)"}}}}}'

And you can see the status:

kubectl rollout status deployment your-deployment

Note this works on a nix machine. This is until this feature is added.

Update 05/05/2021

Helm and kubectl provide this now:

Helm: https://helm.sh/docs/howto/charts_tips_and_tricks/#automatically-roll-deployments

kubectl: kubectl rollout restart deploy WORKLOAD_NAME

6
votes

https://helm.sh/docs/howto/charts_tips_and_tricks/#automatically-roll-deployments Helm3 has this feature now. deployments are rolled out when there is change in configmap template file.

1
votes

it worked for me, below is the code snippet from my deployment.yaml file, make sure your configmap and secret yaml file are same as what referred in the annotations:

spec:
  template:
    metadata:
      annotations:
        checksum/config: {{ include (print $.Template.BasePath "/my-configmap.yaml") . | sha256sum }}
        checksum/secret: {{ include (print $.Template.BasePath "/my-secret.yaml") . | sha256sum }}
0
votes

I deployed pod with configmap with this feature https://helm.sh/docs/howto/charts_tips_and_tricks/#automatically-roll-deployments. When I edited the configmap at runtime , it didn't trigger the roll-deployment.