是否可以在 kustomize 中使用动态 namePrefix/nameSuffix?
Is it possible to have a dynamic namePrefix/nameSuffix in kustomize?
在 Helm 中,可以使用
指定发布名称
helm install my-release-name chart-path
这意味着,我可以使用 CLI 指定版本名称及其组件(使用全名)。
在kustomize中(我是kustomize的新手),有一个类似的概念,namePrefix
and nameSuffix
可以在kustomization.yaml
中定义
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
namePrefix: overlook-
resources:
- deployment.yaml
但是,这种方法需要一个自定义文件,使用“动态”名称前缀意味着必须使用模板生成 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 .
将 return 以下内容:
apiVersion: apps/v1
kind: Deployment
metadata:
name: dev-the-deployment
spec:
replicas: 5
template:
containers:
- image: registry/conatiner:latest
name: the-container
在 Helm 中,可以使用
指定发布名称helm install my-release-name chart-path
这意味着,我可以使用 CLI 指定版本名称及其组件(使用全名)。
在kustomize中(我是kustomize的新手),有一个类似的概念,namePrefix
and nameSuffix
可以在kustomization.yaml
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
namePrefix: overlook-
resources:
- deployment.yaml
但是,这种方法需要一个自定义文件,使用“动态”名称前缀意味着必须使用模板生成 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 .
将 return 以下内容:
apiVersion: apps/v1
kind: Deployment
metadata:
name: dev-the-deployment
spec:
replicas: 5
template:
containers:
- image: registry/conatiner:latest
name: the-container