Statically provisioned disk volumes let you attach an existing Alibaba Cloud disk to a pod so that data survives pod restarts and rescheduling. Unlike dynamic provisioning, you create the persistent volume (PV) and persistent volume claim (PVC) yourself, then deploy an application that references the PVC.
Here is a summary of the process:
-
As a cluster administrator, create a PV backed by an existing disk.
-
Create a PVC that binds to the PV using a label selector.
-
Deploy an application that mounts the PVC.
Prerequisites
Before you begin, ensure that you have:
-
An ACK managed cluster. See Create an ACK managed cluster.
-
An existing Alibaba Cloud disk. See Create a disk.
-
kubectl connected to your cluster. See Obtain the kubeconfig file of a cluster and use kubectl to connect to the cluster.
Limitations
-
Each disk can be mounted to only one pod at a time.
-
A disk can only be mounted to a node in the same zone as the disk.
Use cases
Static disk provisioning is a good fit for:
-
Stateful workloads with high I/O requirements — databases such as MySQL and Redis that need dedicated block storage without data sharing.
-
High-speed log writes — applications that write log data at sustained high throughput.
-
Pod-independent data storage — data that must outlive any individual pod.
Create a PV
-
Create a file named
pv-static.yamlwith the following content:apiVersion: v1 kind: PersistentVolume metadata: name: <your-disk-id> labels: alicloud-pvname: <your-disk-id> failure-domain.beta.kubernetes.io/zone: <your-zone> failure-domain.beta.kubernetes.io/region: <your-region> spec: capacity: storage: 20Gi accessModes: - ReadWriteOnce flexVolume: driver: "alicloud/disk" fsType: "ext4" options: volumeId: "<your-disk-id>"Replace the placeholders with your actual values:
Field Description Required Example name(metadata)The name of the PV. Set to the disk ID. Yes <your-disk-id>alicloud-pvnameLabel used by the PVC selector to bind to this PV. Set to the disk ID. Yes <your-disk-id>failure-domain.beta.kubernetes.io/zoneThe zone where the disk is deployed. Required for multi-zone clusters to schedule pods to the correct zone. Yes (multi-zone clusters) cn-hangzhou-bfailure-domain.beta.kubernetes.io/regionThe region where the disk is deployed. Required for multi-zone clusters. Yes (multi-zone clusters) cn-hangzhoucapacity.storageStorage size. Yes 20GivolumeIdThe ID of the existing disk to attach. Yes <your-disk-id>For clusters deployed across multiple zones, the
failure-domain.beta.kubernetes.io/zoneandfailure-domain.beta.kubernetes.io/regionlabels ensure that pods are scheduled to the zone where the disk is located. See Mount a statically provisioned disk volume for details. -
Apply the manifest:
kubectl create -f pv-static.yaml -
Verify that the PV was created: Log on to the ACK console. In the left-side navigation pane, click Clusters. On the Clusters page, find the cluster that you want to manage, and click the name of the cluster or click Details in the Actions column. In the left-side navigation pane of the details page, choose Volumes > Persistent Volumes. Verify that the newly created PV is displayed.
Create a PVC
-
Create a file named
pvc-static.yamlwith the following content:kind: PersistentVolumeClaim apiVersion: v1 metadata: name: pvc-disk spec: accessModes: - ReadWriteOnce resources: requests: storage: 20Gi selector: matchLabels: alicloud-pvname: <your-disk-id>Replace
<your-disk-id>with the disk ID you used when creating the PV. Theselector.matchLabelsfield binds this PVC to the PV with the matchingalicloud-pvnamelabel. -
Apply the manifest:
kubectl create -f pvc-static.yaml -
Verify that the PVC was created: Log on to the ACK console. In the left-side navigation pane, click Clusters. On the Clusters page, find the cluster that you want to manage, and click the name of the cluster or click Details in the Actions column. In the left-side navigation pane of the details page, choose Volumes > Persistent Volume Claims. On the Persistent Volume Claims page, verify that the newly created PVC is displayed.
Deploy an application
-
Create a file named
static.yamlwith the following content:apiVersion: apps/v1 kind: Deployment metadata: name: nginx-static labels: app: nginx spec: selector: matchLabels: app: nginx template: metadata: labels: app: nginx spec: containers: - name: nginx image: nginx volumeMounts: - name: disk-pvc mountPath: "/data" volumes: - name: disk-pvc persistentVolumeClaim: claimName: pvc-diskThe Deployment mounts the
pvc-diskPVC to the/datapath inside the container. -
Apply the manifest:
kubectl create -f static.yaml -
Verify that the Deployment and pod are running:
kubectl get pod | grep staticExpected output:
nginx-static-78c7dcb9d7-g**** 2/2 Running 0 32sYou can also verify in the ACK console: navigate to Workloads > Deployments and confirm that
nginx-staticis listed.
Verify data persistence
Run through the following steps to confirm that data written to the disk survives pod deletion and recreation.
-
Confirm the disk is mounted to
/data:kubectl exec nginx-static-78c7dcb9d7-g**** -- df | grep dataExpected output:
/dev/vdf 20511312 45080 20449848 1% /data -
List the files at
/data:kubectl exec nginx-static-78c7dcb9d7-g**** -- ls /dataExpected output:
lost+found -
Create a test file:
kubectl exec nginx-static-78c7dcb9d7-g**** -- touch /data/static -
Confirm the file exists:
kubectl exec nginx-static-78c7dcb9d7-g**** -- ls /dataExpected output:
static lost+found -
Delete the pod to trigger recreation:
kubectl delete pod nginx-static-78c7dcb9d7-g****Expected output:
pod "nginx-static-78c7dcb9d7-g****" deletedIn a separate terminal, watch the pod lifecycle:
kubectl get pod -w -l app=nginxExpected output:
NAME READY STATUS RESTARTS AGE nginx-static-78c7dcb9d7-g**** 2/2 Running 0 50s nginx-static-78c7dcb9d7-g**** 2/2 Terminating 0 72s nginx-static-78c7dcb9d7-h**** 0/2 Pending 0 0s nginx-static-78c7dcb9d7-h**** 0/2 Pending 0 0s nginx-static-78c7dcb9d7-h**** 0/2 Init:0/1 0 0s nginx-static-78c7dcb9d7-g**** 0/2 Terminating 0 73s nginx-static-78c7dcb9d7-h**** 0/2 Init:0/1 0 5s nginx-static-78c7dcb9d7-g**** 0/2 Terminating 0 78s nginx-static-78c7dcb9d7-g**** 0/2 Terminating 0 78s nginx-static-78c7dcb9d7-h**** 0/2 PodInitializing 0 6s nginx-static-78c7dcb9d7-h**** 2/2 Running 0 8s -
Get the name of the recreated pod:
kubectl get podExpected output:
NAME READY STATUS RESTARTS AGE nginx-static-78c7dcb9d7-h**** 2/2 Running 0 14s -
Verify that the test file still exists in the recreated pod:
kubectl exec nginx-static-78c7dcb9d7-h6brd -- ls /dataExpected output:
static lost+foundThe
staticfile is present, confirming that data written to the disk persists across pod deletions and recreations.
What's next
-
To use a storage class for automatic PV provisioning, see Use dynamically provisioned disk volumes for persistent storage.
-
For advanced configuration options when mounting statically provisioned disk volumes, see Mount a statically provisioned disk volume.