How to create a new storageclass with RECLAIMPOLICY: Retain in VKS
search cancel

How to create a new storageclass with RECLAIMPOLICY: Retain in VKS

book

Article ID: 398198

calendar_today

Updated On:

Products

VMware vSphere Kubernetes Service

Issue/Introduction

Default storageclass RECLAIMPOLICY is "Delete" in VKS.  Changing RECLAIMPOLICY for existing storageclass is not supported.

This KB explains how to create a new storageclass with RECLAIMPOLICY:Retain.

Environment

VMware vSphere Kubernetes Service

Resolution

1. Generate a YAML file for a new storageclass

STORAGECLASS_NAME=test-sc
STORAGEPOICY_NAME=vsan-default-storage-policy

cat > ${STORAGECLASS_NAME}.yaml <<EOF
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
  labels:
    isSyncedFromSupervisor: "false"
  name: ${STORAGECLASS_NAME}
parameters:
  storagepolicyname: "${STORAGEPOLICY_NAME}"
provisioner: csi.vsphere.vmware.com
reclaimPolicy: Retain
allowVolumeExpansion: true
volumeBindingMode: Immediate
EOF

2. Switch to the Guest Cluster context

kubectl config use-context <TARGET_GUEST_CLUSTER>

2. Apply

kubectl apply -f ${STORAGECLASS_NAME}.yaml
kubectl get sc

NAME                                      PROVISIONER              RECLAIMPOLICY   VOLUMEBINDINGMODE
test-sc                                   csi.vsphere.vmware.com   Retain          Immediate # <------ New "Retain" StorageClass
vsan-default-storage-policy (default)     csi.vsphere.vmware.com   Delete          Immediate
vsan-default-storage-policy-latebinding   csi.vsphere.vmware.com   Delete          WaitForFirstConsumer