• Cloud Container Engine

cce
  1. Help Center
  2. Cloud Container Engine
  3. API Reference
  4. Appendix
  5. Using kubectl to Interconnecting PV with EVS

Using kubectl to Interconnecting PV with EVS

Prerequisites

kubectl has successfully interconnected with the container cluster. For detailed operations, see Using kubectl to Access a Container Cluster.

Procedure

  1. Create an EVS.

    For detailed operations, see Help Center > Elastic Volume Service > API Reference > Elastic Volume Service > Creating an EVS Disk on the management console.

    The EVS must be in the same AZ as the nodes of the CCE container cluster.

  2. Run the following command to configure the evs-pv.yaml file, which is used to create a PV.

    touch evs-pv.yaml

    vim evs-pv.yaml

    Example configurations:

    kind: PersistentVolume 
    apiVersion: v1 
    metadata: 
      labels: 
        app: test 
      name: evs-pv 
    spec: 
      accessModes: 
      - ReadWriteMany 
      capacity: 
        storage: 1Gi 
      hwsElasticVolumeService: 
        volumeID: 4ceaf953-99b1-49cb-993e-25f0033ad44f 
        fsType: ext4 
      persistentVolumeReclaimPolicy: Recycle

    In the configuration information:

    • AccessModes: After the EVS is created, the value of this parameter must be ReadWriteMany.
    • VolumeID: This parameter is set to the disk ID of the EVS created in 1.

  3. Run the ./kubectl create -f evs-pv.yaml command to create a PV.
  4. Run the following command to configure the evs-pvc.yaml file, which is used to create a PVC.

    touch evs-pvc.yaml

    vim evs-pvc.yaml

    Example configurations:

    kind: PersistentVolume 
    apiVersion: v1 
    kind: PersistentVolumeClaim 
    metadata: 
      labels: 
        app: test 
      name: evs-pvc 
      namespace: default 
    spec: 
      accessModes: 
      - ReadWriteMany 
      resources: 
        requests: 
          storage: 1Gi 

    accessModes must be set to ReadWriteMany.

  5. Run the ./kubectl create -f evs-pvc.yaml command to create a PVC.
  6. Run the following command to configure the evs-rc.yaml file, which is used to create an RC.

    touch evs-rc.yaml

    vim evs-rc.yaml

    Example configurations:

    kind: ReplicationController 
    apiVersion: v1 
    metadata: 
      name: evs-rc 
      labels: 
        app: test 
    spec: 
      replicas: 1 
      template: 
        metadata: 
          labels: 
            app: test 
        spec: 
          containers: 
          - name: pod-evs 
            image: nginx 
            volumeMounts: 
            - mountPath: "/usr/share/nginx/html" 
              name: mypd 
          volumes: 
            - name: mypd 
              persistentVolumeClaim: 
                claimName: pvc-evs 
          restartPolicy: Always 
          dnsPolicy: ClusterFirst

  7. Run the ./kubectl create -f evs-rc.yaml command to create an RC.
  8. Run the following command to query the IP address of the node where the pod resides and the pod IP address:

    ./kubectl get pod -o json |egrep 'hostIP|"name": "<evs-rc>|podIP'

    Replace <evs-rc> with the name of the RC created in 6.

  9. Add the following security rule to the node where the pod resides.

    Table 1 Security group rule to be added

    Protocol

    Transfer Direction

    Port Range

    Source IP Address

    TCP

    Inbound

    22

    0.0.0.0/0

    NOTE:

    For more information about security group rules, see Help Center > Virtual Private Cloud > User Guide > Security > Security Group on the management console.

  10. Log in as the linux user to the node where the pod resides by uploading the key file.
  11. Run the mount command to check whether the directory mounting status.

    If the information similar to the following is displayed, the directories are successfully mounted:

    /dev/xvdc on /mnt/paas/kubernetes/kubelet/plugins/kubernetes.io/evs/mounts/209fc26e-1a52-4611-9ba4-061360089152 type ext4 (rw,relatime,data=ordered)
    /dev/xvdc on /mnt/paas/kubernetes/kubelet/pods/b2e85fd5-8ba4-11e7-b213-fa163e8b66c4/volumes/kubernetes.io~evs/evs-pv type ext4 (rw,relatime,data=ordered)

  12. Run the following command to switch to the root user:

    su root

  13. Run the cd <file_name> command to go to either of the mount directories queried in 11.

    Replace <file_name> with the actual mount directory.

  14. Run the following commands to generate the index.html file:

    echo "test" > index.html

    chmod 644 index.html

  15. Exit the mount directory:
  16. Run the following command to access the application:

    curl 172.18.40.4:80

    172.18.40.4 is the pod IP address obtained in 8.

    The following information is displayed:

    test

    If you can successfully access the application, the PV has successfully interconnected with EVS.