如果工作流程的多個步驟之間需要共用資料或狀態,您可以在叢集中掛載儲存卷。目前支援OSS儲存卷、NAS儲存卷。本文結合樣本介紹如何建立靜態儲存卷,並指定樣本工作流程使用該儲存卷。
使用說明
OSS儲存卷、NAS儲存卷的側重的使用情境不同。下方建議供您參考。
儲存卷 | 使用情境 |
OSS儲存卷 |
|
NAS儲存卷 |
更多資訊,請參見NAS儲存卷。 |
CPFS儲存卷 |
更多資訊,請參見使用CPFS通用版靜態儲存卷和管理CPFS通用版動態儲存裝置卷。 |
在不同儲存卷有對應的使用限制和說明,也會產生對應的資源費用,請參見以下文檔瞭解詳情。
OSS儲存卷:OSS儲存卷、使用ossfs 1.0靜態儲存卷
NAS儲存卷:NAS儲存卷、使用NAS靜態儲存卷
CPFS儲存卷:CPFS通用版儲存卷、使用CPFS通用版靜態儲存卷
使用OSS儲存卷
使用以下範例程式碼,建立OSS儲存卷。
更多資訊,請參見使用ossfs 1.0靜態儲存卷。
apiVersion: v1 kind: Secret metadata: name: oss-secret namespace: argo stringData: akId: <yourAccessKey ID> # 替換為實際的AccessKeyID。 akSecret: <yourAccessKey Secret> # 替換為實際的AccessKeySecret。 --- apiVersion: v1 kind: PersistentVolume metadata: name: pv-oss namespace: argo labels: alicloud-pvname: pv-oss spec: capacity: storage: 5Gi accessModes: - ReadWriteMany persistentVolumeReclaimPolicy: Retain csi: driver: ossplugin.csi.alibabacloud.com volumeHandle: pv-oss # 與PV名字保持一致。 nodePublishSecretRef: name: oss-secret namespace: argo volumeAttributes: bucket: <your bucket name> # 替換為實際的Bucket名稱。 url: "oss-<your region id>-internal.aliyuncs.com" # 替換<your region id>為OSS的地區ID,例如華北2(北京)地區為oss-cn-beijing-internal.aliyuncs.com。 otherOpts: "-o max_stat_cache_size=0 -o allow_other -o multipart_size=30 -o parallel_count=20" # -o max_stat_cache_size=0 path: "/" #掛載Bucket根目錄,也可以設定此參數掛載Bucket下子目錄,例如path: "testdir/testdir1"。 --- apiVersion: v1 kind: PersistentVolumeClaim metadata: name: pvc-oss namespace: argo spec: accessModes: - ReadWriteMany resources: requests: storage: 5Gi selector: matchLabels: alicloud-pvname: pv-oss選擇性參數
您可以為OSS儲存卷輸入定製化參數,格式為
-o *** -o ***,例如-o umask=022 -o max_stat_cache_size=0 -o allow_other。參數
說明
umask
用於更改ossfs讀檔案的許可權。例如,設定
umask=022後,ossfs檔案的許可權都會變更為755。通過SDK、OSS控制台等其他方式上傳的檔案在ossfs中預設許可權均為640。因此,建議您在讀寫分離情境中配置umask許可權。max_stat_cache_size
用於指定檔案中繼資料的緩衝空間,可緩衝多少個檔案的中繼資料。中繼資料快取可加快ls操作速度。但若通過其他例如OSS、SDK、控制台、ossutil等方式修改檔案,可能會導致中繼資料未被及時更新。
allow_other
賦予電腦上其他使用者訪問掛載目錄的許可權,但不包含目錄內的檔案。
更多選擇性參數,請參見選項列表。
使用以下範例程式碼,建立執行個體工作流程,使用儲存卷。
apiVersion: argoproj.io/v1alpha1 kind: Workflow metadata: generateName: volumes-existing- namespace: argo spec: entrypoint: volumes-existing-example volumes: # Pass my-existing-volume as an argument to the volumes-existing-example template. # Same syntax as k8s Pod spec. - name: workdir persistentVolumeClaim: claimName: pvc-oss templates: - name: volumes-existing-example steps: - - name: generate template: whalesay - - name: print template: print-message - name: whalesay container: image: mirrors-ssl.aliyuncs.com/busybox:latest command: [sh, -c] args: ["echo generating message in volume; echo hello world | tee /mnt/vol/hello_world.txt"] volumeMounts: - name: workdir mountPath: /mnt/vol - name: print-message container: image: mirrors-ssl.aliyuncs.com/alpine:latest command: [sh, -c] args: ["echo getting message from volume; find /mnt/vol; cat /mnt/vol/hello_world.txt"] volumeMounts: - name: workdir mountPath: /mnt/vol
使用NAS儲存卷
使用以下範例程式碼,建立NAS共用儲存卷。
更多資訊,請參見使用NAS靜態儲存卷。
apiVersion: v1 kind: PersistentVolume metadata: name: pv-nas namespace: argo labels: alicloud-pvname: pv-nas spec: capacity: storage: 100Gi accessModes: - ReadWriteMany csi: driver: nasplugin.csi.alibabacloud.com volumeHandle: pv-nas # 必須與PV Name保持一致。 volumeAttributes: server: "<your nas filesystem id>.cn-beijing.nas.aliyuncs.com" path: "/" mountOptions: - nolock,tcp,noresvport - vers=3 --- kind: PersistentVolumeClaim apiVersion: v1 metadata: name: pvc-nas namespace: argo spec: accessModes: - ReadWriteMany resources: requests: storage: 100Gi selector: matchLabels: alicloud-pvname: pv-nas使用以下範例程式碼,在工作流程中掛載和使用NAS。
apiVersion: argoproj.io/v1alpha1 kind: Workflow metadata: generateName: volumes-existing- namespace: argo spec: entrypoint: volumes-existing-example volumes: # Pass my-existing-volume as an argument to the volumes-existing-example template. # Same syntax as k8s Pod spec. - name: workdir persistentVolumeClaim: claimName: pvc-nas templates: - name: volumes-existing-example steps: - - name: generate template: whalesay - - name: print template: print-message - name: whalesay container: image: mirrors-ssl.aliyuncs.com/busybox:latest command: [sh, -c] args: ["echo generating message in volume; echo hello world | tee /mnt/vol/hello_world.txt"] volumeMounts: - name: workdir mountPath: /mnt/vol - name: print-message container: image: mirrors-ssl.aliyuncs.com/alpine:latest command: [sh, -c] args: ["echo getting message from volume; find /mnt/vol; cat /mnt/vol/hello_world.txt"] volumeMounts: - name: workdir mountPath: /mnt/vol
使用CPFS2.0儲存卷
執行以下命令,建立CPFS2.0共用卷。
更多資訊,請參見使用CPFS通用版靜態儲存卷。
cat << EOF | kubectl apply -f - apiVersion: v1 kind: PersistentVolume metadata: name: pv-cpfs namespace: argo labels: alicloud-pvname: pv-cpfs spec: accessModes: - ReadWriteOnce capacity: storage: 1000Gi csi: driver: nasplugin.csi.alibabacloud.com volumeAttributes: mountProtocol: cpfs-nfs # 掛載時,使用NFS協議進行掛載。 path: "/share" # 掛載目錄必須以/share為首碼。 volumeAs: subpath server: "<your cpfs id, e.g cpfs-****>.<regionID>.cpfs.aliyuncs.com" # 為掛載點前面的網域名稱。 volumeHandle: pv-cpfs # 必須與PV Name保持一致。 mountOptions: - rsize=1048576,wsize=1048576,hard,timeo=600,retrans=2,noresvport - vers=3 --- apiVersion: v1 kind: PersistentVolumeClaim metadata: name: pvc-cpfs namespace: argo spec: accessModes: - ReadWriteOnce resources: requests: storage: 1000Gi selector: matchLabels: alicloud-pvname: pv-cpfs EOF使用以下範例程式碼,在工作流程中掛載和使用CPFS2.0。
apiVersion: argoproj.io/v1alpha1 kind: Workflow metadata: generateName: volumes-existing- namespace: argo spec: entrypoint: volumes-existing-example volumes: # Pass my-existing-volume as an argument to the volumes-existing-example template. # Same syntax as k8s Pod spec. - name: workdir persistentVolumeClaim: claimName: pvc-cpfs templates: - name: volumes-existing-example steps: - - name: generate template: whalesay - - name: print template: print-message - name: whalesay container: image: mirrors-ssl.aliyuncs.com/busybox:latest command: [sh, -c] args: ["echo generating message in volume; echo hello world | tee /mnt/vol/hello_world.txt"] volumeMounts: - name: workdir mountPath: /mnt/vol - name: print-message container: image: mirrors-ssl.aliyuncs.com/alpine:latest command: [sh, -c] args: ["echo getting message from volume; find /mnt/vol; cat /mnt/vol/hello_world.txt"] volumeMounts: - name: workdir mountPath: /mnt/vol