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 %}}
2019-05-27 02:21:49 +00:00
This page shows how to use a [`projected` ](/docs/concepts/storage/volumes/#projected ) Volume to mount
2018-06-29 01:48:20 +00:00
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
2019-05-27 02:21:49 +00:00
In this exercise, you create username and password {{< glossary_tooltip text = "Secrets" term_id = "secret" > }} 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.
2017-05-22 17:57:42 +00:00
Here is the configuration file for the Pod:
2018-07-03 20:31:20 +00:00
{{< codenew file = "pods/storage/projected.yaml" > }}
2017-05-22 17:57:42 +00:00
1. Create the Secrets:
2019-05-08 19:06:35 +00:00
```shell
2018-05-12 14:52:25 +00:00
# Create files containing the username and password:
2019-05-08 19:06:35 +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:
2019-05-08 19:06:35 +00:00
kubectl create secret generic user --from-file=./username.txt
kubectl create secret generic pass --from-file=./password.txt
```
2017-05-22 17:57:42 +00:00
1. Create the Pod:
2019-05-08 19:06:35 +00:00
```shell
kubectl apply -f https://k8s.io/examples/pods/storage/projected.yaml
```
2019-05-27 02:21:49 +00:00
1. Verify that the Pod's container is running, and then watch for changes to
2017-05-22 17:57:42 +00:00
the Pod:
2019-05-08 19:06:35 +00:00
```shell
kubectl get --watch pod test-projected-volume
```
2017-05-22 17:57:42 +00:00
The output looks like this:
2019-05-27 02:21:49 +00:00
```
2019-05-08 19:06:35 +00:00
NAME READY STATUS RESTARTS AGE
test-projected-volume 1/1 Running 0 14s
```
2019-05-27 02:21:49 +00:00
1. In another terminal, get a shell to the running container:
2019-05-08 19:06:35 +00:00
```shell
kubectl exec -it test-projected-volume -- /bin/sh
```
2017-07-01 19:34:12 +00:00
1. In your shell, verify that the `projected-volume` directory contains your projected sources:
2019-05-08 19:06:35 +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 %}}