Exposing ConfigMap as files inside the container

Exposing ConfigMap data into files within a container is very similar to how annotations and labels are exposed into a container. There are two parts to the specification on a Pod. The first is defining a volume for the container, including a name for it, and the location for where it should be mounted:

        volumeMounts:          - name: config            mountPath: /etc/kconfig            readOnly: true

The second part is a volume description that references the same name for the volume and lists ConfigMap as a property to indicate where to get the values:

      volumes:        - name: config          configMap:            name: example-config

Once that specification is applied, the values will be available as files within the container:

ls -al /etc/kconfig/ ...

Get Kubernetes for Developers now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.