How to mount multiple files / secrets into common directory in kubernetes?
Projected Volume
You can use a projected volume to have two secrets in the same directory
Example
apiVersion: v1kind: Podmetadata: labels: run: alpine-secret name: alpine-secretspec: containers: - command: - sleep - "3600" image: alpine name: alpine-secret volumeMounts: - name: xyfiles mountPath: "/var/secrets/" readOnly: true volumes: - name: xyfiles projected: sources: - secret: name: my-secret-one - secret: name: my-secret-two
(EDIT: Never mind - I just noticed @Jonas gave the same answer earlier. +1 from me)
Starting with Kubernetes v1.11+ it is possible with projected
volumes:
A projected volume maps several existing volume sources into the same directory.
Currently, the following types of volume sources can be projected:
- secret
- downwardAPI
- configMap
- serviceAccountToken
This is an example for "... how to use a projected Volume to mount several existing volume sources into the same directory".
May be subPath (using subPath) will help.
Example:
volumeMounts: - name: app-redis-vol mountPath: /app/config/redis.yaml subPath: redis.yaml - name: app-config-vol mountPath: /app/config/app.yaml subPath: app.yaml volumes: - name: app-redis-vol configMap: name: config-map-redis items: - key: yourKey path: redis.yaml - name: app-config-vol configMap: name: config-map-app items: - key: yourKey path: app.yaml
Here your configMap named config-map-redis
created from file redis.yaml
mounted in app/config/
as file redis.yaml
.Also configMap config-map-app
mounted in app/config/
as app.yaml
There is nice article about this here: Injecting multiple Kubernetes volumes to the same directory