Restart pods when configmap updates in Kubernetes?

后端 未结 7 2130
猫巷女王i
猫巷女王i 2020-11-29 16:51

How do I automatically restart Kubernetes pods and pods associated with deployments when their configmap is changed/updated?


I know there\'s been talk about th

7条回答
  •  暗喜
    暗喜 (楼主)
    2020-11-29 17:00

    https://github.com/kubernetes/helm/blob/master/docs/charts_tips_and_tricks.md#user-content-automatically-roll-deployments-when-configmaps-or-secrets-change

    Often times configmaps or secrets are injected as configuration files in containers. Depending on the application a restart may be required should those be updated with a subsequent helm upgrade, but if the deployment spec itself didn't change the application keeps running with the old configuration resulting in an inconsistent deployment.

    The sha256sum function can be used together with the include function to ensure a deployments template section is updated if another spec changes:

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

    In my case, for some reasons, $.Template.BasePath didn't work but $.Chart.Name does:

    spec:
      replicas: 1
      template:
        metadata:
          labels:
            app: admin-app
          annotations:
            checksum/config: {{ include (print $.Chart.Name "/templates/" $.Chart.Name "-configmap.yaml") . | sha256sum }}
    

提交回复
热议问题