Ali Cloud Kubernetes CSI Practice - CPFS Storage Volume Use

1. Preface

CPFS(Cloud Paralleled File System) is a parallel file system.CPFS data is stored in multiple data nodes in the cluster and can be accessed by multiple clients at the same time, thereby providing high IOPS, high throughput, and low latency data storage services for large high performance computer clusters.
Aliyun Kubernetes CSI supports both static and dynamic mounting of CPFS storage volumes.In the way of static storage volume mounting, manual editing and creating a pv/pvc are usually required for mounting. When a large number of pv/pvcs are required, manual creation becomes tedious, and the function of dynamic storage volume mounting can meet your needs.This article demonstrates how to use in an ACK cluster alibaba-cloud-csi-driver Mount the CPFS storage volume.

2. Deploy csi-cpfs components

If you need to mount the CPFS storage volume, you first need to deploy cpfs-provisioner and cpfs-plugin in the ACK cluster by following these steps:

2.1 Deploy cpfs-provisioner:

$ kubectl apply -f https://raw.githubusercontent.com/kubernetes-sigs/alibaba-cloud-csi-driver/master/deploy/cpfs/cpfs-provisioner.yaml

2.2 Deploy cpfs-plugin:

$ kubectl apply -f https://raw.githubusercontent.com/kubernetes-sigs/alibaba-cloud-csi-driver/master/deploy/cpfs/cpfs-plugin.yaml

2.3 Check Running Status

$ kubectl -nkube-system get po |grep cpfs
csi-cpfs-provisioner-0                             1/1     Running
csi-cpfsplugin-g2czx                               2/2     Running
csi-cpfsplugin-l6zp8                               2/2     Running
csi-cpfsplugin-nwt2j                               2/2     Running
csi-cpfsplugin-skjds                               2/2     Running
csi-cpfsplugin-sp9mb                               2/2     Running
csi-cpfsplugin-tmjm5                               2/2     Running

3. Use CPFS dynamic storage volumes

Currently, the Ali Cloud Kubernetes CSI supports subpath CPFS dynamic storage volume mounting.

When multiple Kubernetes applications or Pods need to mount the same CPFS storage volume to share data, or different Pods mount different subdirectories of the same CPFS file system, you can use subpath CPFS dynamic storage volume.csi automatically creates a subdirectory named PV name in the root directory of the CPFS file system and mounts it in the pod of the application.

3.1 Create CPFS file system

Users use it first NAS Console Create the CPFS file system.
File system:

View file system details and get mount point information:

3.2 Create StoragClass

Edit the storageclass.yaml file for detailed parameter descriptions: https://github.com/kubernetes-sigs/alibaba-cloud-csi-driver/blob/master/docs/cpfs-dynamic.md

apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
  name: alicloud-cpfs
parameters:
  volumeAs: subpath
  server: "xxxxxx@tcp:xxxxxx@tcp:/xxxxxx"
  archiveOnDelete: "false"
provisioner: cpfsplugin.csi.alibabacloud.com
reclaimPolicy: Delete

Replace the sever parameter with the mount point path information and run the following command to create StorageClass alicloud-cpfs

$ kubectl create -f storageclass.yaml
storageclass.storage.k8s.io/alicloud-cpfs created
3.3 Create PV/PVC and OD mounted cpfs storage volumes

The sample application orchestration file deploy.yaml is as follows:

kind: PersistentVolumeClaim
apiVersion: v1
metadata:
  name: cpfs-pvc
spec:
  accessModes:
    - ReadWriteMany
  storageClassName: alicloud-cpfs
  resources:
    requests:
      storage: 20Gi
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: deployment-cpfs
  labels:
    app: nginx
spec:
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx:1.7.9
        ports:
        - containerPort: 80
        volumeMounts:
          - name: cpfs-pvc
            mountPath: "/data"
      volumes:
        - name: cpfs-pvc
          persistentVolumeClaim:
            claimName: cpfs-pvc

Create pvc and deployment:

$ kubectl create -f deploy.yaml

$ kubectl get po
NAME                               READY   STATUS    RESTARTS   AGE
deployment-cpfs-7f6977f9f6-s8wdx   1/1     Running   0          25s

At this point, we have successfully created a subdirectory in the CPFS file system and mounted it to the application deployment-cpfs.

If you need to mount different subdirectories of the same CPFS file system for different Pod s, just create cpfs-pvc-01 and cpfs-pvc-02 and their corresponding application orchestrations, respectively.

4. Use CPFS static storage volumes

Unlike CPFS dynamic storage volumes, CPFS static storage volumes require manual PV resource orchestration and can customize subpath paths. Examples of orchestration files are as follows:

apiVersion: v1
kind: PersistentVolume
metadata:
  name: cpfs-csi-pv
  labels:
    alicloud-pvname: cpfs-pv
spec:
  capacity:
    storage: 5Gi
  accessModes:
    - ReadWriteOnce
  persistentVolumeReclaimPolicy: Retain
  csi:
    driver: cpfsplugin.csi.alibabacloud.com
    volumeHandle: cpfs-csi-pv
    volumeAttributes:
      server: "xxxxxx@tcp:xxxxxx@tcp"
      fileSystem: "xxxxxx"
      subPath: "/k8s"
---
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
  name: cpfs-pvc
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 5Gi
  selector:
    matchLabels:
      alicloud-pvname: cpfs-pv
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: deployment-cpfs
  labels:
    app: nginx
spec:
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx:1.7.9
        ports:
        - containerPort: 80
        volumeMounts:
          - name: cpfs-pvc
            mountPath: "/data"
      volumes:
        - name: cpfs-pvc
          persistentVolumeClaim:
            claimName: cpfs-pvc

5. Reference Documents

CPFS CSI Plugin
File Storage CPFS

Keywords: Web Server Nginx Kubernetes github

Added by ofi on Thu, 23 Jan 2020 09:49:55 +0200