Interview Prep/Real-World Interview/Write-a-Kubernetes-manifest tasks

Write a ConfigMap and Secret and inject them as environment variables and as a mounted file.

IntermediateHands-onWrite-a-Kubernetes-manifest tasks
Answer
apiVersion: v1
kind: ConfigMap
metadata: { name: app-config }
data:
  LOG_LEVEL: info
  app.yaml: |
    featureX: true
---
apiVersion: v1
kind: Secret
metadata: { name: app-secret }
type: Opaque
stringData:
  DB_PASSWORD: s3cr3t
---
# in the pod spec
containers:
  - name: app
    image: myapp:1.0
    envFrom:
      - configMapRef: { name: app-config }
    env:
      - name: DB_PASSWORD
        valueFrom:
          secretKeyRef: { name: app-secret, key: DB_PASSWORD }
    volumeMounts:
      - { name: cfg, mountPath: /etc/app, readOnly: true }
volumes:
  - name: cfg
    configMap:
      name: app-config
      items: [{ key: app.yaml, path: app.yaml }]

Key trick → stringData lets you write plain text and the API server base64-encodes it. Env vars don't update when the ConfigMap changes, but mounted files do (eventually, and not when mounted with subPath).

All Real-World Interview questions Roadmap: Interview readiness

More on Write-a-Kubernetes-manifest tasks