<p>In Azure Kubernetes Service, my goal is to configure both staging and production k8 clusters with a common YAML file, with critical values &amp; environment variables parameterized from a ConfigMap.</p>
<p>I can set container environment variables easily using valueFrom but I would like to use the ConfigMap values in other areas of the YAML file, for example:</p>
<p>staging-config-map.yaml:</p>
<pre><code>kind: ConfigMap 
apiVersion: v1 
metadata:
  name: base-config 
data:
  ENVIRONMENT_NAME: staging
  ...
</code></pre>
<p>prod-config-map.yaml:</p>
<pre><code>kind: ConfigMap 
apiVersion: v1 
metadata:
  name: base-config 
data:
  ENVIRONMENT_NAME: prod
  ...
</code></pre>
<p>common-cluster-config.yaml:</p>
<pre><code>apiVersion: v1
kind: Service
metadata:
  name: my-amazing-microservice
  annotations:
    service.beta.kubernetes.io/azure-dns-label-name: &quot;my-amazing-microservice-$ENVIRONMENT_NAME&quot;
spec:
  type: LoadBalancer
  ports:
  - targetPort: 5000
    name: port5000
    port: 5000
    protocol: TCP
  selector:
    app: my-amazing-microservice
---
...
</code></pre>
<p>Note the reference to $ENVIRONMENT_NAME which is where I want to insert something from the ConfigMap.</p>
<p>Can I do this, so I don't have to maintain duplicated manifests for staging and prod?</p>

Brendan Hill
<p>No you cant with vanilla k8's manifests. ConfigMaps are just resources that get mounted into the container when it starts. Either as env variables or as a file. You cant access a config map at deployment time.</p>
<p>I suggest looking into <a href="https://helm.sh/" rel="nofollow noreferrer">helm</a> that can do this with templating.</p>
