<p>I'm trying to assign static IPs for Load Balancers in GKE to services by storing them in the <code>values.yaml</code> file as:</p>
<pre><code>ip:
  sandbox:
    service1: xxx.xxx.201.74
    service2: xxx.xxx.80.114
  dev:
    service1: xxx.xxx.249.203
    service2: xxx.xxx.197.77
  test:
    service1: xxx.xxx.123.212
    service2: xxx.xxx.194.133
  prod:
    service1: xxx.xx.244.211
    service2: xxx.xxx.207.177
</code></pre>
<p>All works fine till I want to deploy to prod and that will fail as:</p>
<pre><code>Error: UPGRADE FAILED: template: chart-v1/templates/service2-service.yaml:24:28: executing &quot;chart-v1/templates/service2-service.yaml&quot; at &lt;.Values.ip.prod.service2&gt;: nil pointer evaluating interface {}.service2
helm.go:94: [debug] template: chart-v1/templates/service2-service.yaml:24:28: executing &quot;chart-v1/templates/service2-service.yaml&quot; at &lt;.Values.ip.prod.service2&gt;: nil pointer evaluating interface {}.service2
</code></pre>
<p>and the part for <code>service2-service.yaml</code> looks like:</p>
<pre><code>apiVersion: v1
kind: Service
metadata:
  annotations:
    appName: {{ include &quot;common.fullname&quot; . }}
    componentName: service2
  labels:
    io.kompose.service: service2
  name: service2
spec:
  ports:
  - name: &quot;{{ .Values.service.service2.ports.name }}&quot;
    port: {{ .Values.service.service2.ports.port }}
    protocol: {{ .Values.service.service2.ports.protocol }}
    targetPort: {{ .Values.service.service2.ports.port }}
  type: LoadBalancer
{{ if eq .Values.target.deployment.namespace &quot;sandbox&quot; }}
  loadBalancerIP: {{ .Values.ip.sandbox.service2 }}
{{ else if eq .Values.target.deployment.namespace &quot;dev&quot; }}
  loadBalancerIP: {{ .Values.ip.dev.service2 }}
{{ else if eq .Values.target.deployment.namespace &quot;test&quot; }}
  loadBalancerIP: {{ .Values.ip.test.service2 }}
{{ else if eq .Values.target.deployment.namespace &quot;prod&quot; }}
  loadBalancerIP: {{ .Values.ip.prod.service2 }}
{{ else }}
{{ end }}
  selector:
    io.kompose.service: service2
status:
  loadBalancer: {}
</code></pre>
<p>Any clue why is complaining that is <code>nil</code> (empty)?</p>

JackTheKnife
<p>it could be due to the function changing the context and defined in <code>values.yaml</code></p>
<p>Normally with range, we can use the <strong>$</strong> for global scope, <code>appName: {{ include &quot;common.fullname&quot; $ }}</code></p>
<p>When tested the same template by keeping the static value of the <strong>appName</strong> it worked for me, so there is no issue with access from <code>values.yaml</code> unless <strong>nil</strong> is getting set at <strong>.Values.ip.prod.service2</strong>.</p>
<p>in other case as you mentioned <code>{{ (.Values.ip.prod).service2 }}</code> multiple level nesting will solve issue.</p>
