Kubernetes allows you to combine multiple volume sources into one directory inside a Pod. Projected volumes solve the need to inject secrets, ConfigMaps, Pod metadata, service account tokens, and trust bundles at once. This article explains how projected volumes work, when to use them, and how to configure them efficiently.
TL;DR
- You can merge secrets, ConfigMaps, Downward API, service account tokens, and trust bundles into one projected volume directory.
- They simplify Pod configuration when you need multiple data sources in a single mount.
- Use
volumeProjection
entries underprojected
in the Pod spec to define each source. - They respect file modes, ownership, and expiration for tokens.
- They do not require a CSI driver; Kubernetes handles them in kubelet.
- They suit event-driven flows that rely on runtime metadata and secrets.
Overview of Projected Volumes
Projected volumes map multiple existing volume sources into the same directory on the target container. You declare a single volume with type projected
. Under it, you list each source. Kubernetes will merge them at mount time. You avoid mounting each source separately. You also control file modes, paths, and token lifetimes for each sub-source.
Supported Sources in Projected Volumes
Currently, projected volumes can include:
- secret: Inject keys from a Secret into the directory.
- configMap: Pull ConfigMap data as files.
- downwardAPI: Expose Pod metadata and fields as files.
- serviceAccountToken: Mount a service account token with custom expiration and audience.
- clusterTrustBundle: Provide cluster root certificates for TLS validation.
All sources must reside in the same namespace as the Pod.
Configuring Projected Volumes: YAML Example
Here is a Pod spec that combines a Secret, a Downward API field, and a ConfigMap into /etc/projected
:
apiVersion: v1
kind: Pod
metadata:
name: projected-example
spec:
containers:
- name: app-container
image: busybox
command: ["sh", "-c", "ls -l /etc/projected && cat /etc/projected/namespace"]
volumeMounts:
- name: proj-vol
mountPath: /etc/projected
volumes:
- name: proj-vol
projected:
sources:
- secret:
name: my-secret
items:
- key: password
path: password.txt
- downwardAPI:
items:
- path: namespace
fieldRef:
fieldPath: metadata.namespace
- configMap:
name: my-configmap
items:
- key: config.yaml
path: config.yaml
This example mounts three sources under one directory. Kubernetes flattens them and handles file permissions.
Projected Volumes Use-Cases and Patterns
Use projected volumes when:
- You need to inject both secrets and metadata into your container directory at once.
- Your application reads multiple files from a single directory.
- You want a unified mount for event-driven functions that read configuration and tokens on startup.
- You need to control token expiration or audience for secure API calls.
For event-driven architectures, projected volumes let you access Pod fields and secrets in initializers and sidecars. They avoid multiple mounts and simplify permission checks. They also work well with autoscaling functions in Knative or Kafka consumers in Strimzi.
Event-Driven Flows with Projected Volumes
In an event-driven pipeline, services often need runtime metadata to process events. For example, a Kafka consumer Pod might need:
- Consumer group ID from ConfigMap.
- Service account token to access the Kafka cluster API.
- Namespace and Pod name via Downward API for logging.
Volume Lifecycle, Claims, and Provisioning
Projected volumes are ephemeral. Kubernetes provisions them when you create the Pod. Kubelet writes files to the host and mounts the directory into the container. No PersistentVolumeClaim
is required. They do not consume storage class capacity. You cannot snapshot them because they do not back onto a PersistentVolume
.
Because projected volumes rely on existing resources (Secrets, ConfigMaps), cleanup happens when you delete those objects. Pods recreate the projected volume on restart. You manage capacity indirectly by limiting Secrets and ConfigMap sizes via quotas in the namespace.
Security, Quotas, and Access Controls
Projected volumes follow RBAC and PodSecurityPolicies:
- The Pod’s service account must have
get
permission on the Secrets and ConfigMaps. - You can specify file
mode
under each source to restrict access at the filesystem level. - ServiceAccountToken sources allow you to set
expirationSeconds
andaudience
to limit token scope. - Namespace quotas limit total size of Secrets and ConfigMaps. That indirectly caps your projected volume footprint.
- clusterTrustBundle provides root CAs for TLS; it inherits trust boundaries of the control plane.
References
- Kubernetes Projected Volumes
- Kubernetes Volumes
- Expose Pod Information to Containers Through Files
- Configure Service Accounts for Pods
- Kubernetes ConfigMap
- Kubernetes Secret
Suggested Reading
PostHashID: 743efef914bb78f06cc9b2d51f660ba58ced592d67bb898c2c00b080ae0d9719