Config Maps
How to Create Config Maps
Imperative
From Literal
1kubectl create configmap \
2 <config-name> --from-literal=<key>=<value>
1kubectl create configmap \
2 <config-name> \
3 --from-literal=APP_COLOR=blue \
4 --from-literal=APP_COLOR_1=pink \
5 --from-literal=APP_COLOR_2=green \
From Path
1kubectl create configmap \
2 <config-name> --from-path=<path-to-file>
1kubectl create configmap \
2 <config-name> --from-path=app_config.properties
Declaritive
Config Map
Fiels Available
1apiVersion: v1
2kind:
3metadata:
4
5data:
Config Map
Example
1apiVersion: v1
2kind: ConfigMap
3metadata:
4 name: app-config
5data:
6 APP_COLOR: pink
7 APP_MODE: prod
Debug
Get Config Maps
kubectl get cm
NAME DATA AGE
kube-root-ca.crt 1 8d
Get Describe Maps
kubectl describe cm <config-map-name>
Name: kube-root-ca.crt
Namespace: default
Labels: <none>
Annotations: kubernetes.io/description:
Contains a CA bundle that can be used to verify the kube-apiserver when using internal endpoints such as the internal service IP or kubern...
Data
====
ca.crt:
----
-----BEGIN CERTIFICATE-----
-----END CERTIFICATE-----
BinaryData
====
Events: <none>
Use Config Map
CONFIG MAP
1apiVersion: v1
2kind: ConfigMap
3metadata:
4 name: app-config
5data:
6 APP_COLOR: pink
7 APP_MODE: prod
envFrom
1
2apiVersion:
3kind: Pod
4metadata:
5 name: simple-webapp-color
6spec:
7 containers:
8 - name: simple-webapp-color
9 image: simple-webapp-color
10 ports:
11 - containerPort: 8080
12
13 envFrom:
14 - configMapRef:
15 name: app-config
env valueFrom
1
2apiVersion:
3kind: Pod
4metadata:
5 name: simple-webapp-color
6spec:
7 containers:
8 - name: simple-webapp-color
9 image: simple-webapp-color
10 ports:
11 - containerPort: 8080
12
13 env:
14 - name: APP_COLOR
15 valueFrom:
16 name: app-config
17 key: APP_COLOR
volume
1
2apiVersion:
3kind: Pod
4metadata:
5 name: simple-webapp-color
6spec:
7 containers:
8 - name: simple-webapp-color
9 image: simple-webapp-color
10 ports:
11 - containerPort: 8080
12
13 volumes:
14 - name: app-config-volume
15 configMap:
16 name: app-config