PV & PVC Client implementation
This commit is contained in:
parent
5742299dbc
commit
22ce40fe48
|
@ -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 {
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
kind: PersistentVolumeClaim
|
||||
apiVersion: v1beta3
|
||||
metadata:
|
||||
name: myclaim-1
|
||||
spec:
|
||||
accessModes:
|
||||
- ReadWriteOnce
|
||||
resources:
|
||||
requests:
|
||||
storage: 3
|
|
@ -0,0 +1,10 @@
|
|||
kind: PersistentVolumeClaim
|
||||
apiVersion: v1beta3
|
||||
metadata:
|
||||
name: myclaim-2
|
||||
spec:
|
||||
accessModes:
|
||||
- ReadWriteOnce
|
||||
resources:
|
||||
requests:
|
||||
storage: 8
|
|
@ -0,0 +1,17 @@
|
|||
{
|
||||
"kind": "PersistentVolumeClaim",
|
||||
"apiVersion": "v1beta3",
|
||||
"metadata": {
|
||||
"name": "myclaim-3"
|
||||
}, "spec": {
|
||||
"accessModes": [
|
||||
"ReadWriteOnce",
|
||||
"ReadOnlyMany"
|
||||
],
|
||||
"resources": {
|
||||
"requests": {
|
||||
"storage": "10G"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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
|
||||
|
||||
```
|
|
@ -0,0 +1,10 @@
|
|||
{
|
||||
"kind": "Namespace",
|
||||
"apiVersion":"v1beta3",
|
||||
"metadata": {
|
||||
"name": "myns",
|
||||
"labels": {
|
||||
"name": "development"
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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
|
|
@ -0,0 +1,10 @@
|
|||
kind: PersistentVolume
|
||||
apiVersion: v1beta3
|
||||
metadata:
|
||||
name: pv0003
|
||||
spec:
|
||||
capacity:
|
||||
storage: 10
|
||||
gcePersistentDisk:
|
||||
pdName: "abc123"
|
||||
fsType: "ext4"
|
|
@ -0,0 +1,11 @@
|
|||
kind: PersistentVolume
|
||||
apiVersion: v1beta3
|
||||
metadata:
|
||||
name: pv0001
|
||||
labels:
|
||||
type: local
|
||||
spec:
|
||||
capacity:
|
||||
storage: 10Gi
|
||||
hostPath:
|
||||
path: "/tmp/data01"
|
|
@ -0,0 +1,11 @@
|
|||
kind: PersistentVolume
|
||||
apiVersion: v1beta3
|
||||
metadata:
|
||||
name: pv0002
|
||||
labels:
|
||||
type: local
|
||||
spec:
|
||||
capacity:
|
||||
storage: 5Gi
|
||||
hostPath:
|
||||
path: "/tmp/data02"
|
Loading…
Reference in New Issue