my-configmap.yaml
apiVersion: v1
kind: ConfigMap
metadata:
name: demo-config
data:
APP_MODE: "development"
WELCOME_MSG: "Willkommen in Kubernetes!"
kubectl apply -f my-configmap.yaml
pod-with-configmap.yaml
apiVersion: v1
kind: Pod
metadata:
name: configmap-demo
spec:
containers:
- name: demo-container
image: busybox
command: [ "sh", "-c", "env; echo; echo Datei-Inhalt:; cat /etc/config/WELCOME_MSG; sleep 3600" ]
env:
- name: APP_MODE
valueFrom:
configMapKeyRef:
name: demo-config
key: APP_MODE
volumeMounts:
- name: config-volume
mountPath: /etc/config
volumes:
- name: config-volume
configMap:
name: demo-config
kubectl apply -f pod-with-configmap.yaml
kubectl get pod configmap-demo
kubectl logs configmap-demo
→ Du solltest Folgendes sehen:
APP_MODE=development
aus Umgebungsvariable/etc/config/WELCOME_MSG
: Willkommen in Kubernetes!
Ändere z. B. den Begrüßungstext:
kubectl create configmap demo-config --from-literal=WELCOME_MSG="Hallo aus dem Cluster!" --from-literal=APP_MODE="production" -o yaml --dry-run=client | kubectl apply -f -
Danach:
kubectl delete pod configmap-demo
kubectl apply -f pod-with-configmap.yaml
→ Änderungen sind nur nach Neustart des Pods wirksam!
kubectl delete pod configmap-demo
kubectl delete configmap demo-config
Verwendung | Beschreibung |
---|---|
envFrom / env | Zugriff auf Werte als Umgebungsvariablen |
volumeMount | Zugriff auf Werte als Dateien im Container |
Live-Updates | Werden nicht automatisch erkannt – Pod muss neu gestartet werden |