Help Center/ Cloud Container Engine_Autopilot/ User Guide/ Storage/ Object Storage Service/ Using an Existing OBS Bucket Through a Static PV
Updated on 2024-12-18 GMT+08:00

Using an Existing OBS Bucket Through a Static PV

This section describes how to use an existing Object Storage Service (OBS) bucket to statically create PVs and PVCs and implement data persistence and sharing in workloads.

Prerequisites

If you want to create a cluster using commands, use kubectl to connect to the cluster. For details, see Connecting to a Cluster Using kubectl.

Constraints

  • If OBS volumes are used, the owner group and permission of the mount point cannot be modified.
  • Hard links are not supported when common buckets are mounted.
  • Multiple PVs can use the same OBS volume with the following restrictions:
    • Do not mount all PVCs/PVs that use the same underlying OBS volume to a pod. This will result in a pod startup failure because not all PVCs can be mounted to the pod due to the same volumeHandle values of these PVs.
    • The persistentVolumeReclaimPolicy parameter in the PVs should be set to Retain. If any other value is used, when a PV is deleted, the associated underlying volume may be deleted. In this case, other PVs associated with the underlying volume malfunction.
    • If underlying storage is repeatedly used, you are required to maintain data consistency. Enable isolation and protection for ReadWriteMany at the application layer and prevent multiple clients from writing the same file to prevent data overwriting and loss.

Using an Existing OBS Bucket on the Console

  1. Log in to the CCE console and click the cluster name to access the cluster console.
  2. Statically create a PVC and PV.

    1. In the navigation pane on the left, choose Storage. Then click the PVCs tab. In the upper right corner, click Create PVC. In the displayed dialog box, configure the parameters.

      Parameter

      Description

      PVC Type

      In this example, select OBS.

      OBS Endpoint

      To access OBS in a CCE Autopilot cluster, you need to create an OBS endpoint.

      PVC Name

      Enter the PVC name, which must be unique in the same namespace.

      Creation Method

      • If underlying storage is available, create a storage volume or use an existing storage volume to statically create a PVC based on whether a PV is available.
      • If no underlying storage is available, select Dynamically provision. For details, see Using an OBS Bucket Through a Dynamic PV.

      In this example, select Create new to create a PV and PVC at the same time on the console.

      PVa

      Select an existing PV in the cluster. Create a PV in advance. For details, see "Creating a storage volume" in Related Operations.

      You do not need to specify this parameter in this example.

      OBSb

      Click Select OBS. In the dialog box displayed, select the OBS storage that meets your requirements and click OK.

      PV Nameb

      Enter the PV name, which must be unique in the same cluster.

      Access Modeb

      OBS volumes support only ReadWriteMany, indicating that a storage volume can be mounted to multiple nodes in read/write mode. For details, see Volume Access Modes.

      Reclaim Policyb

      You can select Delete or Retain to specify the reclaim policy of the underlying storage when the PVC is deleted. For details, see PV Reclaim Policy.

      NOTE:

      If multiple PVs use the same OBS volume, use Retain to avoid cascading deletion of underlying volumes.

      Access Key (AK/SK)b

      Custom: Customize a secret if you want to assign different user permissions to different OBS storage devices. For details, see Using a Custom Access Key (AK/SK) to Mount an OBS Volume.

      Only secrets with the secret.kubernetes.io/used-by = csi label can be selected. The secret type is cfe/secure-opaque. If no secret is available, click Create Secret to create one.
      • Name: Enter a secret name.
      • Namespace: Select the namespace where the secret is located.
      • Access Key (AK/SK): Upload a key file in .csv format. For details, see Obtaining an Access Key.

      Mount Optionsb

      Enter the mounting parameter key-value pairs. For details, see Configuring OBS Mount Options.

      a: The parameter is available when Creation Method is set to Use existing.

      b: The parameter is available when Creation Method is set to Create new.

    2. Click Create to create a PVC and a PV.

      In the navigation pane on the left, choose Storage. View the created PVC and PV on the PVCs and PVs tabs, respectively.

  3. Create a workload.

    1. In the navigation pane on the left, choose Workloads. Then click the Deployments tab.
    2. In the upper right corner, click Create Workload. On the displayed page, click Data Storage in the Container Settings area and click Add Volume to select PVC.
      Mount and use storage volumes, as shown in Table 1. For details about other parameters, see Creating a Workload.
      Table 1 Mounting a storage volume

      Parameter

      Description

      PVC

      Select an existing object storage volume.

      Mount Path

      Enter a mount path, for example, /tmp.

      This parameter indicates the container path that the volume will be mounted to. Do not mount the volume to a system directory such as / or /var/run. This may cause container errors. Mount the volume to an empty directory. If the directory is not empty, ensure that there are no files that affect container startup. If there are such files, they will be replaced, which will lead to a container startup or workload creation failure.
      NOTICE:

      If a volume is mounted to a high-risk directory, use an account with minimum permissions to start the container, or high-risk files on the host may be damaged.

      Subpath

      Enter the subpath of the storage volume and mount a path in the storage volume to the container. In this way, different folders of the same storage volume can be used in a single pod. tmp, for example, indicates that data in the mount path of the container is stored in the tmp directory of the storage volume. If this parameter is left blank, the root path is used by default.

      Permission

      • Read-only: You can only read the data in the mounted volume.
      • Read-write: You can modify the volume mounted to the path. Newly written data will not be migrated if the container is migrated, which may cause data loss.

      In this example, the volume is mounted to the /data path of the container. The container data generated in this path is stored in the OBS volume.

    3. Configure other parameters and click Create Workload.

      After the workload is created, the data in the container mount directory will be persistently stored. Verify the storage by referring to Verifying Data Persistence and Sharing.

