[英]Helm, Is there a way to add kubernetes labels to values.yaml (without using template and _helpers.tpl)
So as in the title, I would like to add labels to my helms of my already running applications (sonarqube and jenkins from official helm charts).因此,如标题所示,我想为我已经运行的应用程序的 helm 添加标签(来自官方 helm 图表的 sonarqube 和 jenkins)。 I don't have templates in them just values.yaml.我没有模板,只有 values.yaml。 I am afraid of adding templates, because as I said, application is already running and I just want to add few labels in metadata.我害怕添加模板,因为正如我所说,应用程序已经在运行,我只想在元数据中添加一些标签。
Both charts mentioned in comment under question has a way to define custom labels有问题的评论中提到的两个图表都有定义自定义标签的方法
https://github.com/jenkinsci/helm-charts/blob/main/charts/jenkins/templates/jenkins-master-deployment.yaml#L42 https://github.com/jenkinsci/helm-charts/blob/main/charts/jenkins/templates/jenkins-master-deployment.yaml#L42
{{- range $key, $val := .Values.master.podLabels }}
{{ $key }}: {{ $val | quote }}
{{- end}}
https://github.com/Oteemo/charts/blob/master/charts/sonarqube/templates/deployment.yaml#L31 https://github.com/Oteemo/charts/blob/master/charts/sonarqube/templates/deployment.yaml#L31
{{- with .Values.podLabels }}
{{ toYaml . | indent 8 }}
{{- end }}
So you need something like this in values.yaml
所以你在values.yaml
中需要这样的东西
# Jenkins
master:
podLabels:
label1Name: label1Value
# Sonar
podLabels:
label1Name: label1Value
As described by @rkosegi this solution uses best practices while working with k8s configurations.正如@rkosegi所述,此解决方案在使用 k8s 配置时使用了最佳实践。
Please keep in mind, that users always should store configuration files ( Configuration Best Practices ).请记住,用户始终应该存储配置文件( 配置最佳实践)。 It allows us to quickly change/roll back any configuration in an easy way, using:它允许我们以简单的方式快速更改/回滚任何配置,使用:
kubectl apply -f ...
kubectl replace ...
Another solutions:另一个解决方案:
kubectl edit deployment <deployment_name> kubectl 编辑部署<deployment_name>
Update API Objects in Place Using kubectl patch : 使用 kubectl patch 更新 API 对象:
a ) adding or changing existing labels: a ) 添加或更改现有标签:
#patch-file.yaml
spec:
template:
metadata:
labels:
test: label
kubectl patch deployment <deployment-name> --patch "$(cat patch-file.yaml)"
b ) using a json patch approach, you can: b ) 使用 json 补丁方法,您可以:
kubectl patch deployment <deployment-name> --type='json' -p='[{"op": "add", "path": "/spec/template/metadata/labels/NewTest", "value":"TestValue"}]'
kubectl patch deployment <deployment-name> --type='json' -p='[{"op": "replace", "path": "/spec/template/metadata/labels/NewTest", "value": "OldTest"}]'
kubectl patch deployment <deployment-name> --type='json' -p='[{"op": "remove", "path": "/spec/template/metadata/labels/NewTest"}]'
Additional informations:附加信息:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.