configmap更改时,舵图重启pod

时间:2018-10-05 05:25:58

标签: kubernetes yaml kubernetes-helm

当配置文件或秘密更改时,我试图重新启动Pod。我已经尝试过与https://github.com/helm/helm/blob/master/docs/charts_tips_and_tricks.md#automatically-roll-deployments-when-configmaps-or-secrets-change中所述的同一段代码 但是,更新configmap后,我的pod不会重新启动。您是否知道这里可能做错了什么?

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 个答案:

答案 0 :(得分:3)

Helm和Kubernetes均未提供针对ConfigMap更改的特定滚动更新。解决办法已经有一段时间了,只是对部署进行修补,从而触发滚动更新:

{
"GCM": "{ \"notification\": { \"text\": \"test message\" } }"
}

您可以看到状态:

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

请注意,这在nix机器上有效。直到添加了feature

答案 1 :(得分:1)

https://helm.sh/docs/howto/charts_tips_and_tricks/#automatically-roll-deployments Helm3现在具有此功能。 configmap模板文件发生更改时,将部署部署。

答案 2 :(得分:1)

它对我有用,下面是我的 deployment.yaml 文件中的代码片段,请确保您的 configmap 和秘密 yaml 文件与注释中提到的相同:

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

答案 3 :(得分:0)

我使用具有此功能的 configmap 部署了 pod https://helm.sh/docs/howto/charts_tips_and_tricks/#automatically-roll-deployments。 当我在运行时编辑 configmap 时,它没有触发滚动部署。