(kubectl) Using an Existing OBS Bucket

  1. Use kubectl to connect to the cluster.
  2. Create a PV.

    1. Create the pv-obs.yaml file.
      apiVersion: v1
      kind: PersistentVolume
      metadata:
        annotations:
          pv.kubernetes.io/provisioned-by: everest-csi-provisioner
          everest.io/reclaim-policy: retain-volume-only      # (Optional) The PV is deleted while the underlying volume is retained.
        name: pv-obs       # PV name.
      spec:
        accessModes:
        - ReadWriteMany    # Access mode. The value must be ReadWriteMany for OBS.
        capacity:
          storage: 1Gi     # OBS volume capacity.
        csi:
          driver: obs.csi.everest.io        # Dependent storage driver for the mounting.
          fsType: obsfs                     # Instance type.
          volumeHandle: <your_volume_id>    # Name of the OBS volume.
          volumeAttributes:
            storage.kubernetes.io/csiProvisionerIdentity: everest-csi-provisioner
            everest.io/obs-volume-type: STANDARD
            everest.io/region: <your_region>                        # Region where the OBS volume is located.
          nodePublishSecretRef:            # Custom secret of the OBS volume.
            name: <your_secret_name>       # Custom secret name.
            namespace: <your_namespace>    # Namespace of the custom secret.
        persistentVolumeReclaimPolicy: Retain    # Reclaim policy.
        storageClassName: csi-obs               # Storage class name.
        mountOptions: []                         # Mount options.
      Table 2 Key parameters

      Parameter

      Mandatory

      Description

      everest.io/reclaim-policy: retain-volume-only

      No

      Optional.

      Currently, only retain-volume-only is supported.

      If the reclaim policy is Delete and the value is retain-volume-only, the associated PV is deleted while the underlying storage volume is retained, when a PVC is deleted.

      fsType

      Yes

      Instance type. The value can be obsfs or s3fs.

      • obsfs: Parallel file system, which is mounted using obsfs.
      • s3fs: Object bucket, which is mounted using s3fs.

      volumeHandle

      Yes

      OBS volume name.

      everest.io/obs-volume-type

      Yes

      OBS storage class.

      • If fsType is set to s3fs, STANDARD (standard bucket) and WARM (infrequent access bucket) are supported.
      • This parameter is invalid when fsType is set to obsfs.

      everest.io/region

      Yes

      Region where the OBS bucket is deployed.

      For details, see Regions and Endpoints.

      nodePublishSecretRef

      No

      Access key (AK/SK) used for mounting the OBS volume. You can use the AK/SK to create a secret and mount it to the PV. For details, see Using a Custom Access Key (AK/SK) to Mount an OBS Volume.

      An example is as follows:
      nodePublishSecretRef:
        name: secret-demo
        namespace: default

      mountOptions

      No

      Mount options. For details, see Configuring OBS Mount Options.

      persistentVolumeReclaimPolicy

      Yes

      The Delete and Retain reclaim policies are supported. For details, see PV Reclaim Policy. If multiple PVs use the same OBS volume, use Retain to avoid cascading deletion of underlying volumes.

      Delete:

      • If everest.io/reclaim-policy is not specified, both the PV and OBS bucket will be deleted when a PVC is deleted.
      • If everest.io/reclaim-policy is set to retain-volume-only, when a PVC is deleted, the PV will be deleted but the OBS bucket will be retained.

      Retain: When a PVC is deleted, the PV and underlying storage resources are not deleted. Instead, you must manually delete these resources. After that, the PV is in the Released state and cannot be bound to a PVC again.

      storage

      Yes

      Storage capacity, in Gi.

      For OBS, this field is used only for verification (cannot be empty or 0). Its value is fixed at 1, and any value you set does not take effect for OBS.

      storageClassName

      Yes

      The StorageClass for OBS volumes is csi-obs.

    2. Run the following command to create a PV:
      kubectl apply -f pv-obs.yaml

  3. Create a PVC.

    1. Create the pvc-obs.yaml file.
      apiVersion: v1
      kind: PersistentVolumeClaim
      metadata:
        name: pvc-obs
        namespace: default
        annotations:
          volume.beta.kubernetes.io/storage-provisioner: everest-csi-provisioner
          everest.io/obs-volume-type: STANDARD
          csi.storage.k8s.io/fstype: obsfs
          csi.storage.k8s.io/node-publish-secret-name: <your_secret_name>  # Custom secret name.
          csi.storage.k8s.io/node-publish-secret-namespace: <your_namespace>        # Namespace of the custom secret.
      spec:
        accessModes:
        - ReadWriteMany                  # The value must be ReadWriteMany for OBS.
        resources:
          requests:
            storage: 1Gi
        storageClassName: csi-obs       # Storage class name, which must be the same as that of the PV.
        volumeName: pv-obs    # PV name.
      Table 3 Key parameters

      Parameter

      Mandatory

      Description

      csi.storage.k8s.io/node-publish-secret-name

      No

      Name of the custom secret specified in the PV.

      csi.storage.k8s.io/node-publish-secret-namespace

      No

      Namespace of the custom secret specified in the PV.

      storage

      Yes

      Requested capacity in the PVC, in Gi.

      For OBS, this field is used only for verification (cannot be empty or 0). Its value is fixed at 1, and any value you set does not take effect for OBS.

      storageClassName

      Yes

      Storage class name, which must be the same as the storage class of the PV in 2.a.

      The StorageClass for OBS volumes is csi-obs.

      volumeName

      Yes

      PV name, which must be the same as the PV name in 2.a.

    2. Run the following command to create a PVC:
      kubectl apply -f pvc-obs.yaml

  4. Create a workload.

    1. Create a file named web-demo.yaml. In this example, the OBS volume is mounted to the /data path.
      apiVersion: apps/v1
      kind: Deployment
      metadata:
        name: web-demo
        namespace: default
      spec:
        replicas: 2
        selector:
          matchLabels:
            app: web-demo
        template:
          metadata:
            labels:
              app: web-demo
          spec:
            containers:
            - name: container-1
              image: nginx:latest
              volumeMounts:
              - name: pvc-obs-volume    # Volume name, which must be the same as the volume name in the volumes field.
                mountPath: /data  # Location where the storage volume is mounted.
            imagePullSecrets:
              - name: default-secret
            volumes:
              - name: pvc-obs-volume    # Custom volume name
                persistentVolumeClaim:
                  claimName: pvc-obs    # Name of the created PVC.
    2. Run the following command to create a workload that the OBS volume is mounted to:
      kubectl apply -f web-demo.yaml

      After the workload is created, you can try Verifying Data Persistence and Sharing.

