天天看點

如何在阿裡雲ACK叢集中使用CPFS存儲卷服務

介紹:

CPFS(Cloud Paralleled File System)是一種并行檔案系統。CPFS 的資料存儲在叢集中的多個資料節點,并可由多個用戶端同時通路,進而能夠為大型高性能計算機叢集提供高IOPS、高吞吐、低延遲時間的資料存儲服務。

CPFS詳細産品介紹參考:

https://help.aliyun.com/product/111536.html

CPFS是共享存儲服務類型,适合于容器服務場景對資源共享、高性能的要求,在大資料、AI、基因計算等高性能場景中使用容器服務 + CPFS是一個推薦的解決方案。

本文介紹如何在容器服務中安裝Flexvolume插件,并通過CPFS資料卷的方式為應用(Pod)提供CPFS服務。

CSI中如何使用CPFS服務請參考:

https://github.com/kubernetes-sigs/alibaba-cloud-csi-driver/blob/master/docs/cpfs.md

插件部署:

1. 限制:

容器服務中使用CPFS依賴兩個驅動類元件:CPFS容器驅動 和 CPFS用戶端驅動;

CPFS容器驅動:即為Flexvolume-cpfs插件,對centos各個版本都是相容的,部署Flexvolume-cpfs即可完成安裝;

CPFS用戶端驅動:為CPFS挂載時的用戶端(類似于nfs-client),驅動與作業系統核心是強依賴。容器場景中安裝CPFS用戶端驅動有幾種方案:

手動安裝驅動,參考 https://help.aliyun.com/document_detail/131060.html Flexvolume-cpfs部署時自動安裝驅動,但隻支援部分核心版本,

目前容器場景下支援在以下核心版本安裝CPFS用戶端驅動:

3.10.0-957.5.1
3.10.0-957.21.3
3.10.0-1062.9.1           

可以通過在節點上執行: uname -r 檢視核心版本。

目前Flexvolume隻支援安裝CPFS Client驅動,不支援cpfs-client驅動更新,即發現節點安裝了cpfs用戶端,不再繼續安裝驅動;

更新Flexvolume版本,隻會更新Flexvolume驅動(容器驅動),而不會更新cpfs-client版本;

在已經部署了cpfs-client、lustre驅動的節點上安裝cpfs flexvolume不會再安裝新版本的CPFS-Client;

