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). I don't have templates in them just 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.
As described by @rkosegi this solution uses best practices while working with k8s configurations.
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>
a) adding or changing existing labels:
#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:
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:
Both charts mentioned in comment under question has a way to define custom labels
{{- range $key, $val := .Values.master.podLabels }}
{{ $key }}: {{ $val | quote }}
{{- end}}
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 is values.yaml
# Jenkins
master:
podLabels:
label1Name: label1Value
# Sonar
podLabels:
label1Name: label1Value