11
sync      sync all resources from state file (repos, releases and chart deps)
apply     apply all resources from state file only when there are changes

同步

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.

申请

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.

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

4

3 回答 3

16

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

如果您每五分钟使用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

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

于 2020-02-13T09:42:41.203 回答
2

其他答案中的所有内容都是正确的。sync但是,使用vs还需要了解另外一件重要的事情apply

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

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


如果您想了解更多详细信息,请查看我的博客文章helmfile:同步和应用之间的区别(Helm 3)

于 2021-10-11T17:07:14.887 回答
0

简而言之,这就是它们的工作方式:

  • helmfile sync来电helm upgrade --install

  • helmfile applyhelm upgrade --install当且仅当helm diff返回一些更改时调用。

所以,一般来说,helmfile apply会更快,我建议大部分时间使用它。

但是,请考虑到,如果有人从图表中手动删除了任何deployments 或s,则不会看到任何更改,因此将不起作用,这些资源仍将被删除,同时将重新创建它以恢复原始图表配置。configmaphelm diffhelmfile applyhelmfile sync

于 2022-02-15T13:09:51.023 回答