diff --git a/examples_test.go b/examples_test.go index 8c5ce092..4cbf5aa6 100644 --- a/examples_test.go +++ b/examples_test.go @@ -65,6 +65,11 @@ func validateObject(obj runtime.Object) (errors []error) { for i := range t.Items { errors = append(errors, validateObject(&t.Items[i])...) } + case *api.PersistentVolume: + errors = validation.ValidatePersistentVolume(t) + case *api.PersistentVolumeClaim: + api.ValidNamespace(ctx, &t.ObjectMeta) + errors = validation.ValidatePersistentVolumeClaim(t) default: return []error{fmt.Errorf("no validation defined for %#v", obj)} } @@ -160,6 +165,16 @@ func TestExampleObjectSchemas(t *testing.T) { "kitten-rc": &api.ReplicationController{}, "nautilus-rc": &api.ReplicationController{}, }, + "../examples/persistent-volumes/volumes": { + "local-01": &api.PersistentVolume{}, + "local-02": &api.PersistentVolume{}, + "gce": &api.PersistentVolume{}, + }, + "../examples/persistent-volumes/claims": { + "claim-01": &api.PersistentVolumeClaim{}, + "claim-02": &api.PersistentVolumeClaim{}, + "claim-03": &api.PersistentVolumeClaim{}, + }, } for path, expected := range cases { diff --git a/persistent-volumes/claims/claim-01.yaml b/persistent-volumes/claims/claim-01.yaml new file mode 100644 index 00000000..cb0a2abb --- /dev/null +++ b/persistent-volumes/claims/claim-01.yaml @@ -0,0 +1,10 @@ +kind: PersistentVolumeClaim +apiVersion: v1beta3 +metadata: + name: myclaim-1 +spec: + accessModes: + - ReadWriteOnce + resources: + requests: + storage: 3 diff --git a/persistent-volumes/claims/claim-02.yaml b/persistent-volumes/claims/claim-02.yaml new file mode 100644 index 00000000..134ae4cf --- /dev/null +++ b/persistent-volumes/claims/claim-02.yaml @@ -0,0 +1,10 @@ +kind: PersistentVolumeClaim +apiVersion: v1beta3 +metadata: + name: myclaim-2 +spec: + accessModes: + - ReadWriteOnce + resources: + requests: + storage: 8 diff --git a/persistent-volumes/claims/claim-03.json b/persistent-volumes/claims/claim-03.json new file mode 100644 index 00000000..b3b0717a --- /dev/null +++ b/persistent-volumes/claims/claim-03.json @@ -0,0 +1,17 @@ +{ + "kind": "PersistentVolumeClaim", + "apiVersion": "v1beta3", + "metadata": { + "name": "myclaim-3" + }, "spec": { + "accessModes": [ + "ReadWriteOnce", + "ReadOnlyMany" + ], + "resources": { + "requests": { + "storage": "10G" + } + } + } +} diff --git a/persistent-volumes/simpletest/README.md b/persistent-volumes/simpletest/README.md new file mode 100644 index 00000000..026920d1 --- /dev/null +++ b/persistent-volumes/simpletest/README.md @@ -0,0 +1,69 @@ +# How To Use Persistent Volumes + +This guide assumes knowledge of Kubernetes fundamentals and that a user has a cluster up and running. + +## Create volumes + +Persistent Volumes are intended for "network volumes", such as GCE Persistent Disks, NFS shares, and AWS EBS volumes. + +The `HostPath` VolumeSource was included in the Persistent Volumes implementation for ease of testing. + +Create persistent volumes by posting them to the API server: + +``` + +cluster/kubectl.sh create -f examples/persistent-volumes/volumes/local-01.yaml +cluster/kubectl.sh create -f examples/persistent-volumes/volumes/local-02.yaml + +cluster/kubectl.sh get pv + +NAME LABELS CAPACITY ACCESSMODES STATUS CLAIM +pv0001 map[] 10737418240 RWO +pv0002 map[] 5368709120 RWO + + +In the log: + +I0302 10:20:45.663225 1920 persistent_volume_manager.go:115] Managing PersistentVolume[UID=b16e91d6-c0ef-11e4-8be4-80e6500a981e] +I0302 10:20:55.667945 1920 persistent_volume_manager.go:115] Managing PersistentVolume[UID=b41f4f0e-c0ef-11e4-8be4-80e6500a981e] + +``` + +## Create claims + +You must be in a namespace to create claims. + +``` + +cluster/kubectl.sh create -f examples/persistent-volumes/claims/claim-01.yaml +cluster/kubectl.sh create -f examples/persistent-volumes/claims/claim-02.yaml + +NAME LABELS STATUS VOLUME +myclaim-1 map[] +myclaim-2 map[] + +``` + + +## Matching and binding + +``` + +PersistentVolumeClaim[UID=f4b3d283-c0ef-11e4-8be4-80e6500a981e] bound to PersistentVolume[UID=b16e91d6-c0ef-11e4-8be4-80e6500a981e] + + + +cluster/kubectl.sh get pv + +NAME LABELS CAPACITY ACCESSMODES STATUS CLAIM +pv0001 map[] 10737418240 RWO myclaim-1 / f4b3d283-c0ef-11e4-8be4-80e6500a981e +pv0002 map[] 5368709120 RWO myclaim-2 / f70da891-c0ef-11e4-8be4-80e6500a981e + + +cluster/kubectl.sh get pvc + +NAME LABELS STATUS VOLUME +myclaim-1 map[] b16e91d6-c0ef-11e4-8be4-80e6500a981e +myclaim-2 map[] b41f4f0e-c0ef-11e4-8be4-80e6500a981e + +``` diff --git a/persistent-volumes/simpletest/namespace.json b/persistent-volumes/simpletest/namespace.json new file mode 100644 index 00000000..c9e7ced5 --- /dev/null +++ b/persistent-volumes/simpletest/namespace.json @@ -0,0 +1,10 @@ +{ + "kind": "Namespace", + "apiVersion":"v1beta3", + "metadata": { + "name": "myns", + "labels": { + "name": "development" + } + } +} diff --git a/persistent-volumes/simpletest/pod.yaml b/persistent-volumes/simpletest/pod.yaml new file mode 100644 index 00000000..bb76ff4f --- /dev/null +++ b/persistent-volumes/simpletest/pod.yaml @@ -0,0 +1,18 @@ +kind: Pod +apiVersion: v1beta3 +metadata: + name: mypod +spec: + containers: + - image: dockerfile/nginx + name: myfrontend + volumeMounts: + - mountPath: "/var/www/html" + name: mypd + volumes: + - name: mypd + source: + persistentVolumeClaim: + accessMode: ReadWriteOnce + claimRef: + name: myclaim-1 diff --git a/persistent-volumes/volumes/gce.yaml b/persistent-volumes/volumes/gce.yaml new file mode 100644 index 00000000..3e124c59 --- /dev/null +++ b/persistent-volumes/volumes/gce.yaml @@ -0,0 +1,10 @@ +kind: PersistentVolume +apiVersion: v1beta3 +metadata: + name: pv0003 +spec: + capacity: + storage: 10 + gcePersistentDisk: + pdName: "abc123" + fsType: "ext4" diff --git a/persistent-volumes/volumes/local-01.yaml b/persistent-volumes/volumes/local-01.yaml new file mode 100644 index 00000000..105e4393 --- /dev/null +++ b/persistent-volumes/volumes/local-01.yaml @@ -0,0 +1,11 @@ +kind: PersistentVolume +apiVersion: v1beta3 +metadata: + name: pv0001 + labels: + type: local +spec: + capacity: + storage: 10Gi + hostPath: + path: "/tmp/data01" diff --git a/persistent-volumes/volumes/local-02.yaml b/persistent-volumes/volumes/local-02.yaml new file mode 100644 index 00000000..1f40d7a0 --- /dev/null +++ b/persistent-volumes/volumes/local-02.yaml @@ -0,0 +1,11 @@ +kind: PersistentVolume +apiVersion: v1beta3 +metadata: + name: pv0002 + labels: + type: local +spec: + capacity: + storage: 5Gi + hostPath: + path: "/tmp/data02"