ConfigMap

ConfigMap

  • Centrally managed configuration data that can be passed to the containers as environment variables (key-value pairs).
  • Storing config data along with the pod/deployment definition file is not a good idea because as the application grows, managing them would become difficult.
  • Should be used to store parameters that are not secrets
⚠️
The data stored in the ConfigMap, when the container (pod) is created, is used to set the environment variables. If the ConfigMap gets updated later, the pod will continue to use the old values. We need to re-create the pods by performing a rollout (k rollout restart deployment <deployment-name>) on the deployment to make the new pods use the new data.

ConfigMap definition file

apiVersion: v1 kind: ConfigMap metadata: name: app-config data: USERNAME: arkalim PASSWORD: 12345
Using file as a ConfigMap:
apiVersion: v1 kind: ConfigMap metadata: name: rho-pacs-config namespace: 16bit data: orthanc.json: | { /** * General configuration of Orthanc **/ }

Using ConfigMap in Pods

  • Passing the entire ConfigMap of key-value pairs to ENV
    • apiVersion: v1 kind: Pod metadata: labels: name: app spec: containers: - name: nginx image: nginx envFrom: - configMapRef: name: app-config
  • Passing a single key-value pair from the ConfigMap to ENV
    • apiVersion: v1 kind: Pod metadata: labels: name: app spec: containers: - name: nginx image: nginx env: - name: USERNAME valueFrom: configMapKeyRef: name: app-config key: USERNAME
  • Passing a config file as ConfigMap (eg. nginx.conf) by mounting the ConfigMap as a volume
    • apiVersion: v1 kind: Pod metadata: labels: name: app spec: containers: - name: nginx image: nginx volumeMounts: - name: nginx-config-volume mountPath: /etc/nginx/conf.d/ volumes: - name: nginx-config-volume configMap: name: nginx-config