问题描述
在 Helm 中,可以使用
指定发布名称helm install my-release-name chart-path
这意味着,我可以使用 CLI 指定版本名称及其组件(使用全名)。
在 kustomize(我是 kustomize 的新手)中,有一个类似的概念,namePrefix
和 nameSuffix
可以定义在 kustomization.yaml
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
namePrefix: overlook-
resources:
- deployment.yaml
但是,这种方法需要自定义文件,使用“动态”namePrefix 意味着必须使用模板生成 kustomization.yaml
,而 kustomize 是为了避免模板化。
有没有办法动态指定该值?
解决方法
您可以使用 kustomize edit
来编辑 nameprefix
和 namesuffix
值。
例如:
Deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: the-deployment
spec:
replicas: 5
template:
containers:
- name: the-container
image: registry/conatiner:latest
Kustomization.yaml
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- deployment.yaml
然后您可以运行 kustomize edit set nameprefix dev-
并且 kustomize build .
将返回以下内容:
apiVersion: apps/v1
kind: Deployment
metadata:
name: dev-the-deployment
spec:
replicas: 5
template:
containers:
- image: registry/conatiner:latest
name: the-container