All Products
Search
Document Center

Container Compute Service:Use volumes

Last Updated:Dec 27, 2024

If the steps in a workflow need to share data or status, you can mount a volume to the workflow. You can mount OSS and NAS volumes to workflows. This topic describes how to mount a statically provisioned volume to a workflow.

Usage notes

OSS volumes and NAS volumes are used in different scenarios. For more information about the usage notes, limits, and billing of different types of volumes, see Storage overview.

Examples

Use OSS volumes

  1. Create an OSS volume based on the following sample code.

    For more information, see Mount a statically provisioned OSS volume.

    apiVersion: v1
    kind: Secret
    metadata:
      name: oss-secret
      namespace: argo
    stringData:
      akId: <yourAccessKey ID> # Replace with the actual AccessKey ID. 
      akSecret: <yourAccessKey Secret> # Replace with the actual AccessKey secret. 
    ---
    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   # Replace with the actual PV name. 
        nodePublishSecretRef:
          name: oss-secret
          namespace: argo
        volumeAttributes:
          bucket: <your bucket name> # Replace with the actual OSS bucket name. 
          url: "oss-<your region id>-internal.aliyuncs.com" # Replace <your region id> with the region ID of the OSS bucket, such as oss-cn-beijing-internal.aliyuncs.com for China (Beijing). 
          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: "/"  # The root directory of the OSS bucket. You can also specify a subdirectory of the OSS bucket. Example: 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

    Optional parameters

    You can configure custom parameters in the -o *** -o *** format for the OSS volume. Example: -o umask=022 -o max_stat_cache_size=0 -o allow_other.

    Parameter

    Description

    umask

    Modifies the permission mask of files in ossfs. For example, if you specify umask=022, the permission mask of files in ossfs changes to 755. By default, the permission mask of files uploaded by using the OSS SDK or the OSS console is 640 in ossfs. Therefore, we recommend that you specify the umask parameter if you want to split reads and writes.

    max_stat_cache_size

    The maximum number of files whose metadata can be stored in metadata caches. Metadata caching can accelerate List operations. However, if you modify files by using methods other than ossfs, such as the OSS console, OSS SDKs, or ossutil, the cached metadata of the files is not synchronously updated. As a result, the cached metadata becomes outdated, and the results of LIST operations may be inaccurate.

    allow_other

    Allows other users to access the mounted directory. However, these users cannot access the files in the directory.

    For more information about other parameters, see Options.

  2. Use the following sample code to create a workflow to use the OSS volume:

    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

Use NAS volumes

  1. Use the following sample code to create a statically provisioned NAS volume:

    For more information, see Mount a statically provisioned NAS volume.

    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   # Specify the name of the PV. 
        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
  2. Use the following sample code to create a workflow to use the NAS volume.

    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