ConfigMaps & Secrets
Build once, configure per environment. The same demo-app:1.0 image runs in dev, staging and prod. Only config changes.
ConfigMap: non-sensitive settings
Section titled “ConfigMap: non-sensitive settings”apiVersion: v1kind: ConfigMapmetadata: { name: demo-config, namespace: demo }data: APP_MESSAGE: "Hello from Kubernetes!" APP_COLOR: "#4f8cff"Use it as env vars (all keys at once, or one at a time):
envFrom: - configMapRef: { name: demo-config }env: - name: COLOR valueFrom: { configMapKeyRef: { name: demo-config, key: APP_COLOR } }…or mount it as files (good for whole config files like nginx.conf):
volumes: [{ name: cfg, configMap: { name: demo-config } }]volumeMounts: [{ name: cfg, mountPath: /etc/demo }]Secret: passwords, tokens, keys
Section titled “Secret: passwords, tokens, keys”kubectl create secret generic db -n demo \ --from-literal=DB_PASSWORD='s3cr3t'envFrom: [{ secretRef: { name: db } }]