Verifying Data Persistence and Sharing

  1. View the deployed application and files.

    1. Run the following command to view the created pod:
      kubectl get pod | grep web-demo
      Expected output:
      web-demo-846b489584-mjhm9   1/1     Running   0             46s
      web-demo-846b489584-wvv5s   1/1     Running   0             46s
    2. Run the following commands in sequence to view the files in the /data path of the pods:
      kubectl exec web-demo-846b489584-mjhm9 -- ls /data
      kubectl exec web-demo-846b489584-wvv5s -- ls /data

      If no result is returned for both pods, no file exists in the /data path.

  2. Run the following command to create a file named static in the /data path:

    kubectl exec web-demo-846b489584-mjhm9 --  touch /data/static

  3. Run the following command to check the files in the /data path:

    kubectl exec web-demo-846b489584-mjhm9 -- ls /data

    Expected output:

    static

  4. Verify data persistence.

    1. Run the following command to delete the pod named web-demo-846b489584-mjhm9:
      kubectl delete pod web-demo-846b489584-mjhm9

      Expected output:

      pod "web-demo-846b489584-mjhm9" deleted

      After the deletion, the Deployment controller automatically creates a replica.

    2. Run the following command to view the created pod:
      kubectl get pod | grep web-demo
      The expected output is as follows, in which web-demo-846b489584-d4d4j is the newly created pod:
      web-demo-846b489584-d4d4j   1/1     Running   0             110s
      web-demo-846b489584-wvv5s    1/1     Running   0             7m50s
    3. Run the following command to check whether the files in the /data path of the new pod have been modified:
      kubectl exec web-demo-846b489584-d4d4j -- ls /data

      Expected output:

      static

      The static file is retained, indicating that the data in the file system can be stored persistently.

  5. Verify data sharing.

    1. Run the following command to view the created pod:
      kubectl get pod | grep web-demo
      Expected output:
      web-demo-846b489584-d4d4j   1/1     Running   0             7m
      web-demo-846b489584-wvv5s   1/1     Running   0             13m
    2. Run the following command to create a file named share in the /data path of either pod: In this example, select the pod named web-demo-846b489584-d4d4j.
      kubectl exec web-demo-846b489584-d4d4j --  touch /data/share
      Check the files in the /data path of the pod.
      kubectl exec web-demo-846b489584-d4d4j -- ls /data

      Expected output:

      share
      static
    3. Check whether the share file exists in the /data path of another pod (web-demo-846b489584-wvv5s) as well to verify data sharing.
      kubectl exec web-demo-846b489584-wvv5s -- ls /data

      Expected output:

      share
      static

      After you create a file in the /data path of a pod, if the file is also created in the /data path of the other pod, the two pods share the same volume.

