Help Center> Cloud Container Instance (CCI)> Developer Guide> Using PersistentVolumeClaim to Apply for Persistent Storage

Using PersistentVolumeClaim to Apply for Persistent Storage

CCI supports the following persistent storage services in containers:

  • Elastic Volume Service (EVS) is a block storage service that provides three specifications: common I/O (SATA), high I/O (SAS), and ultra-high I/O (SSD).
  • Scalable File Service (SFS) provides shared file storage and supports the standard file protocol type (nfs-rw). SFS provides two types of file systems: SFS and SFS Turbo.
    • SFS is expandable to petabytes, and provides fully hosted shared file storage. It features high availability and durability, and seamlessly handles data-intensive and bandwidth-intensive applications. SFS is suitable for high-performance computing (HPC), media processing, file sharing, content management and web services.
    • SFS Turbo is expandable to 320 TB, and provides fully hosted shared file storage. It features high availability and durability, and supports massive quantities of small files and applications requiring low latency and high IOPS. SFS Turbo is suitable for high-performance websites, log storage, compression and decompression, DevOps, enterprise offices, and containerized applications.

    Currently, SFS Turbo volumes are unavailable in the CN East-Shanghai 1 region.

  • Object Storage Service (OBS) is an object-based storage service, and provides massive, secure, highly reliable, and low-cost data storage capabilities.

Among the three storage services, OBS is the most easy to use. CCI can use OBS as SDK. You can configure OBS usage when defining an application using an SDK, package the application into an image, and then use the image to deploy a workload on CCI. For details about how to download and use the OBS SDK, see https://developer.huaweicloud.com/en-us/sdk?OBS.

EVS and SFS need to be mounted before being used. The following describes how to use EVS and SFS.

PersistentVolumeClaim (PVC)

Kubernetes provides PVC to apply for persistent storage. The PVC allows you to specify the type and capacity of storage without concerning about how to create and release underlying storage resources.

In practice, you can associate a PVC with the volume in the pod and use the persistent storage through the PVC, as shown in Figure 1.

Figure 1 Using persistent storage

Creating a PVC

  • Creating a PVC to apply for a 100 GB SATA EVS disk
    To create an encrypted EVS volume, add the paas.storage.io/cryptKeyId field in metadata.annotations.
    apiVersion: v1
    kind: PersistentVolumeClaim
    metadata:
      name: pvc-evs
      namespace: namespaces-test
      annotations: {
      paas.storage.io/cryptKeyId: ee9b610c-e356-11e9-aadc-d0efc1b3bb6b
      }
    spec:
      accessModes:                  
      - ReadWriteMany
      resources:  
        requests:
          storage: 100Gi
      storageClassName: sata
    accessModes indicates the volume access modes. The following three modes are supported:
    • ReadWriteOnce: A volume can be mounted to a single node for reading and writing.
    • ReadOnlyMany: A volume can be mounted to multiple nodes for reading.
    • ReadWriteOnce: A volume can be mounted to multiple nodes for reading and writing.

    storageClassName indicates the applied storage class. Currently, the following four classes are supported:

    • sata: SATA (common I/O) EVS disk
    • sas: SAS (high I/O) EVS disk
    • ssd: SSD (ultra-high I/O) EVS disk
    • nfs-rw: SFS file storage of the standard file protocol
  • Creating a PVC to apply for a 100 GB file system

    To create an encrypted SFS volume, add the paas.storage.io/cryptKeyId, paas.storage.io/cryptAlias, and paas.storage.io/cryptDomainId fields in metadata.annotations.

    apiVersion: v1
    kind: PersistentVolumeClaim
    metadata:
      name: pvc-sfs
      namespace: namespace-test
      annotations: {
      paas.storage.io/cryptKeyId: ee9b610c-e356-11e9-aadc-d0efc1b3bb6b
      paas.storage.io/cryptAlias: sfs/default
      paas.storage.io/cryptDomainId: d6912480-c3d6-4e9e-8c70-38afeea434c3
      volume.beta.kubernetes.io/storage-provisioner: flexvolume-huawei.com/fuxinfs
      }
    spec:
      accessModes:                  
      - ReadWriteMany
      resources:  
        requests:
          storage: 100Gi
      storageClassName: nfs-rw

Using a PVC

After applying for storage resources using a PVC, you can use a volume in the pod to associate the PVC and mount the volume to containers.

The following example shows how to use a PVC in a pod. A volume named pvc-test-example is defined and mounted to the /tmp/volume0 directory of the container. In this way, the data written to /tmp is written to the PVC named pvc-test.

  • Writing data to the applied SATA EVS disk
    apiVersion: v1
    kind: Pod
    metadata:
      name: nginx
      labels:
        app: nginx
    spec:
      containers:
      - image: nginx:latest
        name: container-0
        resources:
          limits:
            cpu: 500m
            memory: 1024Mi
          requests:
            cpu: 500m
            memory: 1024Mi
        volumeMounts:                 
        - mountPath: "/tmp"           # Mount the PVC to the /tmp/volume0 directory of the container.
          name: pvc-test-example      # Volume name.
      volumes:                        # Define a volume, and associate it with the PVC.
      - name: pvc-test-example
        persistentVolumeClaim:
          claimName: pvc-test         # PVC name.
      imagePullSecrets:
      - name: imagepull-secret
  • Writing data to the applied file system (with storageClassName set to nfs-rw)
    When creating a PVC to apply for a file system (with storageClassName set to nfs-rw), you can set the mount subdirectory in volumeMounts, that is, a subdirectory in the root directory of the file system.
    apiVersion: v1
    kind: Pod
    metadata:
      name: nginx
      labels:
        app: nginx
    spec:
      containers:
      - image: nginx:latest
        name: container-0
        resources:
          limits:
            cpu: 500m
            memory: 1024Mi
          requests:
            cpu: 500m
            memory: 1024Mi
        volumeMounts:                 
        - mountPath: "/tmp"           # Mount the PVC to the /tmp/volume0 directory of the container.
          subPath: "abc"              # Subdirectory in the root directory of the file system. If the subdirectory does not exist, it is automatically created in the file system. The subdirectory must be a relative directory.
          name: pvc-test-example      # Volume name.
      volumes:                        # Define a volume, and associate it with the PVC.
      - name: pvc-test-example
        persistentVolumeClaim:
          claimName: pvc-test         # PVC name.
      imagePullSecrets:
      - name: imagepull-secret