2017-05-22 17:57:42 +00:00
---
2018-02-18 19:29:37 +00:00
reviewers:
2017-05-22 17:57:42 +00:00
- jpeeler
- pmorie
2017-06-08 18:48:28 +00:00
title: Configure a Pod to Use a Projected Volume for Storage
2018-05-05 16:00:51 +00:00
content_template: templates/task
2018-05-20 04:43:52 +00:00
weight: 70
2017-05-22 17:57:42 +00:00
---
2018-05-05 16:00:51 +00:00
{{% capture overview %}}
2018-06-29 01:48:20 +00:00
This page shows how to use a [`projected` ](/docs/concepts/storage/volumes/#projected ) volume to mount
several existing volume sources into the same directory. Currently, `secret` , `configMap` , `downwardAPI` ,
and `serviceAccountToken` volumes can be projected.
{{< note > }}
`serviceAccountToken` is not a volume type.
{{< / note > }}
2018-05-05 16:00:51 +00:00
{{% /capture %}}
2017-05-22 17:57:42 +00:00
2018-05-05 16:00:51 +00:00
{{% capture prerequisites %}}
{{< include " task-tutorial-prereqs . md " > }} {{< version-check > }}
{{% /capture %}}
2017-05-22 17:57:42 +00:00
2018-05-05 16:00:51 +00:00
{{% capture steps %}}
2017-05-22 17:57:42 +00:00
## Configure a projected volume for a pod
In this exercise, you create username and password Secrets from local files. You then create a Pod that runs one Container, using a [`projected` ](/docs/concepts/storage/volumes/#projected ) Volume to mount the Secrets into the same shared directory.
Here is the configuration file for the Pod:
2018-05-05 16:00:51 +00:00
{{< code file = "projected-volume.yaml" > }}
2017-05-22 17:57:42 +00:00
1. Create the Secrets:
2018-05-12 14:52:25 +00:00
```shell
# Create files containing the username and password:
2017-08-06 04:22:56 +00:00
echo -n "admin" > ./username.txt
echo -n "1f2d1e2e67df" > ./password.txt
2017-05-22 17:57:42 +00:00
2018-05-12 14:52:25 +00:00
# Package these files into secrets:
2017-08-06 04:22:56 +00:00
kubectl create secret generic user --from-file=./username.txt
kubectl create secret generic pass --from-file=./password.txt
2018-05-12 14:52:25 +00:00
```
2017-05-22 17:57:42 +00:00
1. Create the Pod:
2018-05-12 14:52:25 +00:00
```shell
2017-10-03 14:12:24 +00:00
kubectl create -f https://k8s.io/docs/tasks/configure-pod-container/projected-volume.yaml
2018-05-12 14:52:25 +00:00
```
2017-05-22 17:57:42 +00:00
1. Verify that the Pod's Container is running, and then watch for changes to
the Pod:
2018-05-12 14:52:25 +00:00
```shell
2017-08-06 04:22:56 +00:00
kubectl get --watch pod test-projected-volume
2018-05-12 14:52:25 +00:00
```
2017-05-22 17:57:42 +00:00
The output looks like this:
2017-08-17 23:19:24 +00:00
NAME READY STATUS RESTARTS AGE
test-projected-volume 1/1 Running 0 14s
2017-05-22 17:57:42 +00:00
1. In another terminal, get a shell to the running Container:
2018-05-12 14:52:25 +00:00
```shell
2017-08-06 04:22:56 +00:00
kubectl exec -it test-projected-volume -- /bin/sh
2018-05-12 14:52:25 +00:00
```
2017-07-01 19:34:12 +00:00
1. In your shell, verify that the `projected-volume` directory contains your projected sources:
2018-05-12 14:52:25 +00:00
```shell
ls /projected-volume/
```
2018-05-05 16:00:51 +00:00
{{% /capture %}}
2017-05-22 17:57:42 +00:00
2018-05-05 16:00:51 +00:00
{{% capture whatsnext %}}
2017-05-22 17:57:42 +00:00
* Learn more about [`projected` ](/docs/concepts/storage/volumes/#projected ) volumes.
2018-05-05 16:00:51 +00:00
* Read the [all-in-one volume ](https://github.com/kubernetes/community/blob/{{< param "githubbranch" >}}/contributors/design-proposals/node/all-in-one-volume.md ) design document.
{{% /capture %}}
2017-05-22 17:57:42 +00:00