Mount dynamically provisioned volumes by using a StorageClass. Create a storage class before you mount a volume.
LHC is not integrated with Alibaba Cloud NAS or cloud disk storage. To use storage features, install a third-party storage plugin.
Prerequisites
A storage class has been created.
Step 1: Create a PVC
Before you create a pod, create a persistent volume claim (PVC). A corresponding Persistent Volume (PV) is then automatically created.
Example of a PVC for a cloud disk
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: test-pvc
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 25Gi
storageClassName: csi-disk-efficiency
Parameter description
|
Parameter name |
Description |
Required |
Notes |
|
accessModes |
Read-only or read/write access mode. |
No |
Only `ReadWriteOnce` is supported. |
|
storage |
Storage size |
Yes |
Subject to backend storage limits. For more information, see Limits. For the `csi-disk-ssd` and `csi-disk-efficiency` StorageClasses, the minimum storage size is 20 GiB. Otherwise, the PV cannot be created and the PVC remains in the `Pending` state. |
|
storageClassName |
The name of the StorageClass. |
Yes |
Required to create the cloud disk. |
Example of a PVC for NAS
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: test-pvc
spec:
accessModes:
- ReadWriteMany
resources:
requests:
storage: 25Gi
storageClassName: csi-nas-capacity # Valid values: csi-nas-capacity or csi-nas-performance
For NAS storage, the specified storage size limit is not enforced. The limit does not restrict how much data a container can write at runtime. It is used only for matching during the PV-PVC binding process.
Parameter description
|
Parameter |
Description |
Required |
Notes |
|
accessModes |
Read-only or read/write access mode. |
No |
Valid values: - ReadWriteOnce - ReadWriteMany |
|
storage |
Storage size |
Yes |
Subject to backend storage limits, such as Alibaba Cloud NAS limits. The maximum capacity is 1 PB for Performance NAS or 10 PB for Capacity NAS. |
|
storageClassName |
The name of the StorageClass. |
Yes |
If you do not specify an existing name, the cloud disk cannot be created. |
Step 2: Use the PVC
When you create a pod, reference the PVC to mount a dynamically provisioned volume.
apiVersion: v1
kind: Pod
metadata:
name: pod-with-nas
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 running, the pod status changes to `Running`:
# kubectl get pod
NAME READY STATUS RESTARTS AGE
pod-with-nas 1/1 Running 0 103s