Static volume provisioning
Create a pod with a statically provisioned volume:
Before getting started
Look up the unique ID of the disk to be used to create the PersistentVolume
, or create a new disk:
-
If you don't have a disk yet, create one.
-
Look up the unique disk ID:
$ yc compute disk list +----------------------+------+--------------+---------------+--------+----------------------+-------------+ | ID | NAME | SIZE | ZONE | STATUS | INSTANCE IDS | DESCRIPTION | +----------------------+------+--------------+---------------+--------+----------------------+-------------+ | ef3ouo4sgl86740ridn6 | k8s | 4294967296 | ru-central1-c | READY | | | | ef3qh55ckuu7md2kqhbt | | 103079215104 | ru-central1-c | READY | ef3sin41eksav1kn4gct | | | epd9vda1h0knttpcuhfu | | 10737418240 | ru-central1-b | READY | epdegdecs9o14r13gbad | | +----------------------+------+--------------+---------------+--------+----------------------+-------------+
Create a PersistentVolume
-
Save the
PersistentVolume
creation specification to a YAML file namedtest-pv.yaml
.To learn more about the specification, see the Kubernetes documentation.
When setting the
capacity: storage
parameter, make sure you specify the exact size of the disk. CSI doesn't validate the disk size for statically provisioned volumes.To create a
PersistentVolume
from an existing cloud drive, enter its unique disk ID in thevolumeHandle
parameter.apiVersion: v1 kind: PersistentVolume metadata: name: test-pv spec: capacity: storage: 4Gi accessModes: - ReadWriteOnce csi: driver: disk-csi-driver.mks.ycloud.io fsType: ext4 volumeHandle: ef3ouo4sgl86740ridn6
-
Run the command:
$ kubectl create -f test-pv.yaml persistentvolume/test-pv created
-
View information about the
PersistentVolume
created:$ kubectl describe persistentvolume test-pv Name: test-pv Labels: <none> Annotations: <none> Finalizers: [kubernetes.io/pv-protection] StorageClass: yc-network-hdd Status: Available ...
Create a PersistentVolumeClaim
-
Save the
PersistentVolumeClaim
creation specification to a YAML file namedtest-claim.yaml
.To learn more about the specification, see the Kubernetes documentation.
apiVersion: v1 kind: PersistentVolumeClaim metadata: name: test-claim spec: accessModes: - ReadWriteOnce resources: requests: storage: 4Gi volumeName: test-pv
-
Run the command:
$ kubectl create -f test-claim.yaml persistentvolumeclaim/test-claim created
-
View information about the
PersistentVolumeClaim
created:$ kubectl describe persistentvolumeclaim test-claim Name: test-claim Namespace: default StorageClass: yc-network-hdd Status: Bound Volume: test-pv ...
-
Create a pod with a statically provisioned volume
-
Save the following example to a YAML file named
test-pod.yaml
.apiVersion: v1 kind: Pod metadata: name: test-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: test-claim
To learn more about the specification, see the Kubernetes documentation.
-
Run the command:
$ kubectl create -f test-pod.yaml pod/test-pod created
-
View information about the pod created:
$ kubectl describe pod test-pod Name: test-pod Namespace: default Priority: 0 Node: cl1gqrct5oier258n08t-ypap/10.0.0.9 Start Time: Tue, 23 Jul 2019 18:34:57 +0300 Labels: <none> Annotations: <none> Status: Pending ... Events: Type Reason Age From Message ---- ------ ---- ---- ------- Normal Scheduled 3s default-scheduler Successfully assigned default/test-pod to cl1gqrct5oier258n08t-ypap
In the Compute Cloud management console under Disks, you will see the word Active next to the disk you're using.