<p>I'm running this tutorial <a href="https://www.elastic.co/guide/en/cloud-on-k8s/current/k8s-deploy-elasticsearch.html" rel="nofollow noreferrer">https://www.elastic.co/guide/en/cloud-on-k8s/current/k8s-deploy-elasticsearch.html</a> and found that the elasticsearch operator comes included with a pre-defined secret which is accessed through <code>kubectl get secret quickstart-es-elastic-user -o go-template='{{.data.elastic | base64decode}}'</code>. I was wondering how I can access it in a manifest file for a pod that will make use of this as an env var.  The pod's manifest is as follows:</p>
<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: user-depl
spec:
  replicas: 1
  selector:
    matchLabels:
      app: user
  template:
    metadata:
      labels:
        app: user
    spec:
      containers:
        - name: user
          image: reactor/user
          env:
            - name: PORT
              value: &quot;3000&quot;
            - name: ES_SECRET
              valueFrom:
                secretKeyRef:
                  name: quickstart-es-elastic-user
                  key: { { .data.elastic } }

---
apiVersion: v1
kind: Service
metadata:
  name: user-svc
spec:
  selector:
    app: user
  ports:
    - name: user
      protocol: TCP
      port: 3000
      targetPort: 3000
</code></pre>
<p>When trying to define <code>ES_SECRET</code> as I did in this manifest, I get this error message: <code>invalid map key: map[interface {}]interface {}{\&quot;.data.elastic\&quot;:interface {}(nil)}\n</code>. Any help on resolving this would be much appreciated.</p>

reactor
<p>The secret returned via API (<code>kubectl get secret ...</code>) is a JSON-structure, where there:</p>
<pre class="lang-json prettyprint-override"><code>{
  &quot;data&quot;: {
    &quot;elastic&quot;: &quot;base64 encoded string&quot;
  }
}
</code></pre>
<p>So you just need to replace</p>
<pre class="lang-yaml prettyprint-override"><code>key: { { .data.elastic } }
</code></pre>
<p>with</p>
<pre class="lang-yaml prettyprint-override"><code>key: elastic
</code></pre>
<p>since it's <code>secretKeyRef</code>erence (e.g. you refer a value in some <code>key</code> in <code>data</code> (=contents) of some secret, which name you specified above). No need to worry about base64 decoding; Kubernetes does it for you.</p>
