【问题标题】:Use different name of the kustomization.yaml使用不同的 kustomization.yaml 名称
【发布时间】:2020-11-04 14:23:58
【问题描述】:

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

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

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

【问题讨论】:

  • 恐怕改名kustomization.yaml是不行的。您是否考虑过将Deployment 拆分为两个目录kustomization_deploy/kustomization_rollback,每个目录分别包含kustomization.yaml
  • 同意,如果无法更改 kustomization.yaml 的名称,有不同的方法来处理这个问题

标签: kubernetes kubectl kustomize


【解决方案1】:

目前无法更改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'

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

  • Deployment 拆分为两个目录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",
}

选择Kustomization文件背后的逻辑放在:

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

补充参考:

【讨论】:

  • @Girish 您的问题已得到解答。将此标记为正确答案。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-10-14
相关资源
最近更新 更多