<p>I'm new to Kubernetes. In my project I'm trying to use Kustomize to generate configMaps for my deployment. Kustomize adds a hash after the configMap name, but I can't get it to also change the deployment to use that new configMap name.</p>

<p>Deployment:</p>

<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: env-receiver-deployment
  labels:
    app: env-receiver-app
    project: env-project
spec:
  replicas: 1
  selector:
    matchLabels:
      app: env-receiver-app
  template:
    metadata:
      labels:
        app: env-receiver-app
        project: env-project
    spec:
      containers:
      - name: env-receiver-container
        image: eu.gcr.io/influxdb-241011/env-receiver:latest
        resources: {}
        ports:
        - containerPort: 8080
        envFrom:
        - configMapRef:
            name: env-receiver-config
        args: [ "-port=$(ER_PORT)", "-dbaddr=$(ER_DBADDR)", "-dbuser=$(ER_DBUSER)", "-dbpass=$(ER_DBPASS)" ]

</code></pre>

<p>kustomize.yml:</p>

<pre><code>apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
configMapGenerator:
- name: env-receiver-config
  literals:
  - ER_PORT=8080
  - ER_DBADDR=http://localhost:8086
  - ER_DBUSER=writeuser
  - ER_DBPASS=writeuser
</code></pre>

<p>Then I run kustomize, apply the deployment and check if it did apply the environment.</p>

<pre><code>$ kubectl apply -k .
configmap/env-receiver-config-258g858mgg created
$ kubectl apply -f k8s/deployment.yml
deployment.apps/env-receiver-deployment unchanged
$ kubectl describe pod env-receiver-deployment-76c678dcf-5r2hl 
Name:               env-receiver-deployment-76c678dcf-5r2hl
[...]
    Environment Variables from:
      env-receiver-config  ConfigMap  Optional: false
    Environment:           &lt;none&gt;
[...]
</code></pre>

<p>But it still gets its environment variables from: <code>env-receiver-config</code>, not <code>env-receiver-config-258g858mgg</code>.</p>

<p>My current workaround is to disable the hash suffixes in the <code>kustomize.yml</code>.</p>

<pre><code>generatorOptions:
  disableNameSuffixHash: true
</code></pre>

<p>It looks like I'm missing a step to tell the deployment the name of the new configMap. What is it?</p>

<p>It looks like the problem come from the fact that you generate the config map through kustomize but the deployment via kubectl directly without using kustomize.</p>

<p>Basically, kustomize will look for all the <code>env-receiver-config</code> in all your resources and replace them by the hash suffixed version.</p>

<p>For it to work, <strong>all</strong> your resources have to go through kustomize.
To do so, you need to add to your <code>kustomization.yml</code>:</p>

<pre><code>resources:
  - yourDeployment.yml
</code></pre>

<p>and then just run <code>kubectl apply -k .</code>. It should create both the ConfigMap and the Deployment using the right ConfigMap name</p>
