How to Set Environment Variable in a Pod Using ConfigMaps

Planted .

First, create a ConfigMap.

Then, in pod definition file, as an example:

apiVersion: v1
kind: Pod
metadata:
  name: sajal-pod
spec:
  containers:
    - name: sajal-container
      image: registry.k8s.io/busybox:1.27.2
      command: [ "/bin/sh", "-c", "env" ]
      env:
        - name: SPECIAL_LEVEL_KEY
          valueFrom:
            configMapKeyRef:
              name: myconfigmap
              key: username
  restartPolicy: Never

Updated . Thoughts? Email me.