All Documents
Current Document

Content is empty

If you don't find the content you expect, please try another search term

Documentation

Use EBS volumes

Last updated:2021-11-11 17:43:13

You can use EBS volumes in Kubernetes clusters of KCE. An EBS volume can be mounted to the specified path in a container as a static volume. If the container is migrated, the EBS volume is migrated with the container.

Kingsoft Cloud provides the following methods for you to mount EBS volumes to Kubernetes:

Static volume

Instructions

  1. An EBS volume does not support shared storage and can only be mounted to a single pod. The number of replicas must be set to 1.

  2. Before you use a static volume, you must create an EBS volume in the EBS console and obtain the volume ID.

  3. The volume name and PV name must be the same as the volume ID.

  4. An EBS volume can only be mounted to a cluster node in the same availability zone.

  5. File systems ext3, ext4, and xfs are supported.

  6. You can mount EBS volumes to the following types of KEC instances: General Purpose N1, General Purpose N2, I/O Optimized I2, and I/O Optimized I3. For more information, see Limits. If you select EBS volumes, we recommend that you schedule pods to the preceding types of KEC instances when you create Services. Otherwise, EBS volumes may fail to be mounted. For more information, see Assigning Pods to Nodes.

Directly use volumes

In the following nginx-disk-deploy.yaml file, the EBS volume specified in the YAML file is mounted to the /data path of the nginx-flexvolume-disk container in the pod.

apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-disk-deploy
spec:
  replicas: 1
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx-flexvolume-disk
        image: nginx
        volumeMounts:
          - name: "b5c80953-1499-40ff-918a-4d6d4dfbfddd"
            mountPath: "/data"
      volumes:
        - name: "b5c80953-1499-40ff-918a-4d6d4dfbfddd"
          flexVolume:
            driver: "ksc/ebs"
            fsType: "ext4"
            options:
              volumeId: "b5c80953-1499-40ff-918a-4d6d4dfbfddd"

Use PVs or PVCs

Define a PV:

apiVersion: v1
kind: PersistentVolume
metadata:
  name: "b5c80953-1499-40ff-918a-4d6d4dfbfddd"
spec:
  capacity:
    storage: 20Gi
  storageClassName: disk
  accessModes:
    - ReadWriteOnce
  flexVolume:
    driver: "ksc/ebs"
    fsType: "ext4"
    options:
      volumeId: "b5c80953-1499-40ff-918a-4d6d4dfbfddd"

Define a PVC:

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: pvc-disk
spec:
  accessModes:
    - ReadWriteOnce
  storageClassName: disk
  resources:
    requests:
      storage: 20Gi

Create a deployment:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-disk-deploy
spec:
  replicas: 1
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx-flexvolume-disk
        image: nginx
        volumeMounts:
        - name: pvc-disk
          mountPath: "/data"
      volumes:
      - name: pvc-disk
        persistentVolumeClaim:
          claimName: pvc-disk

Dynamic volume

You need to manually create a StorageClass for a dynamic volume and specify the StorageClass name in a PVC.

Create a StorageClass

apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
  name: ssd30
provisioner: ksc/ebs
parameters:
  type: SSD3.0
  zone: cn-beijing-6b # This parameter is optional. #
  chargetype: Daily

Parameter description:

  • provisioner: Set the value to ksc/ebs, indicating that the Kingsoft Cloud provisioner plug-in is used.
  • reclaimPolicy: the reclaim policy of the EBS volume. Default value: Delete. You can set this parameter to Retain to retain the EBS volume.
  • type: the type of the EBS volume. This parameter is required. Valid values: SSD2.0, SSD3.0, SATA2.0, and SATA3.0.
  • zone: the availability zone of the EBS volume. This parameter is optional. Note that the types of EBS volumes that can be created vary with the availability zones. For more information, see Limits. If the availability zone is not specified, the EBS volume is created in one of the availability zones where nodes in the cluster reside.
  • chargetype: the billing mode of the EBS volume. Default value: Daily. For more information, see the chargetype field in CreateVolume.
  • purchasetime: If you select the Subscription billing mode, you must set the purchase period, in months.

Create a deployment

apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx
spec:
  replicas: 1
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx
        volumeMounts:
        - name: pvc-disk
          mountPath: "/data"
      volumes:
      - name: pvc-disk
        persistentVolumeClaim:
          claimName: nginx-pvc
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: nginx-pvc
spec:
  accessModes:
    - ReadWriteOnce
  storageClassName: ssd30
  resources:
    requests:
      storage: 20Gi
On this page
Pure ModeNormal Mode

Pure Mode

Click to preview the document content in full screen
Feedback