This is a draft document that was built and uploaded automatically. It may document beta software and be incomplete or even incorrect. Use this document at your own risk.

The vSphere cloud provider can be enabled with SUSE CaaS Platform to allow Kubernetes pods to use VMWare vSphere Virtual Machine Disk (VMDK) volumes as persistent storage.
This chapter provides the two types of persistent volume usage and description.
Please refer to Cluster Bootstrap on how to setup vSphere cloud provider enabled cluster.
Extra node meta could be found when region and zone was added to vsphere.conf before bootstrap cluster node.
[Labels] region = "<VC_DATACENTER_TAG>" zone = "<VC_CLUSTER_TAG>"
Region refers to the datacenter and zones refers to the cluster grouping of hosts within the datacenter.
Adding region and zone makes Kubernetes persistent volume created with zone and region labels.
With such an environment, Kubernetes pod scheduler is set to be locational aware for the persistent volume.
For more information refer to: https://vmware.github.io/vsphere-storage-for-kubernetes/documentation/zones.html.
You can view the cloudprovider associated node meta with command.
kubectl get nodes -o jsonpath='{range .items[*]}{.metadata.name}{"\tregion: "}{.metadata.labels.failure-domain\.beta\.kubernetes\.io/region}{"\tzone: "}{.metadata.labels.failure-domain\.beta\.kubernetes\.io/zone}{"\n"}{end}'
...
010084072206 region: vcp-provo zone: vcp-cluster-jazz
010084073045 region: vcp-provo zone: vcp-cluster-jazzCreate new VMDK volume in datastore. The VMDK volume used in persistent volume must exist before the resource is created.
You can use govc to automate the task.
For installation instructions, refer to: https://github.com/vmware/govmomi/tree/master/govc.
govc datastore.disk.create -dc <DATA_CENTER> -ds <DATA_STORE> -size <DISK_SIZE> <DISK_NAME>
<DATA_CENTER> The datacenter name in vCenter where Kubernetes nodes reside.
<DATA_STORE> The datastore in vCenter where volume should be created.
<DISK_SIZE> The volume size to create, for example 1G.
<DISK_NAME> The VMDK volume name. for example my-disk.vmdk, or <CLUSTER_NAME>-folder/my-disk.vmdk.
Create persistent volume - sample-static-pv.yaml.
kubectl create -f sample-static-pv.yaml
apiVersion: v1 kind: PersistentVolume metadata: name: sample-static-pv 1 spec: capacity: storage: 1Gi 2 accessModes: - ReadWriteOnce persistentVolumeReclaimPolicy: Delete 3 vsphereVolume: volumePath: "[datastore] volume/path" 4 fsType: ext4 5
Create persistent volume claim - sample-static-pvc.yaml.
kubectl create -f sample-static-pvc.yaml
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: sample-static-pvc
labels:
app: sample
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 1Gi 1The required volume size. |
Create deployement - sample-static-deployment.yaml.
kubectl create -f sample-static-deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: sample-static-deployment
labels:
app: sample
tier: sample
spec:
selector:
matchLabels:
app: sample
tier: sample
strategy:
type: Recreate
template:
metadata:
labels:
app: sample
tier: sample
spec:
containers:
- image: busybox
name: sample
volumeMounts:
- name: sample-volume
mountPath: /data 1
command: [ "sleep", "infinity" ]
volumes:
- name: sample-volume
persistentVolumeClaim:
claimName: sample-static-pvc 2Check persistent volume claim is bonded and pod is running.
kubectl get pvc ... NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE sample-static-pvc Bound sample-static-pv 1Gi RWO 55s kubectl get pod ... NAME READY STATUS RESTARTS AGE sample-static-deployment-549dc77d76-pwdqw 1/1 Running 0 3m42s
Create storage class - sample-sc.yaml.
kubectl create -f sample-sc.yaml
kind: StorageClass
apiVersion: storage.k8s.io/v1
metadata:
name: sample-sc
annotations:
storageclass.kubernetes.io/is-default-class: "true" 1
provisioner: kubernetes.io/vsphere-volume
parameters:
datastore: "datastore" 2Create persistent volume claim - sample-dynamic-pvc.yaml.
kubectl create -f sample-dynamic-pvc.yaml
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: sample-dynamic-pvc
annotations:
volume.beta.kubernetes.io/storage-class: sample-sc 1
labels:
app: sample
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 1Gi 2Create deployment - sample-deployment.yaml
kubectl create -f sample-deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: sample-dynamic-deployment
labels:
app: sample
tier: sample
spec:
selector:
matchLabels:
app: sample
tier: sample
strategy:
type: Recreate
template:
metadata:
labels:
app: sample
tier: sample
spec:
containers:
- image: busybox
name: sample
volumeMounts:
- name: sample-volume
mountPath: /data 1
command: [ "sleep", "infinity" ]
volumes:
- name: sample-volume
persistentVolumeClaim:
claimName: sample-dynamic-pvc 2Check persistent volume claim is bonded and pod is running.
kubectl get pvc ... NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE sample-dynamic-pvc Bound pvc-0ca694b5-0084-4e36-bef1-5b2354158d79 1Gi RWO sample-sc 70s kubectl get pod ... NAME READY STATUS RESTARTS AGE sample-dynamic-deployment-687765d5b5-67vnh 1/1 Running 0 20s