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
ConfigMapusing thekubectlcommand,kubectl create configmap <configmap-name> --from-literal=<key>=<value> -
create a
ConfigMapusing adefinition,kubectl create configmap <configmap-name> --from-file=<path-to-file> -
get a
ConfigMapkubectl get configmap <configmap-name> -
describe a
ConfigMapkubectl describe configmap <configmap-name> -
delete a
ConfigMapkubectl delete configmap <configmap-name>
Examples π§©
-
sample
ConfigMapAPP_COLOR: blue APP_MODE: production -
sample
ConfigMapdefinitionapiVersion: v1 kind: ConfigMap metadata: name: sample-config data: APP_COLOR: blue APP_MODE: production -
sample
PoddefinitionapiVersion: v1 kind: Pod metadata: name: configmap-pod spec: containers: - name: configmap-container image: nginx ports: - containerPort: 80 envFrom: - configMapRef: name: sample-config