Mounting ConfigMaps/Secrets as Volumes or Environment Variables

Learn how to put the latest open source technology into practice with hands-on training, delivered by industry experts, aligned to your desired business outcomes

ConfigMaps and Secrets are mounted by Pods as either volumes or environment variables to be used by container in a Pod.

ConfigMaps and Secrets can be used with a pod in two ways:

  • Files in a volume
  • Environment variables

Secrets can also be used by the kubelet when pulling images for a pod, called an imagePullSecret

The following Pod manifest mounts the ConfigMap ckad-example-config as a volume to the /etc/myapp directory in the container and uses a secret called “ckad-training-docker-token” as an imagePullSecret:

apiVersion: v1
kind: Pod
  name: pod-config
    - name: nginx
      image: nginx:latest
    - name: ckad-training-docker-token
      - name: config
        mountPath: /etc/myapp
    - name: config
        name: ckad-example-config

Learn more about mounting: