On a Kubernetes Pod, what is the ConfigMap directory location?

1/13/2017

Many applications require configuration via some combination of config files, command line arguments, and environment variables. These configuration artifacts should be decoupled from image content in order to keep containerized applications portable. The ConfigMap API resource provides mechanisms to inject containers with configuration data while keeping containers agnostic of Kubernetes. ConfigMap can be used to store fine-grained information like individual properties or coarse-grained information like entire config files or JSON blobs.

I am unable to find where configmaps are saved. I know they are created however I can only read them via the minikube dashboard.

-- Max Copley
config-files
docker
kubernetes
minikube

1 Answer

1/13/2017

ConfigMaps in Kubernetes can be consumed in many different ways and mounting it as a volume is one of those ways.

You can choose where you would like to mount the ConfigMap on your Pod. Example from K8s documentation:

ConfigMap:

apiVersion: v1
kind: ConfigMap
metadata:
  name: special-config
  namespace: default
data:
  special.how: very
  special.type: charm

Pod

apiVersion: v1
kind: Pod
metadata:
  name: dapi-test-pod
spec:
  containers:
    - name: test-container
      image: gcr.io/google_containers/busybox
      command: [ "/bin/sh", "-c", "cat /etc/config/special.how" ]
      volumeMounts:
      - name: config-volume
        mountPath: /etc/config
  volumes:
    - name: config-volume
      configMap:
        name: special-config
  restartPolicy: Never

Note the volumes definition and the corresponding volumeMounts.

Other ways include:

  • Consumption via environment variables
  • Consumption via command-line arguments

Refer to the documentation for full examples.

-- Sukumar
Source: StackOverflow