Kubernetes: ConfigMaps and Secrets

ConfigMap is used to store data in key-value format.

Create ConfigMap from literals:

kubectl create configmap <configmap_name> \
--from-literal <key1>=<value1> \
--from-literal <key2>=<value2>

Create ConfigMap from files:

kubectl create configmap <configmap_name> \
--from-file <config_file1> \
--from-file <config_file2>
kubectl create configmap <configmap_name> \
--from-file <directory_with_config_files>

Create ConfigMap for ENV files:

kubectl create configmap <configmap_name> \
--from-env-file <env_file1>

To add ConfigMap as environment variables, add this to the spec.containers.container section for Pod or spec.template.spec.containers.container for Deployment.

...
env:
  - name: SOME_ENV
    valueFrom:
      configMapKeyRef:
        name: <configmap_name>
        key: <configmap_key>

envFrom:
- configMapRef:
    name: <configmap1_name>
- configMapRef:
    name: <configmapN_name>
- secretRef:
    name: <secret1_name>
- secretRef:
    name: <secretN_name>
...

References:


Comments

Leave a Reply

Your email address will not be published. Required fields are marked *