title: Helm Chart Labels and Selectors
body: <p>I create a helm chart with <code>helm create</code>command for Helm v3 and it creates for me standart template.Because of I am new to using Helm, I have some confusion to use selector and labels.</p>
  
  <p>So how should use the labels between the deployment.yaml and services.yaml?</p>
  
  <p>Use <code>include-road-dashboard.labels</code> command already do the same thing as below or I need to specify the labels separate like as below command. My question is same as well for <code>{{ include "road-dashboard.selectorLabels" . }}</code> command.</p>
  
  <p><strong>Updated Template</strong></p>
  
  <pre><code>apiVersion: apps/v1
  kind: Deployment
  metadata:
    name: {{ include "road-dashboard.fullname" . }}
    labels:
      app.kubernetes.io/name: {{ include "road-dashboard.name" . }}
      helm.sh/chart: {{ include "road-dashboard.chart" . }}
      app.kubernetes.io/instance: {{ .Release.Name }}
      app.kubernetes.io/managed-by: {{ .Release.Service }}
  </code></pre>
  
  <hr>
  
  <p><strong>Helm Standart Template</strong></p>
  
  <p><strong>deployment.yaml</strong></p>
  
  <pre><code>apiVersion: apps/v1
  kind: Deployment
  metadata:
    name: {{ include "road-dashboard.fullname" . }}
    labels:
      {{- include "road-dashboard.labels" . | nindent 4 }}
  spec:
    replicas: {{ .Values.replicaCount }}
    selector:
      matchLabels:
        {{- include "road-dashboard.selectorLabels" . | nindent 6 }}
    template:
      metadata:
        labels:
          {{- include "road-dashboard.selectorLabels" . | nindent 8 }}
      spec:
  </code></pre>
  
  <p><strong>service.yaml</strong></p>
  
  <pre><code>apiVersion: v1
  kind: Service
  metadata:
    name: {{ include "road-dashboard.fullname" . }}
    labels:
      {{- include "road-dashboard.labels" . | nindent 4 }}
  spec:
    type: {{ .Values.service.type }}
    ports:
      - port: {{ .Values.service.port }}
        targetPort: http
        protocol: TCP
        name: http
    selector:
      {{- include "road-dashboard.selectorLabels" . | nindent 4 }}
  </code></pre>
  
  <p><strong>-helpers.tpl</strong></p>
  
  <pre><code>  {{/*
  Common labels
  */}}
  {{- define "road-dashboard.labels" -}}
  helm.sh/chart: {{ include "road-dashboard.chart" . }}
  {{ include "road-dashboard.selectorLabels" . }}
  {{- if .Chart.AppVersion }}
  app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
  {{- end }}
  app.kubernetes.io/managed-by: {{ .Release.Service }}
  {{- end -}}
  
  {{/*
  Selector labels
  */}}
  {{- define "road-dashboard.selectorLabels" -}}
  app.kubernetes.io/name: {{ include "road-dashboard.name" . }}
  app.kubernetes.io/instance: {{ .Release.Name }}
  {{- end -}}
  </code></pre>