Kubernetes
ConfigMaps
Volume Mount
Troubleshooting
DevOps

Kubernetes ConfigMap volume mount issues: subPath, defaultMode, updates

Codemia Knowledge Hub ·

Most ConfigMap volume problems come from one fact: Kubernetes replaces the contents of the mount directory with the ConfigMap's files. That explains hidden image files, and the fix (subPath) explains why some updates never reach the pod. The other usual issues are file permissions, missing ConfigMaps and path mismatches.

Basic ConfigMap volume mount

yaml
1apiVersion: v1
2kind: ConfigMap
3metadata:
4  name: app-config
5data:
6  app.properties: |
7    database.host=db.example.com
8    database.port=5432
9  logging.conf: |
10    level=INFO
11    format=json
12---
13apiVersion: v1
14kind: Pod
15metadata:
16  name: myapp
17spec:
18  containers:
19    - name: app
20      image: myapp:latest
21      volumeMounts:
22        - name: config-volume
23          mountPath: /etc/config
24  volumes:
25    - name: config-volume
26      configMap:
27        name: app-config

This creates /etc/config/app.properties and /etc/config/logging.conf in the container. Each key becomes a file name and each value becomes the file content.

Issue 1: the mount hides existing files in the directory

yaml
1# PROBLEM: mounting to /etc/config replaces everything in that directory
2volumeMounts:
3  - name: config-volume
4    mountPath: /etc/config  # All existing files in /etc/config are hidden
5
6# FIX: Use subPath to mount individual files without overwriting
7volumeMounts:
8  - name: config-volume
9    mountPath: /etc/config/app.properties
10    subPath: app.properties
11  - name: config-volume
12    mountPath: /etc/config/logging.conf
13    subPath: logging.conf

Mounting a ConfigMap on a directory replaces that directory's contents, so any files the image had at that path become invisible. subPath mounts individual files and leaves the rest of the directory alone.

Issue 2: ConfigMap updates do not reach the pod

yaml
1# Without subPath — updates propagate (with delay)
2volumeMounts:
3  - name: config-volume
4    mountPath: /etc/config
5# ConfigMap updates appear in ~60-90 seconds
6
7# With subPath — updates DO NOT propagate
8volumeMounts:
9  - name: config-volume
10    mountPath: /etc/config/app.properties
11    subPath: app.properties
12# ConfigMap updates are NOT reflected — pod restart required

A directory mount (no subPath) is synced periodically. A subPath file is a static bind mount and never receives updates, so you must restart the pod to pick up changes. Choose directory mounts when you need live updates.

Issue 3: file permissions and defaultMode

yaml
1volumes:
2  - name: config-volume
3    configMap:
4      name: app-config
5      defaultMode: 0644  # Read/write for owner, read for others
6
7# Set permissions per file
8volumes:
9  - name: config-volume
10    configMap:
11      name: app-config
12      items:
13        - key: app.properties
14          path: app.properties
15          mode: 0644
16        - key: secret.conf
17          path: secret.conf
18          mode: 0600  # Owner-only

ConfigMap files are mounted with mode 0644 by default. Set defaultMode for all files or mode on individual items. The mode must be an octal integer.

Issue 4: mounting only some keys

yaml
1volumes:
2  - name: config-volume
3    configMap:
4      name: app-config
5      items:
6        - key: app.properties
7          path: application.properties  # Rename the file

items selects specific keys and can rename them. Keys not listed are not mounted, which helps when a ConfigMap holds several files and you need only one.

Issue 5: the ConfigMap does not exist

yaml
1# Pod stays in ContainerCreating if ConfigMap doesn't exist
2volumes:
3  - name: config-volume
4    configMap:
5      name: app-config
6      optional: false  # Default — pod fails if ConfigMap missing
7
8# Allow pod to start without the ConfigMap
9volumes:
10  - name: config-volume
11    configMap:
12      name: app-config
13      optional: true  # Pod starts even if ConfigMap doesn't exist

With optional: false (the default) and no ConfigMap, the pod stays in ContainerCreating. Set optional: true if the configuration is not required at startup.

Reloading configuration automatically

yaml
1apiVersion: v1
2kind: Pod
3metadata:
4  name: myapp
5spec:
6  shareProcessNamespace: true  # Lets the sidecar see and signal the app process
7  containers:
8    - name: app
9      image: myapp:latest
10      volumeMounts:
11        - name: config-volume
12          mountPath: /etc/config
13    - name: config-reloader
14      image: alpine
15      command:
16        - sh
17        - -c
18        - |
19          apk add --no-cache inotify-tools
20          while true; do
21            # Kubelet swaps the ..data symlink on update, so watch the directory
22            inotifywait -e moved_to /etc/config
23            pkill -HUP myapp  # Signal main process to reload
24          done
25      volumeMounts:
26        - name: config-volume
27          mountPath: /etc/config
28  volumes:
29    - name: config-volume
30      configMap:
31        name: app-config

A sidecar can watch for file changes and signal the application to reload. It watches the directory rather than the file because updates arrive as an atomic rename of the ..data symlink, which never fires a modify event on app.properties, and it needs shareProcessNamespace to reach the app's process. Tools such as configmap-reload or reloader automate this pattern for production.

Debugging ConfigMap mounts

bash
1# Check if ConfigMap exists
2kubectl get configmap app-config -o yaml
3
4# Check pod events for mount errors
5kubectl describe pod myapp
6
7# Verify files inside the container
8kubectl exec myapp -- ls -la /etc/config/
9kubectl exec myapp -- cat /etc/config/app.properties
10
11# Check if ConfigMap was updated
12kubectl get configmap app-config -o jsonpath='{.metadata.resourceVersion}'

Other limits to know

  • Binary data: ConfigMap data values are UTF-8 strings and may corrupt binary content. Put binary files (images, certificates) in the binaryData field with base64 encoding, or use a Secret.
  • Size limit: one ConfigMap cannot exceed 1 MiB. For larger files, use a persistent volume, an init container that downloads the config, or several ConfigMaps.
  • Symlinks: ConfigMap volumes are built from symlinks (a ..data symlink pointing to a timestamped directory). Some applications do not follow symlinks correctly, so check how yours reads configuration files.

Course
Beginner
27 lessons
10 hours
System Design Fundamentals

Build a strong foundation in designing scalable, reliable distributed systems.

View the course
System Design practice on Codemia

Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.

Practice system design