codegurukool.com · Free coding tutorials & online compiler

Home › Kubernetes Tutorial › Use ConfigMaps and Secrets in a Pod

Use ConfigMaps and Secrets in a Pod

Pass settings into containers.

Use valueFrom to take one value from a ConfigMap (configMapKeyRef) or a Secret (secretKeyRef) and expose it as an environment variable. Use envFrom to load every key at once.

Example code

apiVersion: v1
kind: Pod
metadata:
  name: app
spec:
  containers:
    - name: app
      image: busybox:1.36
      command: [sleep, 3600]
      env:
        - name: APP_MODE
          valueFrom:
            configMapKeyRef:
              name: app-config
              key: APP_MODE
        - name: DB_PASSWORD
          valueFrom:
            secretKeyRef:
              name: db-pass
              key: password

Run this code in the online editor

← SecretsVolumes and persistent storage →