<p>Based on the instructions found here (<a href="https://kubernetes.io/docs/tasks/access-application-cluster/connecting-frontend-backend/" rel="nofollow noreferrer">https://kubernetes.io/docs/tasks/access-application-cluster/connecting-frontend-backend/</a>) I am trying to create an nginx deployment and configure it using a config-map. I can successfully access nginx using curl (yea!) but the configmap does not appear to be &quot;sticking.&quot;  The only thing it is supposed to do right now is forward the traffic along. I have seen the thread here (<a href="https://stackoverflow.com/questions/52773494/how-do-i-load-a-configmap-in-to-an-environment-variable">How do I load a configMap in to an environment variable?</a>). although I am using the same format, their answer was not relevant.</p>
<p>Can anyone tell me how to properly configure the configmaps?  the yaml is</p>
<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx
  namespace: sandbox
spec:
  selector:
    matchLabels:
      run: nginx
      app: dsp
      tier: frontend
  replicas: 2
  template:
    metadata:
      labels:
        run: nginx
        app: dsp
        tier: frontend
    spec:
      containers:
      - name: nginx
        image: nginx
        env:
        # Define the environment variable
        - name: nginx-conf
          valueFrom:
            configMapKeyRef:
              # The ConfigMap containing the value you want to assign to SPECIAL_LEVEL_KEY
              name: nginx-conf
              # Specify the key associated with the value
              key: nginx.conf
        resources:
          limits:
            memory: &quot;128Mi&quot;
            cpu: &quot;500m&quot;
        ports:
containerPort: 80 
</code></pre>
<p>the nginx-conf is</p>
<pre><code> # The identifier Backend is internal to nginx, and used to name this specific upstream
upstream Backend {
    # hello is the internal DNS name used by the backend Service inside Kubernetes
    server dsp;
}

server {
    listen 80;

    location / {
        # The following statement will proxy traffic to the upstream named Backend
        proxy_pass http://Backend;
    }
} 
</code></pre>
<p>I turn it into a configmap using the following line</p>
<pre><code>kubectl create configmap -n sandbox nginx-conf --from-file=apps/nginx.conf
</code></pre>

<p>You need to mount the configMap rather than use it as an environment variable, as the setting is not a key-value format.</p>
<p>Your Deployment yaml should be like below:</p>
<pre class="lang-yaml prettyprint-override"><code>containers:
- name: nginx
  image: nginx
  volumeMounts:
  - mountPath: /etc/nginx
    name: nginx-conf
volumes:
- name: nginx-conf
  configMap: 
    name: nginx-conf
    items:
      - key: nginx.conf
        path: nginx.conf
</code></pre>
<p>You need to create (apply) the configMap beforehand. You can create it from file:</p>
<pre><code>kubectl create configmap nginx-conf --from-file=nginx.conf
</code></pre>
<p>or you can directly describe configMap manifest:</p>
<pre><code>apiVersion: v1
kind: ConfigMap
metadata:
  name: nginx-conf
data:
  nginx.conf: |
    # The identifier Backend is internal to nginx, and used to name this specific upstream
    upstream Backend {
        # hello is the internal DNS name used by the backend Service inside Kubernetes
        server dsp;
    }
    ...
} 
</code></pre>
