Kubernetes - ConfigMaps πΊοΈ
Description π
ConfigMap
is a Kubernetes object that provides a way to store configuration data in key-value pairs. They allow you to decouple configuration artifacts from your container images, which enables you to modify the configuration data without rebuilding and repdeploying your containers. Just like everything else in Kubernetes there are two ways to create a ConfigMap
. You can either use the kubectl
command or you can use a ConfigMap
definition.
- example at
yaml-examples/configmap-description.yaml
To tie a ConfigMap
to a Pod you can use the envFrom
or env
section of the Pod definition.
- example at
yaml-examples/configmap-pod.yaml
Basic Commands
π
-
create a
ConfigMap
using thekubectl
command,kubectl create configmap <configmap-name> --from-literal=<key>=<value>
-
create a
ConfigMap
using adefinition
,kubectl create configmap <configmap-name> --from-file=<path-to-file>
-
get a
ConfigMap
kubectl get configmap <configmap-name>
-
describe a
ConfigMap
kubectl describe configmap <configmap-name>
-
delete a
ConfigMap
kubectl delete configmap <configmap-name>
Examples π§©
-
sample
ConfigMap
APP_COLOR: blue APP_MODE: production
-
sample
ConfigMap
definitionapiVersion: v1 kind: ConfigMap metadata: name: sample-config data: APP_COLOR: blue APP_MODE: production
-
sample
Pod
definitionapiVersion: v1 kind: Pod metadata: name: configmap-pod spec: containers: - name: configmap-container image: nginx ports: - containerPort: 80 envFrom: - configMapRef: name: sample-config