Mount a static persistent volume using a PVC

更新时间:
复制 MD 格式

You can mount a static persistent volume for a pod by binding it to an existing Persistent Volume (PV).

Note

LHC is not integrated with Alibaba Cloud NAS or cloud disk storage. To use storage features, you must install a third-party storage plugin.

Prerequisites

Step 1: Create a static PV

Create a PV and attach it to an existing cloud disk. You can create the PV from a YAML file or in the console.

The following is a sample YAML file:

apiVersion: v1
kind:PersistentVolume
metadata:
  labels:
    cafe.sofastack.io/diskId: d-zm0fd73z6tmf5j7pgbpe
  name: pv-efficient
spec:
  accessModes:
-ReadWriteOnce
  capacity:
    storage:25Gi
  csi:
    driver: antcloud-csi
    fsType: ext4
    volumeAttributes:
      storage_type: cloud_disk
    volumeHandle: instance_test_efficiency
  storageClassName: csi-disk-efficiency

Parameter description

Parameter name

Description

Required

Notes

cafe.sofastack.io/diskId

The ID of the Alibaba Cloud disk. The format is d-xxx.

Yes

Obtain the disk ID from the Resource Management console. Navigate to Elastic Compute Service > Storage & Snapshots > Disks.

volumeAttributes

Disk properties.

Yes

Follow the limits of the backend storage, such as the Alibaba Cloud disk limits. For the csi-disk-ssd and csi-disk-efficiency storage classes, the minimum size is 20 GB.

volumeHandle

A unique ID for the backend storage. This ID is specified by the user.

Yes

-

Step 2: Create a PVC and bind it to the PV

You can create the PVC from a YAML file or in the console.

The following is a sample YAML file:

apiVersion: v1
kind:PersistentVolumeClaim
metadata:
 name: test-pvc
namespace:default
spec:
 accessModes:
-ReadWriteOnce
 resources:
   requests:
     storage:25Gi
 storageClassName: csi-disk-efficiency
 volumeName: pv-efficient
Note

You must specify the name of the existing PV in the `volumeName` field. For parameter descriptions, see Mount a dynamically provisioned volume using a PVC.

Step 3: Use the PVC

Use the PVC to mount a static volume when you create a pod.

apiVersion: v1
kind:Pod
metadata:
  name: pod-with-disk
namespace:default
  labels:
    app: nginx
spec:
  tolerations:
- key: node.kubernetes.io/unreachable
    effect:NoSchedule
operator:Exists
  automountServiceAccountToken:false
  containers:
- name: busybox
    image: reg-cnsh-nf.cloud.alipay.com/library/busybox
    command:["sleep","3000"]
    ports:
- containerPort:80
    volumeMounts:
- name: data
        mountPath:"/data"
  volumes:
- name: data
      persistentVolumeClaim:
        claimName: test-pvc

After the container starts, the pod status is `running`:

# kubectl get pod
NAME            READY   STATUS    RESTARTS   AGE
pod-with-disk   1/1     Running   0          103s