Dynamic volume provisioning
Create a pod with a dynamically provisioned volume:
Before you start, install kubectl
Tip
You can use a Yandex Object Storage bucket as storage for your pod. For more information, see Integration with Object Storage.
Create a PersistentVolumeClaim object
-
Save the following
PersistentVolumeClaim
creation specification to a YAML file namedpvc-dynamic.yaml
.Note
If the
storageClassName
parameter is not specified, the default storage class (yc-network-hdd
) is used. To change the default class, see Change the default storage class.To learn more about the
PersistentVolumeClaim
creation specification, see the Kubernetes documentation .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.yaml
Result:
persistentvolumeclaim/pvc-dynamic created
-
View the information about the new
PersistentVolumeClaim
object:kubectl describe persistentvolumeclaim pvc-dynamic
Result:
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
.To learn more about the pod creation specification, see the Kubernetes documentation
.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.yaml
Result:
pod/pod created
-
View the information about the new pod:
kubectl describe pod pod
Result:
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 container
After creating a pod:
-
In the management console
in Compute Cloud in the Disks section, a new disk will appear with thek8s-csi
prefix in the disk name. -
You can find disk provisioning information in the
PersistentVolumeClaim
events:kubectl describe persistentvolumeclaim pvc-dynamic
Result:
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
object:
kubectl delete pvc <PersistentVolumeClaim_object_ID>
The disk will be deleted automatically from Yandex Compute Cloud.