All Products
Search
Document Center

Container Service for Kubernetes:Volumes

Last Updated:Jul 02, 2025

This topic describes how to mount volumes to workflow clusters and then use the volumes.

Usage notes

You can use Object Storage Service (OSS) volumes and File Storage NAS (NAS) volumes in workflow clusters.

Use OSS volumes

  1. Use the following sample code to create an OSS volume.

    For more information, see Mount a statically provisioned ossfs 1.0 volume. To create other types of volumes, replace the corresponding parameters.

    Click to view YAML content

    apiVersion: v1
    kind: Secret
    metadata:
      name: oss-secret
      namespace: default
    stringData:
      akId: <yourAccessKey ID> # Replace with your AccessKey ID. 
      akSecret: <yourAccessKey Secret> # Replace with your AccessKey secret. 
    ---
    apiVersion: v1
    kind: PersistentVolume
    metadata:
      name: pv-oss
      labels:
        alicloud-pvname: pv-oss
    spec:
      capacity:
        storage: 5Gi
      accessModes:
        - ReadWriteMany
      persistentVolumeReclaimPolicy: Retain
      csi:
        driver: ossplugin.csi.alibabacloud.com
        volumeHandle: pv-oss   # Specify the name of the persistent volume (PV). 
        nodePublishSecretRef:
          name: oss-secret
          namespace: default
        volumeAttributes:
          bucket: <your bucket name> # Replace with your bucket name. 
          url: "oss-<your region id>-internal.aliyuncs.com" # Replace <your region id> with the region ID of your OSS bucket. For example, if your OSS bucket is created in the China (Beijing) region, the region ID is oss-cn-beijing-internal.aliyuncs.com. 
          otherOpts: "-o umask=022 -o max_stat_cache_size=1000000 -o allow_other"
          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: default
    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, such as -o umask=022 -o max_stat_cache_size=1000000 -o allow_other.

    • umask: Modify the permission mask of files in OSSFS. For example, if you set 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 console is 640 in OSSFS. Therefore, we recommend that you use the umask command when you want to split reads and writes.

    • max_stat_cache_size: Specify the file metadata cache capacity to define the maximum number of file metadata cached. Default: 100,000 entries (~40MB memory).

      Metadata caching significantly accelerates file traversal and read operations. However, modifications made through alternative methods, such as OSS, SDK, console, and ossutil, may lead to outdated metadata. For strong data consistency requirements, set this value to 0 to disable metadata caching.

    • allow_other: Allow 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 supported by ossfs.

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

    Click to view YAML content

    apiVersion: argoproj.io/v1alpha1
    kind: Workflow
    metadata:
      generateName: volumes-existing-
      namespace: default
    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: docker/whalesay:latest
          command: [sh, -c]
          args: ["echo generating message in volume; cowsay hello world | tee /mnt/vol/hello_world.txt"]
          volumeMounts:
          - name: workdir
            mountPath: /mnt/vol
    
      - name: print-message
        container:
          image: 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:

    Click to view YAML content

    apiVersion: v1
    kind: PersistentVolume
    metadata:
      name: pv-nas
      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
    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.

    Click to view YAML content

    apiVersion: argoproj.io/v1alpha1
    kind: Workflow
    metadata:
      generateName: volumes-existing-
      namespace: default
    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: docker/whalesay:latest
          command: [sh, -c]
          args: ["echo generating message in volume; cowsay hello world | tee /mnt/vol/hello_world.txt"]
          volumeMounts:
          - name: workdir
            mountPath: /mnt/vol
    
      - name: print-message
        container:
          image: 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