From 2ec0f9577ad5290e4a1c4b2ea6e9419dd40232fe Mon Sep 17 00:00:00 2001 From: Abrar Shivani Date: Mon, 17 Oct 2016 16:47:57 -0700 Subject: [PATCH] Add vSphere Volume Examples --- .../persistent-volume-provisioning/README.md | 2 +- volumes/vsphere/README.md | 372 ++++++++++++++++++ volumes/vsphere/deployment.yaml | 22 ++ volumes/vsphere/vsphere-volume-pod.yaml | 17 + volumes/vsphere/vsphere-volume-pv.yaml | 13 + volumes/vsphere/vsphere-volume-pvc.yaml | 10 + volumes/vsphere/vsphere-volume-pvcpod.yaml | 15 + volumes/vsphere/vsphere-volume-pvcsc.yaml | 12 + volumes/vsphere/vsphere-volume-pvcscpod.yaml | 15 + volumes/vsphere/vsphere-volume-sc-fast.yaml | 7 + 10 files changed, 484 insertions(+), 1 deletion(-) create mode 100644 volumes/vsphere/README.md create mode 100644 volumes/vsphere/deployment.yaml create mode 100644 volumes/vsphere/vsphere-volume-pod.yaml create mode 100644 volumes/vsphere/vsphere-volume-pv.yaml create mode 100644 volumes/vsphere/vsphere-volume-pvc.yaml create mode 100644 volumes/vsphere/vsphere-volume-pvcpod.yaml create mode 100644 volumes/vsphere/vsphere-volume-pvcsc.yaml create mode 100644 volumes/vsphere/vsphere-volume-pvcscpod.yaml create mode 100644 volumes/vsphere/vsphere-volume-sc-fast.yaml diff --git a/experimental/persistent-volume-provisioning/README.md b/experimental/persistent-volume-provisioning/README.md index f464c7b6..13f07621 100644 --- a/experimental/persistent-volume-provisioning/README.md +++ b/experimental/persistent-volume-provisioning/README.md @@ -92,7 +92,7 @@ metadata: name: slow provisioner: kubernetes.io/vsphere-volume parameters: - diskformat: thin + diskformat: eagerzeroedthick ``` * `diskformat`: `thin`, `zeroedthick` and `eagerzeroedthick`. See vSphere docs for details. Default: `"thin"`. diff --git a/volumes/vsphere/README.md b/volumes/vsphere/README.md new file mode 100644 index 00000000..f33e900c --- /dev/null +++ b/volumes/vsphere/README.md @@ -0,0 +1,372 @@ + + + + +WARNING +WARNING +WARNING +WARNING +WARNING + +

PLEASE NOTE: This document applies to the HEAD of the source tree

+ +If you are using a released version of Kubernetes, you should +refer to the docs that go with that version. + +Documentation for other releases can be found at +[releases.k8s.io](http://releases.k8s.io). + +-- + + + + + + +# vSphere Volume + + - [Prerequisites](#prerequisites) + - [Examples](#examples) + - [Volumes](#volumes) + - [Persistent Volumes](#persistent-volumes) + - [Storage Class](#storage-class) + +## Prerequisites + +- Kubernetes with vSphere Cloud Provider configured. + For cloudprovider configuration please refer [vSphere getting started guide](http://kubernetes.io/docs/getting-started-guides/vsphere/). + +## Examples + +### Volumes + + 1. Create VMDK. + + First ssh into ESX and then use following command to create vmdk, + + ```shell + vmkfstools -c 2G /vmfs/volumes/datastore1/volumes/myDisk.vmdk + ``` + + 2. Create Pod which uses 'myDisk.vmdk'. + + See example + + ```yaml + apiVersion: v1 + kind: Pod + metadata: + name: test-vmdk + spec: + containers: + - image: gcr.io/google_containers/test-webserver + name: test-container + volumeMounts: + - mountPath: /test-vmdk + name: test-volume + volumes: + - name: test-volume + # This VMDK volume must already exist. + vsphereVolume: + volumePath: "[datastore1] volumes/myDisk" + fsType: ext4 + ``` + + [Download example](vsphere-volume-pod.yaml?raw=true) + + Creating the pod: + + ``` bash + $ kubectl create -f examples/volumes/vsphere/vsphere-volume-pod.yaml + ``` + + Verify that pod is running: + + ```bash + $ kubectl get pods test-vmdk + NAME READY STATUS RESTARTS AGE + test-vmdk 1/1 Running 0 48m + ``` + +### Persistent Volumes + + 1. Create VMDK. + + First ssh into ESX and then use following command to create vmdk, + + ```shell + vmkfstools -c 2G /vmfs/volumes/datastore1/volumes/myDisk.vmdk + ``` + + 2. Create Persistent Volume. + + See example: + + ```yaml + apiVersion: v1 + kind: PersistentVolume + metadata: + name: pv0001 + spec: + capacity: + storage: 2Gi + accessModes: + - ReadWriteOnce + persistentVolumeReclaimPolicy: Retain + vsphereVolume: + volumePath: "[datastore1] volumes/myDisk" + fsType: ext4 + ``` + + [Download example](vsphere-volume-pv.yaml?raw=true) + + Creating the persistent volume: + + ``` bash + $ kubectl create -f examples/volumes/vsphere/vsphere-volume-pv.yaml + ``` + + Verifying persistent volume is created: + + ``` bash + $ kubectl describe pv pv0001 + Name: pv0001 + Labels: + Status: Available + Claim: + Reclaim Policy: Retain + Access Modes: RWO + Capacity: 2Gi + Message: + Source: + Type: vSphereVolume (a Persistent Disk resource in vSphere) + VolumePath: [datastore1] volumes/myDisk + FSType: ext4 + No events. + ``` + + 3. Create Persistent Volume Claim. + + See example: + + ```yaml + kind: PersistentVolumeClaim + apiVersion: v1 + metadata: + name: pvc0001 + spec: + accessModes: + - ReadWriteOnce + resources: + requests: + storage: 2Gi + ``` + + [Download example](vsphere-volume-pvc.yaml?raw=true) + + Creating the persistent volume claim: + + ``` bash + $ kubectl create -f examples/volumes/vsphere/vsphere-volume-pvc.yaml + ``` + + Verifying persistent volume claim is created: + + ``` bash + $ kubectl describe pvc pvc0001 + Name: pvc0001 + Namespace: default + Status: Bound + Volume: pv0001 + Labels: + Capacity: 2Gi + Access Modes: RWO + No events. + ``` + + 3. Create Pod which uses Persistent Volume Claim. + + See example: + + ```yaml + apiVersion: v1 + kind: Pod + metadata: + name: pvpod + spec: + containers: + - name: test-container + image: gcr.io/google_containers/test-webserver + volumeMounts: + - name: test-volume + mountPath: /test-vmdk + volumes: + - name: vmdk-storage + persistentVolumeClaim: + claimName: pvc0001 + ``` + + [Download example](vsphere-volume-pvcpod.yaml?raw=true) + + Creating the pod: + + ``` bash + $ kubectl create -f examples/volumes/vsphere/vsphere-volume-pvcpod.yaml + ``` + + Verifying pod is created: + + ``` bash + $ kubectl get pod pvpod + NAME READY STATUS RESTARTS AGE + pvpod 1/1 Running 0 48m + ``` + +### Storage Class + + __Note: Here you don't need to create vmdk it is created for you.__ + 1. Create Storage Class. + + See example: + + ```yaml + kind: StorageClass + apiVersion: storage.k8s.io/v1beta1 + metadata: + name: fast + provisioner: kubernetes.io/vsphere-volume + parameters: + diskformat: zeroedthick + ``` + + [Download example](vsphere-volume-sc-fast.yaml?raw=true) + + Creating the storageclass: + + ``` bash + $ kubectl create -f examples/volumes/vsphere/vsphere-volume-sc-fast.yaml + ``` + + Verifying storage class is created: + + ``` bash + $ kubectl describe storageclass fast + Name: fast + Annotations: + Provisioner: kubernetes.io/vsphere-volume + Parameters: diskformat=zeroedthick + No events. + ``` + + 2. Create Persistent Volume Claim. + + See example: + + ```yaml + kind: PersistentVolumeClaim + apiVersion: v1 + metadata: + name: pvcsc001 + annotations: + volume.beta.kubernetes.io/storage-class: fast + spec: + accessModes: + - ReadWriteOnce + resources: + requests: + storage: 2Gi + ``` + + [Download example](vsphere-volume-pvcsc.yaml?raw=true) + + Creating the persistent volume claim: + + ``` bash + $ kubectl create -f examples/volumes/vsphere/vsphere-volume-pvcsc.yaml + ``` + + Verifying persistent volume claim is created: + + ``` bash + $ kubectl describe pvc pvcsc001 + Name: pvcsc001 + Namespace: default + Status: Bound + Volume: pvc-80f7b5c1-94b6-11e6-a24f-005056a79d2d + Labels: + Capacity: 2Gi + Access Modes: RWO + No events. + ``` + + Persistent Volume is automatically created and is bounded to this pvc. + + Verifying persistent volume claim is created: + + ``` bash + $ kubectl describe pv pvc-80f7b5c1-94b6-11e6-a24f-005056a79d2d + Name: pvc-80f7b5c1-94b6-11e6-a24f-005056a79d2d + Labels: + Status: Bound + Claim: default/pvcsc001 + Reclaim Policy: Delete + Access Modes: RWO + Capacity: 2Gi + Message: + Source: + Type: vSphereVolume (a Persistent Disk resource in vSphere) + VolumePath: [datastore1] kubevols/kubernetes-dynamic-pvc-80f7b5c1-94b6-11e6-a24f-005056a79d2d.vmdk + FSType: ext4 + No events. + ``` + + __Note: VMDK is created inside ```kubevols``` folder in datastore which is mentioned in 'vsphere' cloudprovider configuration. + The cloudprovider config is created during setup of Kubernetes cluster on vSphere.__ + + 3. Create Pod which uses Persistent Volume Claim with storage class. + + See example: + + ```yaml + apiVersion: v1 + kind: Pod + metadata: + name: pvpod + spec: + containers: + - name: test-container + image: gcr.io/google_containers/test-webserver + volumeMounts: + - name: test-volume + mountPath: /test-vmdk + volumes: + - name: vmdk-storage + persistentVolumeClaim: + claimName: pvcsc001 + ``` + + [Download example](vsphere-volume-pvcscpod.yaml?raw=true) + + Creating the pod: + + ``` bash + $ kubectl create -f examples/volumes/vsphere/vsphere-volume-pvcscpod.yaml + ``` + + Verifying pod is created: + + ``` bash + $ kubectl get pod pvpod + NAME READY STATUS RESTARTS AGE + pvpod 1/1 Running 0 48m + ``` + + + +[![Analytics](https://kubernetes-site.appspot.com/UA-36037335-10/GitHub/examples/volumes/vsphere/README.md?pixel)]() + diff --git a/volumes/vsphere/deployment.yaml b/volumes/vsphere/deployment.yaml new file mode 100644 index 00000000..1ea779b8 --- /dev/null +++ b/volumes/vsphere/deployment.yaml @@ -0,0 +1,22 @@ +apiVersion: extensions/v1beta1 +kind: Deployment +metadata: + name: deployment +spec: + replicas: 1 + template: + metadata: + labels: + app: redis + spec: + containers: + - name: redis + image: redis + volumeMounts: + - name: vmfs-vmdk-storage + mountPath: /data/ + volumes: + - name: vmfs-vmdk-storage + vsphereVolume: + volumePath: "[Datastore] volumes/testdir" + fsType: ext4 \ No newline at end of file diff --git a/volumes/vsphere/vsphere-volume-pod.yaml b/volumes/vsphere/vsphere-volume-pod.yaml new file mode 100644 index 00000000..8660d62e --- /dev/null +++ b/volumes/vsphere/vsphere-volume-pod.yaml @@ -0,0 +1,17 @@ +apiVersion: v1 +kind: Pod +metadata: + name: test-vmdk +spec: + containers: + - image: gcr.io/google_containers/test-webserver + name: test-container + volumeMounts: + - mountPath: /test-vmdk + name: test-volume + volumes: + - name: test-volume + # This VMDK volume must already exist. + vsphereVolume: + volumePath: "[DatastoreName] volumes/myDisk" + fsType: ext4 \ No newline at end of file diff --git a/volumes/vsphere/vsphere-volume-pv.yaml b/volumes/vsphere/vsphere-volume-pv.yaml new file mode 100644 index 00000000..5bc27828 --- /dev/null +++ b/volumes/vsphere/vsphere-volume-pv.yaml @@ -0,0 +1,13 @@ +apiVersion: v1 +kind: PersistentVolume +metadata: + name: pv0001 +spec: + capacity: + storage: 2Gi + accessModes: + - ReadWriteOnce + persistentVolumeReclaimPolicy: Retain + vsphereVolume: + volumePath: "[DatastoreName] volumes/myDisk" + fsType: ext4 \ No newline at end of file diff --git a/volumes/vsphere/vsphere-volume-pvc.yaml b/volumes/vsphere/vsphere-volume-pvc.yaml new file mode 100644 index 00000000..181a3848 --- /dev/null +++ b/volumes/vsphere/vsphere-volume-pvc.yaml @@ -0,0 +1,10 @@ +kind: PersistentVolumeClaim +apiVersion: v1 +metadata: + name: pvc0001 +spec: + accessModes: + - ReadWriteOnce + resources: + requests: + storage: 2Gi \ No newline at end of file diff --git a/volumes/vsphere/vsphere-volume-pvcpod.yaml b/volumes/vsphere/vsphere-volume-pvcpod.yaml new file mode 100644 index 00000000..ae903183 --- /dev/null +++ b/volumes/vsphere/vsphere-volume-pvcpod.yaml @@ -0,0 +1,15 @@ +apiVersion: v1 +kind: Pod +metadata: + name: pvpod +spec: + containers: + - name: test-container + image: gcr.io/google_containers/test-webserver + volumeMounts: + - name: test-volume + mountPath: /test-vmdk + volumes: + - name: vmdk-storage + persistentVolumeClaim: + claimName: pvc0001 \ No newline at end of file diff --git a/volumes/vsphere/vsphere-volume-pvcsc.yaml b/volumes/vsphere/vsphere-volume-pvcsc.yaml new file mode 100644 index 00000000..f73ed91b --- /dev/null +++ b/volumes/vsphere/vsphere-volume-pvcsc.yaml @@ -0,0 +1,12 @@ +kind: PersistentVolumeClaim +apiVersion: v1 +metadata: + name: pvcsc001 + annotations: + volume.beta.kubernetes.io/storage-class: fast +spec: + accessModes: + - ReadWriteOnce + resources: + requests: + storage: 2Gi diff --git a/volumes/vsphere/vsphere-volume-pvcscpod.yaml b/volumes/vsphere/vsphere-volume-pvcscpod.yaml new file mode 100644 index 00000000..d7167ac0 --- /dev/null +++ b/volumes/vsphere/vsphere-volume-pvcscpod.yaml @@ -0,0 +1,15 @@ +apiVersion: v1 +kind: Pod +metadata: + name: pvpod +spec: + containers: + - name: test-container + image: gcr.io/google_containers/test-webserver + volumeMounts: + - name: test-volume + mountPath: /test-vmdk + volumes: + - name: vmdk-storage + persistentVolumeClaim: + claimName: pvcsc0001 \ No newline at end of file diff --git a/volumes/vsphere/vsphere-volume-sc-fast.yaml b/volumes/vsphere/vsphere-volume-sc-fast.yaml new file mode 100644 index 00000000..eac5049d --- /dev/null +++ b/volumes/vsphere/vsphere-volume-sc-fast.yaml @@ -0,0 +1,7 @@ +kind: StorageClass +apiVersion: storage.k8s.io/v1beta1 +metadata: + name: fast +provisioner: kubernetes.io/vsphere-volume +parameters: + diskformat: zeroedthick \ No newline at end of file