<p>Defined labels in temp with top of the same deployment.yml file-</p>
<pre><code>{{- define &quot;chart.labels&quot; }} 
  version: v1.0
  method: http
  internet: enabled
{{- end }}
</code></pre>
<p>I have deployment.yml file in template folder-</p>
<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: app1-deployment
  namespace: {{ .Values.global.namespace }}
  labels:
    app: app1
    type: microservice1
spec:
  replicas: 3
  selector:
    matchLabels:
      app: app1
      type: microservice1
  strategy:
    type: {{ .Values.global.strategytype }}
  template:
    metadata:
      labels:
        app: app1
        type: microservice1
        {{- template &quot;chart.labels&quot; }}
</code></pre>
<p>The Two ways - one from the keyword <em>template</em> (last line of the below code)</p>
<p>And second one from the <em>include</em> keyword I am trying to call the template.</p>
<pre><code>{{include &quot;chart.labels&quot; . | indent 8 }}
</code></pre>
<ul>
<li>I am getting <strong>error</strong> ( when I am using keyword <em>template</em> to call
the template).</li>
</ul>
<blockquote>
<p>Error: YAML parse error on chart/templates/deployment.yml: error
converting YAML to JSON: yaml: line 27: did not find expected key
helm.go:81: [debug] error converting YAML to JSON: yaml: line 27: did
not find expected key YAML parse error on
chart/templates/deployment.yml
helm.sh/helm/v3/pkg/releaseutil.(*manifestFile).sort
helm.sh/helm/v3/pkg/releaseutil/manifest_sorter.go:146 helm.sh/helm/v3/pkg/releaseutil.SortManifests
helm.sh/helm/v3/pkg/releaseutil/manifest_sorter.go:106 helm.sh/helm/v3/pkg/action.(*Configuration).renderResources
helm.sh/helm/v3/pkg/action/action.go:165 helm.sh/helm/v3/pkg/action.(*Install).Run
helm.sh/helm/v3/pkg/action/install.go:247</p>
</blockquote>
<ul>
<li>Getting another <strong>error</strong> (when I use <em>Include</em> keyword to call the
template)</li>
</ul>
<blockquote>
<p>Error: YAML parse error on chart/templates/deployment.yml: error
converting YAML to JSON: yaml: line 29: mapping values are not allowed
in this context helm.go:81: [debug] error converting YAML to JSON:
yaml: line 29: mapping values are not allowed in this context YAML
parse error on chart/templates/deployment.yml
helm.sh/helm/v3/pkg/releaseutil.(*manifestFile).sort
helm.sh/helm/v3/pkg/releaseutil/manifest_sorter.go:146 helm.sh/helm/v3/pkg/releaseutil.SortManifests
helm.sh/helm/v3/pkg/releaseutil/manifest_sorter.go:106 helm.sh/helm/v3/pkg/action.(*Configuration).renderResources
helm.sh/helm/v3/pkg/action/action.go:165 helm.sh/helm/v3/pkg/action.(*Install).Run
helm.sh/helm/v3/pkg/action/install.go:247 main.runInstall</p>
</blockquote>
<p>What am I missing here ?</p>

<p>You need to follow sane indentation. You have:</p>
<pre><code>{{- define &quot;chart.labels&quot; }} 
  version: v1.0
  method: http
  internet: enabled
{{- end }}
</code></pre>
<p>Note there is no double space in chart.labels definition below.</p>
<p>The below works:</p>
<pre><code>{{- define &quot;chart.labels&quot; }} 
version: v1.0
method: http
internet: enabled
{{- end }}

apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ include &quot;test.fullname&quot; . }}
  labels:
    {{- include &quot;test.labels&quot; . | nindent 4 }}
spec:
{{- if not .Values.autoscaling.enabled }}
  replicas: {{ .Values.replicaCount }}
{{- end }}
  selector:
    matchLabels:
      {{- include &quot;test.selectorLabels&quot; . | nindent 6 }}
  template:
    metadata:
    {{- with .Values.podAnnotations }}
      annotations:
        {{- toYaml . | nindent 8 }}
    {{- end }}
      labels:
      {{- include &quot;test.selectorLabels&quot; . | nindent 8 }}
      {{include &quot;chart.labels&quot; . | nindent 8 }}
</code></pre>
<p>Edit: Or only change the nindent to match chart.labels in the template meta as below:</p>
<pre><code>{{include &quot;chart.labels&quot; . | nindent 6 }}
</code></pre>
