Expanding a pod volume
To expand a volume:
- Enable volume expansion.
- Create a PersistentVolumeClaim.
- Create a pod with a dynamically provisioned volume.
- Request volume expansion.
- Check the pod with the volume.
Before you start, install kubectl
Enable volume expansion
To enable the volume expansion feature, make sure the storage class (StorageClass) description contains the allowVolumeExpansion: true parameter. 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 object
-
Save the following PersistentVolumeClaim creation specification to a YAML file named
pvc-expansion.yaml.To learn more about the
PersistentVolumeClaimcreation specification, see the Kubernetes documentation .apiVersion: v1 kind: PersistentVolumeClaim metadata: name: pvc-expansion spec: accessModes: - ReadWriteOnce storageClassName: yc-network-hdd resources: requests: storage: 1Gi -
Create the
PersistentVolumeClaimobject:kubectl create -f pvc-expansion.yamlResult:
persistentvolumeclaim/pvc-expansion created
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-expansion -
Create a pod:
kubectl create -f pod.yamlResult:
pod/pod created
Request volume expansion
-
Edit the
spec.resources.requests.storagefield of thePersistentVolumeClaimobject:kubectl patch pvc pvc-expansion -p '{"spec":{"resources":{"requests":{"storage":"2Gi"}}}}' -
Wait a few minutes for the volume to expand. Check the change results:
kubectl get pvc pvc-expansion -o yamlThe
status.capacity.storagefield shows the requested volume size:apiVersion: v1 kind: PersistentVolumeClaim metadata: ... spec: accessModes: - ReadWriteOnce resources: requests: storage: 2Gi ... status: accessModes: - ReadWriteOnce capacity: storage: 2Gi ...
Check the pod with the volume
Check the pod status:
kubectl get pod pod -o yaml
The pod is running. The status section shows no container restarts.