<p>When I try to install a Helm chart with a template file:</p>
<pre class="lang-yaml prettyprint-override"><code>{{ if eq .Release.Namespace &quot;fedx-app-1100&quot; }}{{ $nodePort := 30106 }}{{ end }}
apiVersion: v1
kind: Service
metadata:
  name: mysql
  namespace: {{ .Release.Namespace }} 
  labels:
    app: mysql
spec:
  type: NodePort
  ports:
  - port: 3306
    targetPort: 3306
    nodePort: {{ $nodePort }}
</code></pre>
<p>It produces an error:</p>
<pre class="lang-none prettyprint-override"><code>Error: parse error at (fedx-install/templates/mysql.yaml:21): undefined variable &quot;$nodePort&quot;
</code></pre>
<p>What causes this error?  How can I restructure the template file to avoid it?</p>

jinlong
<p>Just try this</p>
<pre><code>{{ if eq .Release.Namespace &quot;fedx-app-1100&quot; }}{{ $nodePort := 30106 }}
apiVersion: v1
kind: Service
metadata:
  name: mysql
  namespace: {{ .Release.Namespace }} 
  labels:
    app: mysql
spec:
  type: NodePort
  ports:
  - port: 3306
    targetPort: 3306
    nodePort: {{ $nodePort }}
{{ end }}
</code></pre>
