skip to content
Pradeep Chhetri

Software Engineer. Writing about databases, infrastructure, and distributed systems.

Main navigation

  • Home
  • Blog
  • TIL
GitHub LinkedIn RSS

Kubernetes: Projected Volume

November 5, 2021 · TIL

Tags:
  • kubernetes

In k8s world, sometimes you need to mount both configmap and secret under the same directory.

apiVersion: v1
kind: ConfigMap
metadata:
  name: app-config
data:
  config.yaml: |
    listen-port: 8080 ...
apiVersion: v1
kind: Secret
metadata:
  name: app-secret
data:
  tls.crt: |
    MIIC2DCCAcCgAwIBAgIBATANBgkqh ...
  tls.key: |
    MIIEpgIBAAKCAQEA7yn3bRHQ5FHMQ ...

Let’s say you have to mount all of them under /etc/app such that the layout should look like this

/
├── etc
│   └── app
│       ├── config.yaml
│       ├── tls.crt
│       └── tls.key

You can make use of projected volumes to achive it

apiVersion: apps/v1
kind: Deployment
metadata:
  name: app
spec:
  template:
    spec:
      containers:
        - name: app
          image: app/app:0.1.0
          volumeMounts:
            - name: config-and-secret
              mountPath: /etc/app
      volumes:
        - name: config-and-secret
          projected:
            sources:
              - configMap:
	          name: app-config
	      - secret:
	          name: app-secret

© 2026 Pradeep Chhetri