k3s/docs/user-guide/persistent-volumes/README.md

134 lines
5.0 KiB
Markdown
Raw Normal View History

2015-07-14 00:13:09 +00:00
<!-- BEGIN MUNGE: UNVERSIONED_WARNING -->
<!-- BEGIN STRIP_FOR_RELEASE -->
2015-07-16 17:02:26 +00:00
<img src="http://kubernetes.io/img/warning.png" alt="WARNING"
width="25" height="25">
<img src="http://kubernetes.io/img/warning.png" alt="WARNING"
width="25" height="25">
<img src="http://kubernetes.io/img/warning.png" alt="WARNING"
width="25" height="25">
<img src="http://kubernetes.io/img/warning.png" alt="WARNING"
width="25" height="25">
<img src="http://kubernetes.io/img/warning.png" alt="WARNING"
width="25" height="25">
2015-07-13 22:15:35 +00:00
2015-07-16 17:02:26 +00:00
<h2>PLEASE NOTE: This document applies to the HEAD of the source tree</h2>
2015-07-14 00:13:09 +00:00
2015-07-16 17:02:26 +00:00
If you are using a released version of Kubernetes, you should
refer to the docs that go with that version.
2015-07-14 00:13:09 +00:00
2015-07-16 17:02:26 +00:00
<strong>
The latest 1.0.x release of this document can be found
[here](http://releases.k8s.io/release-1.0/docs/user-guide/persistent-volumes/README.md).
Documentation for other releases can be found at
[releases.k8s.io](http://releases.k8s.io).
</strong>
--
2015-07-13 22:15:35 +00:00
2015-07-14 00:13:09 +00:00
<!-- END STRIP_FOR_RELEASE -->
<!-- END MUNGE: UNVERSIONED_WARNING -->
2015-07-17 22:35:41 +00:00
2015-03-26 19:50:36 +00:00
# How To Use Persistent Volumes
The purpose of this guide is to help you become familiar with [Kubernetes Persistent Volumes](../persistent-volumes.md). By the end of the guide, we'll have
2015-04-17 14:42:25 +00:00
nginx serving content from your persistent volume.
2015-03-26 19:50:36 +00:00
This guide assumes knowledge of Kubernetes fundamentals and that you have a cluster up and running.
2015-03-26 19:50:36 +00:00
2015-07-24 21:52:18 +00:00
See [Persistent Storage design document](../../design/persistent-storage.md) for more information.
2015-04-17 14:42:25 +00:00
## Provisioning
2015-03-26 19:50:36 +00:00
A Persistent Volume (PV) in Kubernetes represents a real piece of underlying storage capacity in the infrastructure. Cluster administrators
must first create storage (create their Google Compute Engine (GCE) disks, export their NFS shares, etc.) in order for Kubernetes to mount it.
2015-03-26 19:50:36 +00:00
PVs are intended for "network volumes" like GCE Persistent Disks, NFS shares, and AWS ElasticBlockStore volumes. `HostPath` was included
for ease of development and testing. You'll create a local `HostPath` for this example.
> IMPORTANT! For `HostPath` to work, you will need to run a single node cluster. Kubernetes does not
support local storage on the host at this time. There is no guarantee your pod ends up on the correct node where the `HostPath` resides.
2015-07-24 21:52:18 +00:00
2015-07-17 02:01:02 +00:00
```console
# This will be nginx's webroot
2015-07-08 05:52:52 +00:00
$ mkdir /tmp/data01
$ echo 'I love Kubernetes storage!' > /tmp/data01/index.html
2015-04-17 14:42:25 +00:00
```
2015-03-26 19:50:36 +00:00
2015-04-17 14:42:25 +00:00
PVs are created by posting them to the API server.
2015-03-26 19:50:36 +00:00
```console
$ kubectl create -f docs/user-guide/persistent-volumes/volumes/local-01.yaml
2015-07-08 05:52:52 +00:00
NAME LABELS CAPACITY ACCESSMODES STATUS CLAIM REASON
pv0001 type=local 10737418240 RWO Available
2015-03-26 19:50:36 +00:00
```
2015-04-17 14:42:25 +00:00
## Requesting storage
Users of Kubernetes request persistent storage for their pods. They don't know how the underlying cluster is provisioned.
2015-07-24 21:52:18 +00:00
They just know they can rely on their claim to storage and can manage its lifecycle independently from the many pods that may use it.
2015-03-26 19:50:36 +00:00
Claims must be created in the same namespace as the pods that use them.
2015-03-26 19:50:36 +00:00
```console
$ kubectl create -f docs/user-guide/persistent-volumes/claims/claim-01.yaml
2015-03-26 19:50:36 +00:00
2015-07-08 05:52:52 +00:00
$ kubectl get pvc
2015-03-26 19:50:36 +00:00
NAME LABELS STATUS VOLUME
myclaim-1 map[]
2015-04-17 14:42:25 +00:00
# A background process will attempt to match this claim to a volume.
# The eventual state of your claim will look something like this:
2015-03-26 19:50:36 +00:00
2015-07-08 05:52:52 +00:00
$ kubectl get pvc
NAME LABELS STATUS VOLUME
myclaim-1 map[] Bound pv0001
2015-03-26 19:50:36 +00:00
2015-07-08 05:52:52 +00:00
$ kubectl get pv
NAME LABELS CAPACITY ACCESSMODES STATUS CLAIM REASON
pv0001 type=local 10737418240 RWO Bound default/myclaim-1
2015-03-26 19:50:36 +00:00
```
2015-04-17 14:42:25 +00:00
## Using your claim as a volume
2015-03-26 19:50:36 +00:00
2015-04-17 14:42:25 +00:00
Claims are used as volumes in pods. Kubernetes uses the claim to look up its bound PV. The PV is then exposed to the pod.
2015-03-26 19:50:36 +00:00
```console
$ kubectl create -f docs/user-guide/persistent-volumes/simpletest/pod.yaml
2015-07-08 05:52:52 +00:00
$ kubectl get pods
NAME READY STATUS RESTARTS AGE
mypod 1/1 Running 0 1h
2015-03-26 19:50:36 +00:00
$ kubectl create -f docs/user-guide/persistent-volumes/simpletest/service.json
2015-07-08 05:52:52 +00:00
$ kubectl get services
NAME CLUSTER_IP EXTERNAL_IP PORT(S) SELECTOR AGE
frontendservice 10.0.0.241 <none> 3000/TCP name=frontendhttp 1d
kubernetes 10.0.0.2 <none> 443/TCP <none> 2d
```
## Next steps
2015-03-26 19:50:36 +00:00
2015-07-24 21:52:18 +00:00
You should be able to query your service endpoint and see what content nginx is serving. A "forbidden" error might mean you
need to disable SELinux (setenforce 0).
```console
$ curl 10.0.0.241:3000
2015-04-17 14:42:25 +00:00
I love Kubernetes storage!
2015-03-26 19:50:36 +00:00
```
Hopefully this simple guide is enough to get you started with PersistentVolumes. If you have any questions, join
[`#google-containers`](https://botbot.me/freenode/google-containers/) on IRC and ask!
Enjoy!
2015-07-14 00:13:09 +00:00
<!-- BEGIN MUNGE: GENERATED_ANALYTICS -->
2015-07-14 16:37:37 +00:00
[![Analytics](https://kubernetes-site.appspot.com/UA-36037335-10/GitHub/docs/user-guide/persistent-volumes/README.md?pixel)]()
2015-07-14 00:13:09 +00:00
<!-- END MUNGE: GENERATED_ANALYTICS -->