Kubernetes ConfigMap resource is a piece of simple key-value pair information that can be passed to any application running on K8S.
Sample file to create config map on a running cluster:
apiVersion: v1
kind: ConfigMap
metadata:
name: my-config-map #name of the config map
data:
myKey1: myValue1
myKey2: myValue2
Save this file as my-config-map.yaml and create config map on a cluster:
kubectl create -f my-config-map.yaml
Now, ref the values from config map inside a pod.
Lets create a sample busybox pod.
apiVersion: v1
kind: Pod
metadata:
name: my-pod
spec:
containers:
- name: my-pod
image: busybox
command: ["sh", "-c", "echo $MY_VAR"]
env:
- name: MY_VAR
valueFrom:
configMapKeyRef:
name: my-config-map
key: myKey1
Save this as my-pod.yaml and create a pod.
kubectl create -f my-pod.yaml
check the logs to see what is printed.
kubectl logs my-pod. #myValue1
Top comments (0)