Challenge, Medium,  on  Kubernetes

Mount a ConfigMap and Secret into a Single Directory Using a Projected Volume

Scenario

The exam namespace already has two resources waiting for you:

  • ConfigMap app-config — holds three configuration files: database.conf, cache.conf, and app.properties
  • Secret app-secret — holds three sensitive keys: db-password, api-key, and jwt-secret

A new Pod needs to read all six files from a single directory /etc/app. The security policy requires the mount to be read-only.


Task

  1. Create a Pod named app in the exam namespace using the busybox image with the command sleep 3600.
  2. Define exactly one volume named app-config-vol that combines both app-config (ConfigMap) and app-secret (Secret) into a single volume using a projected volume.
  3. Mount the volume at /etc/app as readOnly.
Kubernetes projected volume combining ConfigMap and Secret into /etc/app

Both the ConfigMap (app-config) and Secret (app-secret) are projected into a single read-only directory (/etc/app) using one projected volume (app-config-vol).


Hint 1 — Why a Normal Volume Won't Work Here

A standard configMap volume or secret volume can only reference one source. If you define two separate volumes and two separate mounts, you will have two directories — not one. The task requires a single volume and a single mount path that surfaces files from both sources simultaneously.

The volume type that solves this is called a projected volume.

Documentation

Hint 2 — Structure of a Projected Volume

A projected volume uses the projected key instead of configMap or secret. Under it, sources accepts a list — each item is either a configMap or a secret block referencing the resource by name. Both are top-level sibling entries in the same sources list:

volumes:
- name: app-config-vol
  projected:
    sources:
    - configMap:
        name: app-config
    - secret:
        name: app-secret

Documentation

Hint 3 — Making the Mount Read-Only

readOnly is set on the volumeMount inside the container spec, not on the volume definition itself. Reference the volume by the exact name app-config-vol and set readOnly: true:

volumeMounts:
- name: app-config-vol
  mountPath: /etc/app
  readOnly: true

After applying, verify with:

kubectl exec app -n exam -- ls /etc/app

Documentation


⚒ Test Cases