Junior — Middle
Explain the purpose and working principle of the ConfigMap object in Kubernetes
sobes.tech AI
Answer from AI
A ConfigMap in Kubernetes is used to store configuration data as key-value pairs, which can be used by containers in pods.
Main tasks of ConfigMap:
- Separating configuration from the container image to avoid rebuilding the image when settings change.
- Allowing dynamic configuration changes without modifying the code.
Principle of operation:
- ConfigMap is created as a Kubernetes object containing configuration data.
- In pods, ConfigMap can be mounted as files in volumes or passed as environment variables.
- Containers access this data and use it to configure their behavior.
Example of creating a ConfigMap and using it in a pod:
apiVersion: v1
kind: ConfigMap
metadata:
name: example-config
data:
APP_MODE: "production"
LOG_LEVEL: "info"
---
apiVersion: v1
kind: Pod
metadata:
name: example-pod
spec:
containers:
- name: app
image: myapp:latest
envFrom:
- configMapRef:
name: example-config
Thus, ConfigMap provides a convenient way to manage application configuration in Kubernetes.