问题描述
出于CI / CD的目的,该项目正在维护2个kustomization.yaml文件
- 常规部署-kustomization_deploy.yaml
- 回滚部署-kustomization_rollback.yaml
要运行kustomize构建,当前目录中需要一个名称为“ kustomization.yaml”的文件。 如果项目要使用kustomization_rollback.yaml而不是kustomization.yaml,这怎么可能? kustomize是否接受文件名作为参数?文档未对此指定任何内容。
解决方法
当前无法更改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
分成2个目录kustomization_rollback
/kustomization.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
其他参考: