Getting Started VMware Tanzu Community Edition (Part 3)
This is part 3 of Getting Started VMware Tanzu Community Edition
Set Up vSphere CNS and Create a Storage Policy in vSphere
vSphere administrators can set up vSphere CNS and create storage policies for virtual disk (VMDK) storage, based on the needs of workload cluster users. You can use either vSAN or local VMFS (Virtual Machine File System) for persistent storage in a Kubernetes cluster. In this case, use local VMFS as follows:
From the top-level vSphere menu, select Tags & Custom Attributes
- In the Tags pane, select Categories and click New.
2. Enter a category name, such as tkg-storage
. Use the checkboxes to associate it with Datacenter and the storage objects, Folder and Datastore. Click Create.
3. From the top-level Storage view, select your VMFS volume, and in its Summary pane, click Tags > Assign….
4. From the Assign Tag popup, click Add Tag.
5. From the Create Tag popup, give the tag a name, such as tkg-storage-ds1
and assign it the Category you created. Click OK.
6. From Assign Tag, select the tag and click Assign.
7. From top-level vSphere, select VM Storage Policies > Create a Storage Policy. A configuration wizard starts.
Choose Create VM Storage Policy
8. In the Name and description pane, enter a name for your storage policy. Record the storage policy name for reference as the storagePolicyName
value in StorageClass
objects.
9. In the Policy structure pane, under Datastore specific rules, select Enable tag-based placement rules.
10. In the Tag based placement pane, click Add Tag Rule and configure:
- Tag Category: Select your category name, for example
tkg-storage
- Usage option:
Use storage tagged with
- Tags: Browse and select your tag name “tkg-storage-ds1”
11. Confirm and configure other panes or accept defaults as needed, then click Review and finish. Finish creating the storage policy.
See Tanzu VM Storage Policy on the list
Create Persistent Volumes with Storage Classes
Default Storage Classes
Tanzu provides default StorageClass
objects that let workload cluster users provision persistent storage on their infrastructure in a turnkey environment, without needing StorageClass
objects created by a cluster administrator.
The ENABLE_DEFAULT_STORAGE_CLASS
a variable is set to true
by default in the cluster configuration file passed to --file
option of tanzu cluster create
, to enable the default storage class for a workload cluster.
The Tanzu default storage class definitions are “vSphere CNS”:
kind: StorageClass
apiVersion: storage.k8s.io/v1
metadata:
name: default
annotations:
storageclass.kubernetes.io/is-default-class: "true"
provisioner: csi.vsphere.vmware.com
parameters:
storagePolicyName: optional
See the vSphere CSI storage class parameters in the Kubernetes documentation.
Create a Custom Storage Class
Cluster administrators can select or create the VM storage policy to use as the basis for the Kubernetes StorageClass
. vSphere administrators can create a storage policy by following the steps in Set Up vSphere CNS and Create a Storage Policy in vSphere above.
- Create a
StorageClass
configuration.yaml
withprovisioner
,parameters
, and other options.
2. (vSphere only) Associate a Kubernetes storage class with a vSphere storage policy by setting its storagePolicyName
parameter to the vSphere storage policy name, as a double-quoted string. For example tanzu-custom-sc.yaml
### tanzu-custom-sc.yamlapiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
name: custom-sc
annotations:
storageclass.kubernetes.io/is-default-class: "true"
provisioner: csi.vsphere.vmware.com
parameters:
storagePolicyName: "Tanzu VM Storage Policy"
3. Pass the file to kubectl create -f tanzu-custom-sc.yaml
4. Verify the storage class by running kubectl describe storageclass custom-sc
.
Use a Custom Storage Class in a Cluster
To provision persistent storage for their cluster nodes that don’t use one of the Default Storage Classes described above, cluster users include a custom storage class in a pod configuration as follows:
- Set the context of
kubectl
to the cluster. For example:
kubectl config use-context workload1-admin@workload1
2. Select or create a storage class.
==> Select: To list available storage classes, run kubectl get storageclass
.
==> Create: Cluster admins can create storage classes by Creating a Custom Storage Class.
3. Create a PVC and its PV:
Create a PersistentVolumeClaim
configuration .yaml
with spec.storageClassName
set to the metadata.name
value of your StorageClass
object. For an example, see Enabling Dynamic Provisioning in the Kubernetes documentation. For example tanzu-pvc.yaml
### tanzu-pvc.yamlapiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: claim1
spec:
accessModes:
- ReadWriteOnce
storageClassName: custom-sc
resources:
requests:
storage: 5Gi
- Pass the file to
kubectl create -f tanzu-pvc.yaml
- Verify a PVC by running
kubectl describe pvc claim1
- A PV is automatically created with the PVC. Record its name, listed in the
kubectl describe pvc
output afterSuccessfully provisioned volume
. - Verify a PV by running
kubectl describe pv <pv_unique_name>
4. Create a pod using the PVC:
Create a Pod
configuration .yaml
that sets spec.volumes
to include your PVC under persistentVolumeClaim.claimName
. For an example, see Dynamic Provisioning and StorageClass API in the vSphere Storage for Kubernetes documentation. For example tanzu-pod-use-pvc.yaml
### tanzu-pod-use-pvc.yamlapiVersion: v1
kind: Pod
metadata:
name: test-pod
spec:
containers:
- name: my-container1
image: gcr.io/google_containers/test-webserver
volumeMounts:
- name: volume1
mountPath: /test-vmdk
volumes:
- name: volume1
persistentVolumeClaim:
claimName: claim1
- Pass the file to
kubectl create -f tanzu-pod-use-pvc.yaml
- Verify a pod used PVC by running
kubectl describe pod test-pod
References :
- https://tanzucommunityedition.io/docs/latest/
- https://vmware.github.io/vsphere-storage-for-kubernetes/documentation/storageclass.html
#VMware #Tanzu # Community #Orchestration #Kubernetes #PaaS