使用不同名称的 kustomization.yaml

Gir*_*ish 5 kubernetes kubectl kustomize

出于 CI/CD 的目的,该项目正在维护 2 个 kustomization.yaml 文件

  1. 常规部署 - kustomization_deploy.yaml
  2. 回滚部署 - kustomization_rollback.yaml

要运行 kustomize build,当前目录中需要一个名为“kustomization.yaml”的文件。如果项目要使用 kustomization_rollback.yaml 而不是 kustomization.yaml,这怎么可能?kustomize 是否接受文件名作为参数?文档对此没有指定任何内容。

Daw*_*ruk 8

目前无法更改行为kustomize以支持其他文件名(通过使用预编译的二进制文件):

  • kustomization.yaml
  • kustomization.yml
  • Kustomization

以下所有情况都会产生相同的错误输出:

  • kubectl kustomize dir/
  • kubectl apply -k dir/
  • kustomize build dir/
Error: unable to find one of 'kustomization.yaml', 'kustomization.yml' or 'Kustomization' in directory 'FULL_PATH/dir'
Run Code Online (Sandbox Code Playgroud)

根据 CI/CD 平台/解决方案/工具,您应该尝试其他方法,例如:

  • 将其分成Deployment2 个目录kustomization_deploy/kustomization_rollbackkustomization.yaml

作为旁注!

kustomize 使用的文件名放置在:

  • /kubernetes/vendor/sigs.k8s.io/kustomize/pkg/constants/constants.go
// Package constants holds global constants for the kustomize tool.
package constants

// KustomizationFileNames is a list of filenames that can be recognized and consumbed
// by Kustomize.
// In each directory, Kustomize searches for file with the name in this list.
// Only one match is allowed.
var KustomizationFileNames = []string{
  "kustomization.yaml",
  "kustomization.yml",
  "Kustomization",
}
Run Code Online (Sandbox Code Playgroud)

选择文件背后的逻辑Kustomization位于:

  • /kubernetes/vendor/sigs.k8s.io/kustomize/pkg/target/kusttarget.go

附加参考: