Dynamic volume provisioning
Create a pod with a dynamically provisioned volume:
First, install kubectl
Tip
You can use a Yandex Object Storage bucket to store your pod. For more information, see Integration with Object Storage.
Create a PersistentVolumeClaim
-
Save the following
PersistentVolumeClaimcreation specification to a YAML file namedpvc-dynamic.yaml.Note
If the
storageClassNameparameter is not specified, the default storage class,yc-network-hdd, will be used. Learn how to change the default class in Update the default storage class.Learn more about the
PersistentVolumeClaimcreation specification in the Kubernetes guide .apiVersion: v1 kind: PersistentVolumeClaim metadata: name: pvc-dynamic spec: accessModes: - ReadWriteOnce storageClassName: yc-network-hdd resources: requests: storage: 4Gi -
Run this command:
kubectl create -f pvc-dynamic.yamlResult:
persistentvolumeclaim/pvc-dynamic created -
View the information about the new
PersistentVolumeClaimobject:kubectl describe persistentvolumeclaim pvc-dynamicResult:
Name: pvc-dynamic Namespace: default StorageClass: yc-network-hdd ... Type Reason Age From Message ---- ------ ---- ---- ------- Normal WaitForFirstConsumer 9s (x3 over 15s) persistentvolume-controller waiting for first consumer to be created before binding
Create a pod with a dynamically provisioned volume
-
Save the following pod creation specification to a YAML file named
pod.yaml.Learn more about the pod creation specification in this Kubernetes guide
.apiVersion: v1 kind: Pod metadata: name: pod spec: containers: - name: app image: ubuntu command: ["/bin/sh"] args: ["-c", "while true; do echo $(date -u) >> /data/out.txt; sleep 5; done"] volumeMounts: - name: persistent-storage mountPath: /data volumes: - name: persistent-storage persistentVolumeClaim: claimName: pvc-dynamic -
Run this command:
kubectl create -f pod.yamlResult:
pod/pod created -
View the information about the new pod:
kubectl describe pod podResult:
Name: pod Namespace: default Priority: 0 ... Normal Pulled 11s kubelet, cl1gqrct5oie********-ytas Successfully pulled image "ubuntu" Normal Created 10s kubelet, cl1gqrct5oie********-ytas Created container Normal Started 10s kubelet, cl1gqrct5oie********-ytas Started containerAfter creating the pod:
-
In the management console
in Compute Cloud under Disks, a new disk will appear with thek8s-csiprefix in its name. -
You can find the disk provisioning information in the
PersistentVolumeClaimevents:kubectl describe persistentvolumeclaim pvc-dynamicResult:
Name: pvc-dynamic Namespace: default StorageClass: yc-network-hdd ... Normal ExternalProvisioning 4m10s (x3 over 4m10s) persistentvolume-controller waiting for a volume to be created, either by external provisioner "disk-csi-driver.mks.ycloud.io" or manually created by system administrator Normal Provisioning 4m10s disk-csi-driver.mks.ycloud.io_cat1h5l0v862oq74cp8j_d0f0b837-a875-11e9-b6cb-d00d******** External provisioner is provisioning volume for claim "default/pvc-dynamic" Normal ProvisioningSucceeded 4m7s disk-csi-driver.mks.ycloud.io_cat1h5l0v862oq74cp8j_d0f0b837-a875-11e9-b6cb-d00d******** Successfully provisioned volume pvc-c4794058-ad68-11e9-b71a-d00d********
-
How to delete a volume
To delete a dynamically provisioned volume, delete the PersistentVolumeClaim:
kubectl delete pvc <PersistentVolumeClaim_ID>
The disk will be deleted automatically from Yandex Compute Cloud.