ConfigMaps are used to pass configuration data in the form of key-value pairs.
Creating a ConfigMap, the imperative way:
# command syntax:
kubectl create configmap ${configName} --from-literal=${key}=${value}
# example:
kubectl create configmap app-config \
--from-literal=APP_COLOR=blue \
--from-literal=APP_MOD=prod
# getting the key-value pairs from a file
kubectl create configmap app-config \
--from-file=app_config.properties
ConfigMap, the declarative way:
apiVersion: v1
kind: ConfigMap
metadata:
name: app-config
data:
APP_COLOR: blue
APP_MODE: prod
WARNING: a ConfigMap definition file doesn't need a spec
.
ConfigMap in Pods:
# ... pod's definition
spec:
containers:
- # ...
envFrom:
- configMapRef:
name: ${configMapName}
3 ways to use ConfigMaps in Pods:
# env var from whole config map
pod.spec.containers:
- envFrom:
- configMapRef:
name: app-config
# single env var from the config map
pod.spec.containers:
env:
- name: APP_COLOR
valueFrom:
configMapKeyRef:
name: app-config
key: APP_COLOR
# volume
pod.spec.containers:
volumes:
- name: app-config-volume
configMap:
name: app-config
practicing: https://kodekloud.com/topic/configmaps-2/