<p>I'm trying to figure it out, how to change one string inside configmap in Kubernetes. I have pretty simple configmap:</p>
<pre><code>apiVersion: v1
data:
  config.cfg: |-
    [authentication]
    USERNAME=user
    PASSWORD=password
     
    [podname]
    PODNAME=metadata.podName

kind: ConfigMap
metadata:
  name: name_here
</code></pre>
<p>And I need to mount the configmap inside a couple of pods. But PODNAME should be matched to current podname. Is it possible in any another way? thanks!</p>

Roman
<p>I do not think it could be done with ConfigMap. But you can set environment variables in your pod spec that references a pod fields.</p>
<pre><code>apiVersion: v1
kind: Pod
metadata:
  name: test-ref-pod-name
spec:
  containers:
    - name: test-container
      image: busybox
      command: [ &quot;sh&quot;, &quot;-c&quot;]
      args:
      - env | grep PODNAME
      env:
        - name: PODNAME
          valueFrom:
            fieldRef:
              fieldPath: metadata.name
  restartPolicy: Never
</code></pre>
<p>See official documentation: <a href="https://kubernetes.io/docs/tasks/inject-data-application/environment-variable-expose-pod-information/#use-pod-fields-as-values-for-environment-variables" rel="nofollow noreferrer">https://kubernetes.io/docs/tasks/inject-data-application/environment-variable-expose-pod-information/#use-pod-fields-as-values-for-environment-variables</a></p>
