Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Helm chart restart pods when configmap changes

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 }}
like image 339
Arkon Avatar asked Oct 05 '18 05:10

Arkon


People also ask

Do we need to restart pod after Configmap change?

ConfigMaps consumed as environment variables are not updated automatically and require a pod restart.

Can a pod update a Configmap?

Updating the config map in Kubernetes POD requires the restart of POD. A possible approach to auto-update configmap inside pod without restart is mounting it's content as volume. Kubernetes auto-updates the config map into POD if mounted as a volume, however, it has a limitation like it won't work if subpath used.

Does Kubernetes restart pods?

Kubernetes Pods should usually run until they're replaced by a new deployment. As a result, there's no direct way to “restart” a single Pod. If one of your containers experiences an issue, aim to replace it instead of restarting.


3 Answers

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.

like image 160
armourbear Avatar answered Sep 23 '22 06:09

armourbear


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 }}
like image 26
nitin vij Avatar answered Sep 19 '22 06:09

nitin vij


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

like image 41
Rico Avatar answered Sep 21 '22 06:09

Rico