Related Operations

You can also perform the operations described in Table 4.
Table 4 Related operations

Operation

Description

Procedure

Creating a storage volume (PV)

You can create a PV on the CCE console.

  1. In the navigation pane on the left, choose Storage. Then click the PVs tab. In the upper right corner, click Create PersistentVolume. In the displayed dialog box, configure the parameters.
    • Volume Type: Select OBS.
    • OBS: Click Select OBS. In the dialog box displayed, select the OBS storage that meets your requirements and click OK.
    • PV Name: Enter the PV name, which must be unique in the same cluster.
    • Access Mode: Only ReadWriteMany is available. A storage volume can be mounted to multiple nodes in read/write mode. For details, see Volume Access Modes.
    • Reclaim Policy: There are two options: Retain and Delete. For details, see PV Reclaim Policy
      NOTE:

      If multiple PVs use the same underlying storage volume, use Retain to avoid cascading deletion of underlying volumes.

    • Access Key (AK/SK): Customize a secret if you want to assign different user permissions to different OBS storage devices. For details, see Using a Custom Access Key (AK/SK) to Mount an OBS Volume.

      Only secrets with the secret.kubernetes.io/used-by = csi label can be selected. The secret type is cfe/secure-opaque. If no secret is available, click Create Secret to create one.

    • Mount Options: Enter the mounting parameter key-value pairs. For details, see Configuring OBS Mount Options.
  2. Click Create.

Updating an access key

You can update the access key of object storage on the CCE console.

  1. In the navigation pane on the left, choose Storage. Then click the PVCs tab. Click More in the Operation column of the target PVC and select Update Access Key.
  2. Upload a key file in .csv format. For details, see Obtaining an Access Key. Click OK.

Viewing events

You can view event names, event types, number of occurrences, Kubernetes events, first occurrence time, and last occurrence time of the PVC or PV.

  1. In the navigation pane on the left, choose Storage. Then click the PVCs or PVs tab.
  2. Click View Events in the Operation column of the target PVC or PV to view events generated within one hour (events are retained for one hour).

Viewing a YAML file

You can view, copy, and download the YAML files of a PVC or PV.

  1. In the navigation pane on the left, choose Storage. Then click the PVCs or PVs tab.
  2. Click View YAML in the Operation column of the target PVC or PV to view or download the YAML.