CPFS(Cloud Paralleled File System)是一种并行文件系统。CPFS的数据存储在集群中的多个数据节点,并可由多个客户端同时访问,从而能够为大型高性能计算机集群提供高IOPS、高吞吐、低时延的数据存储服务。本文演示如何挂载及使用CPFS1.0静态存储卷。

背景信息

阿里云容器服务ACK的CSI支持静态存储卷挂载和动态存储卷挂载两种方式挂载CPFS1.0存储卷。在静态存储卷挂载的方式中,通常需要手动编辑和创建一个PV和PVC进行挂载,当需要的PV和PVC数量很大的时候,手动创建就显得非常繁琐了,这时动态存储卷挂载的功能可以满足您的需求。本文演示如何在ACK集群中使用alibaba-cloud-csi-driver挂载CPFS1.0存储卷,请参见alibaba-cloud-csi-driver
注意 文件存储CPFS已全面升级CPFS2.0,容器服务ACK不再新增支持使用CPFS1.0存储卷。

操作步骤

  1. 部署CSI-CPFS组件。
    如果您需要挂载CPFS1.0存储卷,需要按照以下步骤在ACK集群中先部署cpfs-plugin组件。
    apiVersion: storage.k8s.io/v1
    kind: CSIDriver
    metadata:
      name: cpfsplugin.csi.alibabacloud.com
    spec:
      attachRequired: false
      podInfoOnMount: true
    ---
    # This YAML defines all API objects to create RBAC roles for csi node plugin.
    kind: DaemonSet
    apiVersion: apps/v1
    metadata:
      name: csi-cpfsplugin
      namespace: kube-system
    spec:
      selector:
        matchLabels:
          app: csi-cpfsplugin
      template:
        metadata:
          labels:
            app: csi-cpfsplugin
        spec:
          tolerations:
          - operator: Exists
          priorityClassName: system-node-critical
          serviceAccount: admin
          hostNetwork: true
          hostPID: true
          containers:
          - name: driver-registrar
            image: registry.cn-hangzhou.aliyuncs.com/acs/csi-node-driver-registrar:v1.2.0
            imagePullPolicy: Always
            args:
            - "--v=5"
            - "--csi-address=/var/lib/kubelet/csi-plugins/cpfsplugin.csi.alibabacloud.com/csi.sock"
            - "--kubelet-registration-path=/var/lib/kubelet/csi-plugins/cpfsplugin.csi.alibabacloud.com/csi.sock"
            volumeMounts:
            - name: kubelet-dir
              mountPath: /var/lib/kubelet/
            - name: registration-dir
              mountPath: /registration
          - name: csi-cpfsplugin
            securityContext:
              privileged: true
              capabilities:
                add: ["SYS_ADMIN"]
              allowPrivilegeEscalation: true
            image: registry.cn-hangzhou.aliyuncs.com/acs/csi-cpfsplugin:v1.20.4-3220e46-aliyun
            imagePullPolicy: "Always"
            args:
            - "--endpoint=$(CSI_ENDPOINT)"
            - "--v=5"
            - "--driver=cpfsplugin.csi.alibabacloud.com"
            env:
            - name: CSI_ENDPOINT
              value: unix://var/lib/kubelet/csi-plugins/cpfsplugin.csi.alibabacloud.com/csi.sock
            volumeMounts:
            - name: kubelet-dir
              mountPath: /var/lib/kubelet/
              mountPropagation: "Bidirectional"
            - mountPath: /var/log/
              name: host-log
            - name: etc
              mountPath: /host/etc
          volumes:
          - name: kubelet-dir
            hostPath:
              path: /var/lib/kubelet/
              type: Directory
          - name: registration-dir
            hostPath:
              path: /var/lib/kubelet/plugins_registry
              type: DirectoryOrCreate
          - name: host-log
            hostPath:
              path: /var/log/
          - name: etc
            hostPath:
              path: /etc
      updateStrategy:
        type: RollingUpdate
    执行以下命令检查应用运行状态。
    kubectl get pod -nkube-system |grep cpfs

    预期输出:

    csi-cpfsplugin-8t585                               2/2     Running   0          4h43m
    csi-cpfsplugin-9z5xj                               2/2     Running   0          4h43m
    csi-cpfsplugin-bdm22                               2/2     Running   0          4h43m
    csi-cpfsplugin-bjnlx                               2/2     Running   0          4h44m
    csi-cpfsplugin-nv7vg                               2/2     Running   0          4h43m
    csi-cpfsplugin-zc7z5                               2/2     Running   0          4h43m
  2. 使用CPFS1.0存储卷。
    1. 创建CPFS文件系统。具体操作,请参见创建文件系统
    2. 创建PV和PVC。
      使用以下模板,创建CPFS类型的PV和PVC。
      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
    3. 创建应用。
      使用以下模板引用上述PVC创建应用。
      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