helmfile 同步与 helmfile 应用

mhy*_*efi 9 kubernetes kubernetes-helm helmfile

sync      sync all resources from state file (repos, releases and chart deps)
apply     apply all resources from state file only when there are changes
Run Code Online (Sandbox Code Playgroud)

同步

The helmfile sync sub-command sync your cluster state as described in your helmfile ... Under 
the covers, Helmfile executes helm upgrade --install for each release declared in the 
manifest, by optionally decrypting secrets to be consumed as helm chart values. It also 
updates specified chart repositories and updates the dependencies of any referenced local 
charts.

For Helm 2.9+ you can use a username and password to authenticate to a remote repository.
Run Code Online (Sandbox Code Playgroud)

申请

The helmfile apply sub-command begins by executing diff. If diff finds that there is any changes
sync is executed. Adding --interactive instructs Helmfile to request your confirmation before sync.
An expected use-case of apply is to schedule it to run periodically, so that you can auto-fix skews
between the desired and the current state of your apps running on Kubernetes clusters.
Run Code Online (Sandbox Code Playgroud)

我浏览了Helmfile 存储库 Readme以找出helmfile sync和之间的区别helmfile apply。似乎与 apply 命令不同,sync 命令不会在所有版本中执行 adiffhelm upgrades 。但是从单词sync,您会期望该命令应用那些已更改的版本。还提到了helmfile apply定期同步发布的潜在应用。为什么不helmfile sync用于这个目的?总的来说,差异并没有变得非常清晰,我认为可能还有更多。所以,我在问。

Fil*_*lov 14

考虑这样一个用例,您有一个 Jenkins 作业每 5 分钟触发一次,并且在该作业中您想要升级您的掌舵图,但前提是有更改。

如果您每五分钟使用helmfile syncwhich 调用helm upgrade --install,您最终将每五分钟增加一次图表修订。

$ helm upgrade --install httpd bitnami/apache > /dev/null
$ helm list
NAME    REVISION        UPDATED                         STATUS          CHART           APP VERSION     NAMESPACE
httpd   1               Thu Feb 13 11:27:14 2020        DEPLOYED        apache-7.3.5    2.4.41          default
$ helm upgrade --install httpd bitnami/apache > /dev/null
$ helm list
NAME    REVISION        UPDATED                         STATUS          CHART           APP VERSION     NAMESPACE
httpd   2               Thu Feb 13 11:28:39 2020        DEPLOYED        apache-7.3.5    2.4.41          default
Run Code Online (Sandbox Code Playgroud)

所以,每一个helmfile sync都会导致新的修订。现在,如果您要运行helmfile apply,它将首先检查差异,然后(如果找到)将调用helmfile sync它反过来调用helm upgrade --install这不会发生。

  • “sync”命令有一个重要含义。如果有人从图表中手动删除某些部署或配置映射,“apply”将不会看到任何更改,并且该资源仍将被删除,而“sync”将重新创建它以恢复原始图表配置。 (3认同)
  • 是的,这是有意的,因为如果 `helm diff` 返回一些更改,apply 只会执行 `helm update --install`。并且在集群上进行手动操作时,helm diff 不会返回任何更改,因此运行 `sync` 是保持状态与代码同步的最佳方式。 (2认同)

Der*_*lin 5

其他答案中的所有内容都是正确的。sync然而,关于vs还有一件重要的事情需要理解apply

  • sync将调用helm upgrade所有版本。因此,将为每个版本创建一个新的 Helm Secret,并且版本的修订版都将增加 1。Helm 3 使用三向策略合并算法来计算补丁,这意味着它将恢复对Helm 处理的实时集群中的资源进行的手动更改;
  • apply将首先使用 helm-diff 插件来确定哪些版本发生了更改,并且仅helm upgrade在更改的版本上运行。但是,helm-diff只将之前的 Helm 状态与新的 Helm 状态进行比较,并没有考虑当前集群的状态。这意味着如果您手动修改某些内容helmfile apply(或更准确地说 helm-diff 插件)可能无法检测到它,并保持原样。

因此,如果您总是通过 helm 修改实时集群,那么helmfile apply这是正确的方法。但是,如果您可以进行手动更改并希望确保实时状态与 Helm/helmfile 中定义的内容一致,那么这helmfile sync是必要的。


如果您想了解更多详细信息,请查看我的博客文章helmfile:sync 和 apply 之间的差异 (Helm 3)

  • 有关使用“HELM_DIFF_THREE_WAY_MERGE”环境变量进行三向合并差异的文章有更新。使用“HELM_DIFF_THREE_WAY_MERGE=true helmfile apply” helmfile 现在也可以检测和更改手动更改。如果您坚持这种最佳实践,那么应用永远是最佳选择。(文字从来源复制) (2认同)