Cheat SheetsKubernetesConfiguration

Configuration — Cheat Sheet

Kubernetes · 1 topics. Download the PDF or the Instagram carousel and share it.

Cheat Sheet · AiCanCode.org
Configuration
Kubernetes1 topicsQuick revision reference
1

ConfigMaps & Secrets

ConfigMaps store non-sensitive configuration; Secrets store sensitive data (passwords, tokens, certs). Both decouple configuration from container images and can be injected as environment variables or mounted as files.

  • ConfigMaps for non-sensitive config; Secrets for passwords, keys, and certs.
  • Both decouple config from images — change config without rebuilding the image.
  • Prefer mounting secrets as files over env vars — not visible in process list or docker inspect.
  • Base64 is encoding, not encryption — etcd encryption at rest or external secret managers are needed for true security.
  • Updates to ConfigMaps/Secrets are not automatically picked up by running pods — you need a rolling restart.
  • envFrom: configMapRef injects all keys at once; env.valueFrom.configMapKeyRef injects one key.
configmap.yaml — ConfigMap usage patterns
# configmap.yaml

apiVersion: v1

kind: ConfigMap

metadata:

  name: my-app-config

data:

  LOG_LEVEL: "info"

  DATABASE_HOST: "postgres.production.svc.cluster.local"

  DATABASE_PORT: "5432"

  MAX_CONNECTIONS: "100"

  # Multi-line value: a full config file

  nginx.conf: |

    server {

      listen 80;

      location /health { return 200 'OK'; }

    }



---

# Use ConfigMap in a Deployment — method 1: envFrom (all keys as env vars)

spec:

  containers:

    - name: app

      image: my-app:v1.2.3

      envFrom:

        - configMapRef:

            name: my-app-config



# method 2: specific key as env var

      env:

        - name: LOG_LEVEL

          valueFrom:

            configMapKeyRef:

              name: my-app-config

              key: LOG_LEVEL



# method 3: mount as file

      volumeMounts:

        - name: config-vol

          mountPath: /etc/nginx/conf.d/

  volumes:

    - name: config-vol

      configMap:

        name: my-app-config

        items:

          - key: nginx.conf

            path: nginx.conf

# Result: /etc/nginx/conf.d/nginx.conf is the ConfigMap value
Learn this free with Aria, your AI tutor → AiCanCode.org/learn/kubernetes