<p>I'm looking for a possible way to reference the secrets in my deployment.yaml (1 liner)</p>

<p>Currently I'm using the</p>

<pre class="lang-sh prettyprint-override"><code>containers:
        - name: {{ template "myapp.name" . }}
          image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
          imagePullPolicy: Always
          env:
            - name: COUCHDB_USER
              valueFrom:
                secretKeyRef:
                  name: {{ .Release.Name }}-secrets
                  key: COUCHDB_USER
            - name: COUCHDB_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: {{ .Release.Name }}-secrets
                  key: COUCHDB_PASSWORD
</code></pre>

<p>With the minimal modification possible, I want to achieve something like this:</p>

<pre class="lang-sh prettyprint-override"><code>containers:
        - name: {{ template "myapp.name" . }}
          image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
          imagePullPolicy: Always
          env:
            - name: COUCHDB_URL
              value: http://${COUCHDB_USER}:${COUCHDB_PASSWORD}@{{ .Release.Name }}-couchdb:5984
</code></pre>

<p>Just carious if I can do this in 1 step in during the deployment, instead of passing 2 env vars and parse them in my application.</p>

<p>I am not seeing any way to achieve it without setting <code>COUCHDB_USER</code> and <code>COUCHDB_PASSWORD</code> in container env. </p>

<p>One workaround is, you can specify your secret in <code>container.EnvFrom</code> and all your secret <code>keys</code> will be converted to Environment variables. then, You can use those environment variables to create your composite env (ie, COUCHDB_URL). </p>

<p>FYI, To create env from another env in kubernetes, <code>()</code> is used. Curly braces <code>{}</code> won't work at this very moment. </p>

<hr>

<p>One sample is, </p>

<pre class="lang-sh prettyprint-override"><code>apiVersion: v1
kind: Secret
metadata:
  name: mysecret
type: Opaque
data:
  COUCHDB_USER: YWRtaW4=
  COUCHDB_PASSWORD: MWYyZDFlMmU2N2Rm
---
apiVersion: v1
kind: Pod
metadata:
  name: secret-env-pod
spec:
  containers:
  - name: mycontainer
    image: redis
    envFrom:
    - secretRef:
        name: mysecret
    env:
    - name: COUCHDB_URL
      value: http://$(COUCHDB_USER):$(COUCHDB_PASSWORD)rest-of-the-url
</code></pre>

<p>You can confirm, the output by,</p>

<pre><code>$ kubectl exec -it secret-env-pod bash

root@secret-env-pod:/data# env | grep COUCHDB
COUCHDB_URL=http://admin:1f2d1e2e67dfrest-of-the-url
COUCHDB_PASSWORD=1f2d1e2e67df
COUCHDB_USER=admin
</code></pre>

<hr>

<p>In your case, the yaml for container is:</p>

<pre class="lang-sh prettyprint-override"><code>    containers:
    - name: {{ template "myapp.name" . }}
      image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
      imagePullPolicy: Always
      envFrom:
      - secretRef:
          name: {{ .Release.Name }}-secrets
      env:
      - name: COUCHDB_URL
        value: http://$(COUCHDB_USER):$(COUCHDB_PASSWORD)@{{ .Release.Name }}-couchdb:5984
</code></pre>