Client更新需要手動進行,參考cpfs使用文檔(

https://help.aliyun.com/document_detail/131060.html)

2. 部署模闆:

在叢集中執行kubectl指令部署下面模闆:

# kubectl create -f flexvolume-cpfs.yaml
           
apiVersion: extensions/v1beta1
kind: DaemonSet
metadata:
  name: flexvolume-cpfs
  namespace: kube-system
  labels:
    k8s-volume: flexvolume-cpfs
spec:
  selector:
    matchLabels:
      name: acs-flexvolume-cpfs
  template:
    metadata:
      labels:
        name: acs-flexvolume-cpfs
    spec:
      hostPID: true
      hostNetwork: true
      tolerations:
      - operator: "Exists"
      priorityClassName: system-node-critical
      affinity:
        nodeAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
            nodeSelectorTerms:
            - matchExpressions:
              - key: type
                operator: NotIn
                values:
                - virtual-kubelet
      containers:
      - name: acs-flexvolume
        image: registry.cn-hangzhou.aliyuncs.com/acs/flexvolume:v1.14.8.71-22f141a-aliyun
        imagePullPolicy: Always
        securityContext:
          privileged: true
        env:
        - name: ACS_CPFS
          value: "true"
        - name: FIX_ISSUES
          value: "false"
        livenessProbe:
          exec:
            command:
            - sh
            - -c
            - ls /acs/flexvolume
          failureThreshold: 8
          initialDelaySeconds: 15
          periodSeconds: 10
          successThreshold: 1
          timeoutSeconds: 15
        volumeMounts:
        - name: usrdir
          mountPath: /host/usr/
        - name: etcdir
          mountPath: /host/etc/
        - name: logdir
          mountPath: /var/log/alicloud/
        - mountPath: /var/lib/kubelet
          mountPropagation: Bidirectional
          name: kubeletdir
      volumes:
      - name: usrdir
        hostPath:
          path: /usr/
      - name: etcdir
        hostPath:
          path: /etc/
      - name: logdir
        hostPath:
          path: /var/log/alicloud/
      - hostPath:
          path: /var/lib/kubelet
          type: Directory
        name: kubeletdir
  updateStrategy:
    type: RollingUpdate           

3. 檢查部署情況:

在叢集中檢視存儲插件的部署情況,示例如下:

# kubectl get pod -nkube-system | grep flex
flexvolume-97psk                                  1/1     Running   0          27m
flexvolume-cpfs-dgxfq                             1/1     Running   0          98s
flexvolume-cpfs-qpbcb                             1/1     Running   0          98s
flexvolume-cpfs-vlrf9                             1/1     Running   0          98s
flexvolume-cpfs-wklls                             1/1     Running   0          98s
flexvolume-cpfs-xtl9b                             1/1     Running   0          98s
flexvolume-j8zjr                                  1/1     Running   0          27m
flexvolume-pcg4l                                  1/1     Running   0          27m
flexvolume-tjxxn                                  1/1     Running   0          27m
flexvolume-x7ljw                                  1/1     Running   0          27m           

以flexvolume-cpfs 開頭的pod表示部署的cpfs存儲卷插件;

不含cpfs字樣的flexvolume pod表示:叢集預設部署的nas、雲盤、oss存儲卷插件,兩個插件可以同時部署;

在叢集的節點上檢視cpfs-client是否安裝完成:

# rpm -qa | grep cpfs
kmod-cpfs-client-2.10.8-202.el7.x86_64
cpfs-client-2.10.8-202.el7.x86_64           

檢視 mount.lustre 是否已經安裝:

# which mount.lustre
/usr/sbin/mount.lustre           

使用CPFS資料卷:

在ACK中使用CPFS資料卷,需要您先到CPFS控制台建立一個CPFS卷和挂載點,參考:

https://help.aliyun.com/document_detail/111860.html

建立CPFS挂載點時,選擇的vpc網絡需要和ACK叢集在同一個vpc内。

下面示例假設擷取挂載點為:

挂載點:cpfs-*-alup.cn-shenzhen.cpfs.nas.aliyuncs.com@tcp:cpfs--ws5v.cn-shenzhen.cpfs.nas.aliyuncs.com@tcp

檔案系統ID為:0237ef41

1. PV模闆:

apiVersion: v1
kind: PersistentVolume
metadata:
  name: pv-cpfs
  labels:
    alicloud-pvname: pv-cpfs
spec:
  capacity:
    storage: 5Gi
  accessModes:
    - ReadWriteMany
  flexVolume:
    driver: "alicloud/cpfs"
    options:
      server: "cpfs-****-alup.cn-shenzhen.cpfs.nas.aliyuncs.com@tcp:cpfs-***-ws5v.cn-shenzhen.cpfs.nas.aliyuncs.com@tcp"
      fileSystem: "0237ef41"
      subPath: "/k8s"
      options: "ro"           

其中:

server:配置為CPFS的挂載點;

fileSystem:配置為CPFS檔案系統ID;

subPath:配置為期望挂載的CPFS子目錄,相對于檔案系統根目錄;

options:可選,挂載配置選項;

2. PVC、應用模闆:

kind: PersistentVolumeClaim
apiVersion: v1
metadata:
  name: pvc-cpfs
spec:
  accessModes:
    - ReadWriteMany
  resources:
    requests:
      storage: 5Gi
  selector:
    matchLabels:
      alicloud-pvname: pv-cpfs
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: nas-cpfs
  labels:
    app: nginx
spec:
  replicas: 1
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx
        ports:
        - containerPort: 80
        volumeMounts:
          - name: pvc-cpfs
            mountPath: "/data"
      volumes:
        - name: pvc-cpfs
          persistentVolumeClaim:
            claimName: pvc-cpfs           

3. 建立應用:

建立上面模闆後檢查pod挂載情況:

# kubectl get pod
NAME                        READY   STATUS    RESTARTS   AGE
nas-cpfs-79964997f5-kzrtp   1/1     Running   0          45s

進入Pod檢視挂載目錄;
# kubectl exec -ti nas-cpfs-79964997f5-kzrtp sh
# mount | grep k8s
192.168.1.12@tcp:192.168.1.10@tcp:/0237ef41/k8s on /data type lustre (ro,lazystatfs)           
進入pod所在節點,檢視挂載目錄;
# mount | grep cpfs
192.168.1.12@tcp:192.168.1.10@tcp:/0237ef41/k8s on /var/lib/kubelet/pods/c4684de2-26ce-11ea-abbd-00163e12e203/volumes/alicloud~cpfs/pv-cpfs type lustre (ro,lazystatfs)           

繼續閱讀