This scenario shows:
- how to create config map (declerative way),
- how to use configmap: volume and environment variable,
- how to create configmap with command (imperative way),
- how to get/delete configmap
- Run minikube (in this scenario, K8s runs on WSL2- Ubuntu 20.04) ("minikube start")
- Create Yaml file (config.yaml) in your directory and copy the below definition into the file.
- File: https://github.com/omerbsezer/Fast-Kubernetes/blob/main/labs/configmap/configmap.yaml
apiVersion: v1
kind: ConfigMap
metadata:
name: myconfigmap
data:
db_server: "db.example.com" # configmap key-value parameters
database: "mydatabase"
site.settings: |
color=blue
padding:25px
---
apiVersion: v1
kind: Pod
metadata:
name: configmappod
spec:
containers:
- name: configmapcontainer
image: nginx
env: # configmap using environment variable
- name: DB_SERVER
valueFrom:
configMapKeyRef:
name: myconfigmap # configmap name, from "myconfigmap"
key: db_server
- name: DATABASE
valueFrom:
configMapKeyRef:
name: myconfigmap
key: database
volumeMounts:
- name: config-vol
mountPath: "/config"
readOnly: true
volumes:
- name: config-vol # transfer configmap parameters using volume
configMap:
name: myconfigmap
- Create configmap and the pod:
- Run bash in the pod:
- Define configmap with imperative way (--from-file and --from-literal) (create a file and put into "theme=dark")
- File: https://github.com/omerbsezer/Fast-Kubernetes/blob/main/labs/configmap/theme.txt
kubectl create configmap myconfigmap2 --from-literal=background=red --from-file=theme.txt
- Delete configmap: