- Using a k8s ConfigMap manifest:
kubectl create -f settings.configmap.yml - Load settings from a file:
kubectl create cm app-settings --from-file=settings.properties. Will add file name as key into ConfigMap data. Will NOT add quotes around non-string values. - Load settings from an env file:
kubectl create cm app-settings --from-env-file=settings.config. Will NOT add file name as key into ConfigMap data. Will add quotes around non-string values. - Define settings in kubectl command:
kubectl create cm app-settings --from-literal=apiUurl=https://my-api --from-literal=otherKey=otherValue --from-literal=count=50. Will add quotes around non-string values.
Demo of accessing ConfigMap data in a Pod container through environment variables and direct settings.
- Delete any ConfigMaps you added into k8s above via:
kubectl delete cm app-settings
- Build image:
docker build -t node-configmap . - Create ConfigMap:
kubectl create cm app-settings --from-env-file=settings.config
- Create deployment:
kubectl apply -f node.deployment.yml
- Port forward the Pod:
kubectl port-forward [pod-name] 9000
- Visit
http://localhost:9000and view the ConfigMap settings output