Updated on 2024-11-11 GMT+08:00

Creating a Deployment Mounted with an SFS Volume

Scenario

After an SFS volume is created or imported to CCE, you can mount the volume to a workload.

Prerequisites

You have created a CCE cluster and installed the CSI plug-in (everest) in the cluster.

Notes and Constraints

The following configuration example applies to clusters of Kubernetes 1.15 or later.

Procedure

  1. Use kubectl to connect to the cluster. For details, see Connecting to a Cluster Using kubectl.
  2. Run the following commands to configure the sfs-deployment-example.yaml file, which is used to create a pod.

    touch sfs-deployment-example.yaml

    vi sfs-deployment-example.yaml

    Example of mounting an SFS volume to a Deployment (PVC-based, shared volume):
    apiVersion: apps/v1 
    kind: Deployment 
    metadata: 
      name: sfs-deployment-example                                # Workload name
      namespace: default 
    spec: 
      replicas: 1 
      selector: 
        matchLabels: 
          app: sfs-deployment-example 
      template: 
        metadata: 
          labels: 
            app: sfs-deployment-example 
        spec: 
          containers: 
          - image: nginx 
            name: container-0 
            volumeMounts: 
            - mountPath: /tmp                                # Mount path 
              name: pvc-sfs-example 
          imagePullSecrets:
            - name: default-secret
          restartPolicy: Always 
          volumes: 
          - name: pvc-sfs-example 
            persistentVolumeClaim: 
              claimName: pvc-sfs-auto-example                # PVC name

    spec.template.spec.containers.volumeMounts.name and spec.template.spec.volumes.name must be consistent because they have a mapping relationship.

  3. Run the following command to create the workload:

    kubectl create -f sfs-deployment-example.yaml