helmfile

Helmfile 多环境 Helm 编排

补充说明

Helmfile 用声明式 YAML 管理多个 Helm release、仓库、values 和环境差异,适合替代大量 helm install/upgrade 脚本。它支持 diff、sync、apply 和模板化。

核心概念:repositories、releases、environments、values、bases、hooks。

常用示例

安装:

brew install helmfile
helmfile --version

helmfile.yaml:

repositories:
- name: bitnami
  url: https://charts.bitnami.com/bitnami

releases:
- name: nginx
  namespace: demo
  chart: bitnami/nginx
  version: 18.0.0
  values:
  - values/common.yaml
  - values/{{ .Environment.Name }}.yaml

指定环境:

helmfile -e prod diff
helmfile -e prod apply
helmfile -e prod sync

只操作某个 release:

helmfile -e prod -l name=nginx diff

易错点与排错

读完自测

合上页面,先回答,再展开对照。

  1. helmfile diff 报错说缺少插件时,前置条件是什么?
  2. 执行 helmfile -e prod sync 前必须确认什么?为什么?
  3. 密钥为什么不能明文写在 values 里?应该用什么方案?
答案
  1. 需要先安装 helm-diff 插件,否则 helmfile diff 会报错。
  2. 必须先确认操作范围,因为 sync 会删除不在 helmfile 中的 release。
  3. 明文密钥会泄露;应使用 SOPS 或 External Secrets。