Use a static cloud disk persistent volume

Updated at:

Mount an existing cloud disk with a persistent volume (PV) and persistent volume claim (PVC).

Static provisioning uses an existing Elastic Compute Service (ECS) cloud disk. ACK binds it to a PVC without creating a disk. For automatic disk creation, see the dynamic provisioning documentation.

Prerequisites

Required:

Considerations

  • Cloud disk is in the same region and zone as the cluster.

  • PV name matches the disk ID in volumeId.

Mount a disk with a PV and PVC

Step 1: Create a PersistentVolume

Create a PV from a YAML file or in the ACK console.

Option 1: YAML file

  1. Create a file named disk-pv.yaml with the following content:

    apiVersion: v1
    kind: PersistentVolume
    metadata:
      name: d-bp1j17ifxfasvts3****
      labels:
        failure-domain.beta.kubernetes.io/zone: cn-hangzhou-b
        failure-domain.beta.kubernetes.io/region: cn-hangzhou
    spec:
      capacity:
        storage: 20Gi
      storageClassName: disk
      accessModes:
        - ReadWriteOnce
      flexVolume:
        driver: "alicloud/disk"
        fsType: "ext4"
        options:
          volumeId: "d-bp1j17ifxfasvts3****"

    Replace these values:

    Field Description
    name Disk ID. Must match volumeId.
    failure-domain.beta.kubernetes.io/zone Zone of the cluster and disk, for example, cn-hangzhou-b.
    failure-domain.beta.kubernetes.io/region Region of the cluster and disk, for example, cn-hangzhou.
    capacity.storage Disk size, for example, 20Gi.
    volumeId Disk ID. Must match name.
  2. Apply the YAML:

    kubectl apply -f disk-pv.yaml
  3. Verify PV creation:

    kubectl get pv

    Expected output:

    NAME                      CAPACITY   ACCESS MODES   STATUS      CLAIM   STORAGECLASS   AGE
    d-bp1j17ifxfasvts3****   20Gi       RWO            Available           disk           5s

    STATUS Available means the PV is ready to claim.

Option 2: ACK console

  1. Log on to the ACK console.

  2. On Clusters, click Details for your cluster in the Actions column.

  3. In the left-side navigation pane, choose Volumes > Persistent Volumes.

  4. Click Create.

  5. In Create PV, configure:

    Parameter Description
    PV Type Select Cloud Disk.
    Volume Plug-in Select Flexvolume.
    Access Mode Defaults to ReadWriteOnce.
    Disk ID Cloud disk in the same region and zone as the cluster.
    File System Type File system type. Valid values: ext4 (default), ext3, xfs, vfat.
    Label Optional PV labels.
  6. Click Create.

Step 2: Create a PersistentVolumeClaim

  1. Create a file named disk-pvc.yaml with the following content:

    storageClassName and accessModes must match the PV. Kubernetes binds the PVC when both match.
    kind: PersistentVolumeClaim
    apiVersion: v1
    metadata:
      name: pvc-disk
    spec:
      accessModes:
        - ReadWriteOnce
      storageClassName: disk
      resources:
        requests:
          storage: 20Gi
  2. Apply the YAML:

    kubectl apply -f disk-pvc.yaml
  3. Verify PVC binding:

    kubectl get pvc

    Expected output:

    NAME       STATUS   VOLUME                    CAPACITY   ACCESS MODES   STORAGECLASS   AGE
    pvc-disk   Bound    d-bp1j17ifxfasvts3****   20Gi       RWO            disk           5s

    STATUS Bound confirms PVC-PV binding.

Step 3: Create a pod that uses the PVC

  1. Create a file named disk-pod.yaml with the following content:

    apiVersion: v1
    kind: Service
    metadata:
      name: nginx
      labels:
        app: nginx
    spec:
      ports:
      - port: 80
        name: web
      clusterIP: None
      selector:
        app: nginx
    ---
    apiVersion: apps/v1
    kind: StatefulSet
    metadata:
      name: web
    spec:
      selector:
        matchLabels:
          app: nginx
      serviceName: "nginx"
      template:
        metadata:
          labels:
            app: nginx
        spec:
          containers:
          - name: nginx
            image: nginx
            ports:
            - containerPort: 80
              name: web
            volumeMounts:
            - name: pvc-disk
              mountPath: /data
          volumes:
            - name: pvc-disk
              persistentVolumeClaim:
                claimName: pvc-disk

    The StatefulSet mounts the PVC (claimName: pvc-disk) at /data in the container.

  2. Apply the YAML:

    kubectl apply -f disk-pod.yaml
  3. Verify the pod runs with the volume mounted:

    kubectl get pods

    Expected output:

    NAME    READY   STATUS    RESTARTS   AGE
    web-0   1/1     Running   0          10s

    STATUS Running confirms the pod started with the disk at /data.

Next steps

  • See the dynamic provisioning documentation to let ACK provision disks automatically.

  • See the snapshot documentation to configure disk snapshots for backup and recovery.