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

(kubectl) Creating a Pod Mounted with an EVS Volume

Scenarios

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

EVS volumes cannot be mounted across AZs. Before mounting a volume, you can run the kubectl get pvc command to obtain the available PVCs in the AZ where the current cluster is located.

Notes and Constraints

The following configuration example applies to clusters of Kubernetes 1.13 or earlier.

Procedure

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

    touch evs-deployment-example.yaml

    vi evs-deployment-example.yaml

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

    Parent Parameter

    Parameter

    Description

    spec.template.spec.containers.volumeMounts

    name

    Name of the volume mounted to the container.

    spec.template.spec.containers.volumeMounts

    mountPath

    Mount path of the container. In this example, the volume is mounted to the /tmp directory.

    spec.template.spec.volumes

    name

    Name of the volume.

    spec.template.spec.volumes.persistentVolumeClaim

    claimName

    Name of an existing PVC.

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

    Mounting an EVS volume to a StatefulSet (PVC template-based, non-shared volume):

    Example YAML:
    apiVersion: apps/v1
    kind: StatefulSet
    metadata:
      name: deploy-evs-sas-in
    spec:
      replicas: 1
      selector:
        matchLabels:
          app: deploy-evs-sata-in
      template:
        metadata:
          labels:
            app: deploy-evs-sata-in
            failure-domain.beta.kubernetes.io/region: ap-southeast-1
            failure-domain.beta.kubernetes.io/zone: ap-southeast-1a
        spec:
          containers:
            - name: container-0
              image: 'nginx:1.12-alpine-perl'
              volumeMounts:
                - name: bs-sas-mountoptionpvc
                  mountPath: /tmp
          imagePullSecrets:
            - name: default-secret
      volumeClaimTemplates:
        - metadata:
            name: bs-sas-mountoptionpvc
            annotations:
              volume.beta.kubernetes.io/storage-class: sas
              volume.beta.kubernetes.io/storage-provisioner: flexvolume-huawei.com/fuxivol
          spec:
            accessModes:
              - ReadWriteOnce
            resources:
              requests:
                storage: 10Gi
      serviceName: wwww
    Table 2 Key parameters

    Parent Parameter

    Parameter

    Description

    metadata

    name

    Name of the created workload.

    spec.template.spec.containers

    image

    Image of the workload.

    spec.template.spec.containers.volumeMount

    mountPath

    Mount path of the container. In this example, the volume is mounted to the /tmp directory.

    spec

    serviceName

    Service corresponding to the workload. For details about how to create a Service, see Creating a StatefulSet.

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

  3. Run the following command to create the pod:

    kubectl create -f evs-deployment-example.yaml

    After the creation is complete, log in to the CCE console. In the navigation pane, choose Resource Management > Storage > EVS. Then, click the PVC name. On the PVC details page, you can view the binding relationship between the EVS volume and the PVC.