Yandex.Cloud
  • Services
  • Why Yandex.Cloud
  • Pricing
  • Documentation
  • Contact us
Get started
Yandex Managed Service for Kubernetes
  • Getting started
  • Step-by-step instructions
    • All instructions
    • Connecting to a node over SSH
    • Creating a configuration file
    • Configuring a Kubernetes cluster network
      • Granting access to an app running in a Kubernetes cluster
      • Using Kubernetes cluster network policies
    • Encrypting secrets
    • Using persistent volumes
      • Dynamically preparing volumes
      • Statically preparing volumes
      • Managing storage classes
      • Expanding a volume
      • Mounting a volume in Block mode
    • Managing a Kubernetes cluster
      • Adding Kubernetes cluster credentials to the kubectl configuration file
      • Getting information about a Kubernetes cluster
      • Creating a Kubernetes cluster
      • Editing a Kubernetes cluster
      • Deleting a Kubernetes cluster
    • Managing a node group
      • Getting information about a node group
      • Creating a node group
      • Editing a node group
      • Deleting a node group
  • Solutions
    • Integration with Container Registry
    • Running workloads with GPUs
    • Making backups to Object Storage
  • Concepts
    • Relationship between service resources
    • Release channels and updates
    • Using Kubernetes API objects
      • Volume
      • Service
    • Node group
      • Autoscaling node groups
      • Evicting pods from a node
      • Dynamic resource allocation for a node
      • Node groups with GPUs
    • Kubernetes cluster network policies
    • Quotas and limits
  • Access management
  • Pricing policy
  • API reference
    • Authentication in the API
    • gRPC
      • Overview
      • ClusterService
      • NodeGroupService
      • VersionService
      • OperationService
    • REST
      • Overview
      • Cluster
        • Overview
        • create
        • delete
        • get
        • list
        • listNodeGroups
        • listNodes
        • listOperations
        • start
        • stop
        • update
      • NodeGroup
        • Overview
        • create
        • delete
        • get
        • list
        • listNodes
        • listOperations
        • update
      • Version
        • Overview
        • list
  • Questions and answers
  1. Step-by-step instructions
  2. Using persistent volumes
  3. Expanding a volume

Expanding a volume

  • Enable volume expansion
  • Create a PersistentVolumeClaim
  • Create a pod with a dynamically provisioned volume
  • Delete the pod with the volume
  • Request volume expansion
  • Create a pod with a volume

To expand a volume, follow these steps.

Enable volume expansion

To enable the volume expansion feature, make sure the storage class (StorageClass) description contains allowVolumeExpansion: true. In Managed Service for Kubernetes storage, this feature is enabled by default:

kind: StorageClass
apiVersion: storage.k8s.io/v1
metadata:
  name: yc-network-hdd
provisioner: disk-csi-driver.mks.ycloud.io
volumeBindingMode: WaitForFirstConsumer
parameters:
  type: network-hdd
  csi.storage.k8s.io/fstype: ext4
allowVolumeExpansion: true
reclaimPolicy: Delete

Create a PersistentVolumeClaim

  1. Save the following PersistentVolumeClaim creation specification to a YAML file named pvc-expansion.yaml.

    To learn more about the PersistentVolumeClaim creation specification, see the Kubernetes documentation.

    apiVersion: v1
    kind: PersistentVolumeClaim
    metadata:
      name: pvc-expansion
    spec:
      accessModes:
        - ReadWriteOnce
      storageClassName: yc-network-hdd
      resources:
        requests:
          storage: 1Gi
    
  2. Create a PersistentVolumeClaim:

    kubectl create -f pvc-expansion.yaml
    

    Command execution result:

    persistentvolumeclaim/pvc-expansion created
    

Create 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-expansion
    
  2. Create a pod:

    kubectl create -f pod.yaml
    

    Command execution result:

    pod/pod created
    

Delete the pod with the volume

To request volume expansion, you need to delete the pod.

  1. Delete the pod:

    kubectl delete pod pod
    

    Command execution result:

    pod "pod" deleted
    

Request volume expansion

Make changes to the spec.resources.requests.storage field of the PersistentVolumeClaim.

  1. Open the YAML file named pvc-expansion.yaml:

    kubectl edit pvc pvc-expansion
    

    In the text editor, change the disk size value and save it:

    # Please edit the object below. Lines beginning with a '#' will be ignored,
    # and an empty file will abort the edit. If an error occurs while saving this file will be
    # reopened with the relevant failures.
    #
    apiVersion: v1
    kind: PersistentVolumeClaim
    metadata:
    ...
    spec:
      accessModes:
      - ReadWriteOnce
      resources:
        requests:
         storage: 1Gi # Change the value to 2Gi.
    ...
    status:
      accessModes:
      - ReadWriteOnce
      capacity:
        storage: 1Gi
    phase: Bound
    
  2. Wait for the volume to expand. Check the change results:

    kubectl get pvc pvc-expansion -o yaml
    

    The spec.resources.requests.storage field shows the requested volume size:

    apiVersion: v1
    kind: PersistentVolumeClaim
    metadata:
    ...
    spec:
      accessModes:
      - ReadWriteOnce
      resources:
        requests:
          storage: 2Gi
    ...
    status:
      accessModes:
      - ReadWriteOnce
      capacity:
        storage: 1Gi
    ...
    

Create a pod with a volume

  1. To resize the volume, create a pod:

    kubectl create -f pod.yaml
    

    Command execution result:

    pod/pod created
    
  2. Check the change results:

    kubectl get pvc pvc-expansion -o yaml
    

    The volume size increased. The status.capacity.storage field shows the expanded size:

    apiVersion: v1
    kind: PersistentVolumeClaim
    metadata:
    ...
    spec:
      accessModes:
      - ReadWriteOnce
      resources:
        requests:
          storage: 2Gi
    ...
    status:
      accessModes:
      - ReadWriteOnce
      capacity:
        storage: 2Gi
    ...
    
In this article:
  • Enable volume expansion
  • Create a PersistentVolumeClaim
  • Create a pod with a dynamically provisioned volume
  • Delete the pod with the volume
  • Request volume expansion
  • Create a pod with a volume
Language
Careers
Privacy policy
Terms of use
© 2021 Yandex.Cloud LLC