【问题标题】:Kubernetes + Helm - only restart pods if new version/changeKubernetes + Helm - 仅在新版本/更改时重新启动 pod
【发布时间】:2020-09-05 07:35:43
【问题描述】:

每当我运行基本部署命令时,都会在我的环境中重新部署所有内容。有没有办法告诉 Helm 仅在进行更改时才应用事物,或者这就是它的工作方式?

我在跑步:

helm upgrade --atomic MyInstall . -f CustomEnvironmentData.yaml

我在Helm Upgrade documentation 中没有看到任何表明此功能的内容。

除非迫不得已,否则我不想改变我的整个环境。

【问题讨论】:

    标签: kubernetes kubernetes-helm


    【解决方案1】:

    没有办法告诉 Helm 这样做,但也没有必要。如果您向 Kubernetes API 服务器提交一个与已经存在的东西完全匹配的对象,通常什么都不会发生。

    例如,假设您有一个指定了image: my/image:{{ .Values.tag }}replicas: 3 的部署对象。您使用tag: 20200904.01 提交一次。现在运行您显示的helm upgrade 命令,tag 值在CustomEnvironmentData.yaml 文件中保持不变。这实际上会触发 Kubernetes 内部的部署控制器。这表明它希望 3 个 pod 与图像 my/image:20200904.01 一起存在。这 3 个 pod 已经存在,所以它什么也不做。

    (这与“不要使用latest标签”建议基本相同:如果您尝试设置image: my/image:latest,并使用此标签重新部署您的部署,因为部署规范未更改,Kubernetes 将不会'不做任何事情,即使注册表中的镜像版本发生了变化。)

    【讨论】:

      【解决方案2】:

      你应该使用helm diff upgrade

      https://github.com/databus23/helm-diff

      $ helm diff upgrade - h
      Show a diff explaining what a helm upgrade would change.
      
          This fetches the currently deployed version of a release
          and compares it to a chart plus values.
          This can be used visualize what changes a helm upgrade will
      perform.
      
          Usage:
      diff upgrade[flags] [RELEASE] [CHART]
      
      Examples:
      helm diff upgrade my-release stable / postgresql--values values.yaml
      
      Flags:
      -h, --help                   help for upgrade
          --detailed - exitcode      return a non - zero exit code when there are changes
      --post - renderer string the path to an executable to be used for post rendering. If it exists in $PATH, the binary will be used, otherwise it will try to look for the executable at the given path
      --reset - values           reset the values to the ones built into the chart and merge in any new values
          --reuse - values           reuse the last release's values and merge in any new values
          --set stringArray        set values on the command line(can specify multiple or separate values with commas: key1 = val1, key2 = val2)
      --suppress stringArray   allows suppression of the values listed in the diff output
          - q, --suppress - secrets       suppress secrets in the output
          - f, --values valueFiles      specify values in a YAML file(can specify multiple)(default[])
          --version string         specify the exact chart version to use.If this is not specified, the latest version is used
      
          Global Flags:
      --no - color   remove colors from the output
      

      【讨论】:

      • 不是我想要的,但这很有帮助。
      • 很好,请为您的最终解决方案添加答案,我会投票赞成。
      猜你喜欢
      • 2019-03-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-01-02
      • 1970-01-01
      • 2018-03-04
      • 2021-07-15
      相关资源
      最近更新 更多