Yandex Cloud
Search
Contact UsGet started
  • Blog
  • Pricing
  • Documentation
  • All Services
  • System Status
    • Featured
    • Infrastructure & Network
    • Data Platform
    • Containers
    • Developer tools
    • Serverless
    • Security
    • Monitoring & Resources
    • ML & AI
    • Business tools
  • All Solutions
    • By industry
    • By use case
    • Economics and Pricing
    • Security
    • Technical Support
    • Customer Stories
    • Gateway to Russia
    • Cloud for Startups
    • Education and Science
  • Blog
  • Pricing
  • Documentation
Yandex project
© 2025 Yandex.Cloud LLC
Yandex Managed Service for Kubernetes
  • Comparison with other Yandex Cloud services
  • Getting started
    • All guides
    • Connecting to a node over SSH
    • Connecting to a node via OS Login
    • Updating Kubernetes
    • Configuring autoscaling
      • Dynamic volume provisioning
      • Static volume provisioning
      • Managing storage classes
      • Expanding a pod volume
      • Increasing volume size for the StatefulSet controller
      • Mounting a volume in block mode
      • Integration with Object Storage
    • Connecting external nodes to the cluster
  • Access management
  • Pricing policy
  • Terraform reference
  • Monitoring metrics
  • Audit Trails events
  • Release notes

In this article:

  • Create a PersistentVolumeClaim object
  • Create a pod with a dynamically provisioned volume
  • How to delete a volume
  1. Step-by-step guides
  2. Working with persistent volumes
  3. Dynamic volume provisioning

Dynamic volume provisioning

Written by
Yandex Cloud
Updated at February 6, 2025
  • Create a PersistentVolumeClaim object
  • Create a pod with a dynamically provisioned volume
  • How to delete a volume

Create a pod with a dynamically provisioned volume:

  1. Create a PersistentVolumeClaim.
  2. Create a pod.

Before you start, install kubectl and configure it to work with the created Managed Service for Kubernetes cluster.

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 objectCreate a PersistentVolumeClaim object

  1. Save the following PersistentVolumeClaim creation specification to a YAML file named pvc-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
    
  2. Run this command:

    kubectl create -f pvc-dynamic.yaml
    

    Result:

    persistentvolumeclaim/pvc-dynamic created
    
  3. 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 volumeCreate a pod with a dynamically provisioned volume

  1. 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
    
  2. Run this command:

    kubectl create -f pod.yaml
    

    Result:

    pod/pod created
    
  3. 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 the k8s-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 volumeHow 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.

Was the article helpful?

Previous
Creating a network load balancer using an NGINX Ingress controller
Next
Static volume provisioning
Yandex project
© 2025 Yandex.Cloud LLC