can I remove all the helm generated labels and use my own labels?

1.1k Views Asked by At

When I do

helm create my-app

I get default labels like below in generated templates (deployment, service, ingress yaml files):

app.kubernetes.io/name: {{ include "my-app.name" . }}
helm.sh/chart: {{ include "my-app.chart" . }}
app.kubernetes.io/instance: {{ .Release.Name }}

Can I remove all of them and just use my own labels, will it affect helm features like rollback etc.???

2

There are 2 best solutions below

2
dippynark On BEST ANSWER

Yeah they can all be removed - from here:

Helm itself never requires that a particular label be present.

0
Gigi_men On

Probably in ./templates/_helpers.tpl there is a section similar to this

{{/*
Common labels
*/}}
{{- define "{CHART_NAME}.labels" -}}
helm.sh/chart: {{ include "{CHART_NAME}.chart" . }}
{{ include "{CHART_NAME}.selectorLabels" . }}
{{- if .Chart.AppVersion }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- end }}

{{/*
Selector labels
*/}}
{{- define "{CHART_NAME}.selectorLabels" -}}
app.kubernetes.io/name: {{ include "{CHART_NAME}.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}

Also, in the labels section of each object that is being labeled there should be something like the next, that references the helper:

  labels:
    {{- include "{CHART_NAME}.labels" . | nindent 4 }}

If you just want to remove those labels, you can remove that block or delete the variables that sets each of the labels to the value that you want.