You need to enable JavaScript to run this app.
Volcengine Kubernetes Engine

Volcengine Kubernetes Engine

Copy page
Download PDF
Local volumes
Using dynamic PersistentVolumes created from dedicated local storage
Copy page
Download PDF
Using dynamic PersistentVolumes created from dedicated local storage
Volcengine Kubernetes Engine (VKE) supports local storage through the Container Storage Interface (CSI). This topic describes how to use dynamic PersistentVolumes created from dedicated local storage.​
Description​
[Beta · Apply for trial] The csi-local add-on for local storage and storage-aware scheduling are currently in the beta stage. To use them, submit an application.​
Usage limits​
  • Use ESSD data volumes to mount to the container and image directories /var/lib/containerd and /var/lib/kubelet. Avoid mounting local disks to the container or image directory, as this mounting type is not applicable to local storage scenarios.​
  • The three add-ons required in this scenario must be installed or uninstalled in the order described in the following content. If this order is not followed, scheduling will malfunction.​
  • The Kubernetes version of the cluster must meet the following requirements:​
  • Local storage does not offer highly available volumes and is only applicable to temporary data storage or applications that internally implement high availability.​
Prerequisites​
  • A cluster that uses a compliant Kubernetes version has already been created. For details, see Creating clusters.​
Procedure​
Step 1: Install and set up dependent add-ons​
To use local storage, you need to install and set up the following add-ons in the order described below.​
danger​
  • The csi-local add-on depends on the snapshot-controller add-on. Before installing the csi-local add-on, confirm that the snapshot-controller add-on is installed.​
  • The csi-local add-on must be used with the storage-aware scheduling feature of the scheduler-plugin add-on. Before enabling the storage-aware scheduling feature, ensure that both the snapshot-controller and csi-local add-ons are installed. Otherwise, normal scheduling will be affected.​
  • Before you uninstall the csi-local add-on, disable the storage-aware scheduling feature in the scheduler-plugin add-on to avoid affecting scheduling capabilities.​
  1. Log in to the VKE console.​
  1. In the left navigation bar, click Cluster. On the page that appears, click the name of the cluster that you need to configure.​
  1. On the cluster management page, click Addons in the left navigation bar.​
  1. Click the Storage tab, move the pointer over the snapshot-controller add-on card, and then click Deploy to install the snapshot-controller add-on. Then, install the csi-local add-on in the same way.​
  1. Click the Scheduling tab, move the pointer over the scheduler-plugin add-on card, and then click Configuration. In the configuration dialog box, select Local storage for the Storage-aware scheduling parameter.​
  • ​
    Parameters​
    Description​
    Storage-aware scheduling​
    Local storage: This feature is disabled by default. Selecting the option enables storage-aware scheduling for local storage. After this feature is enabled, scheduling can be performed according to the storage resources available on each node.​
    tip​
    This feature takes effect only if the csi-local add-on is installed.​
    ​
Step 2: Configure node pools that use local disks​
Configure a node pool that uses a local disk. The following content describes the key configurations involved in this scenario. Specify other parameters based on your business requirements. For details, see Creating node pools and Creating managed node pools.​
  1. Specify the instance type. Select an ECS instance type that supports local disks. For details, see Local disks.​
  1. Configure a data volume.​
  • Specify container and image directories. Use ESSD data volumes to mount to the container and image directories /var/lib/containerd and /var/lib/kubelet.​
Warning​
Do not mount local disks to the container or image directory, as this mounting type is not applicable to local storage scenarios.​
  • Click Add data volume to configure other data volumes by using local disks. Local data volumes support SSD and HDD types. Different ECS types support different data volume types. You can select a local data volume type based on your business requirements.​
  1. Specify custom node labels, which are used to filter nodes during local disk initialization, such as csi-local: "i4ag".​
  1. Configure the InitializeScript to install lvm2 on the node. The installation command is apt-get install -y lvm2.​
Step 3: Initialize local disks​
After the csi-local add-on is installed, local storage-related CRDs will be automatically created, including​
  • NodeLocalStorageInitConfig: Initialize the NodeLocalStorage resources for each node. If NodeLocalStorageInitConfig exists when the csi-local add-on creates NodeLocalStorage resources, the configurations in NodeLocalStorageInitConfig will be populated into the spec of the created NodeLocalStorage resources.​
  • NodeLocalStorage: Report storage device information for each node. You can edit the Spec field of the NodeLocalStorage resource as needed.​
​​​
This example scenario uses an ecs.i4ag.12xlarge instance with an Elastic Block Storage (EBS) cloud disk mounted to /dev/vdc and the csi-local: "i4ag" label attached to the node.​
  1. In the left navigation bar, click Workload > Resource Explorer. On the page that appears, click Create with Yaml. On the Create with Yaml page, configure the CR to initialize the local disk.​
  • Select Custom from the Type drop-down list.​
  • Enter the following sample YAML configurations in the Yaml code editor.​
  • ​
    apiVersion: csi.volcengine.com/v1alpha1​
    kind: NodeLocalStorageInitConfig​
    metadata:​
    name: csi-local​
    spec:​
    globalConfig: # The global default node configuration.​
    listConfig:​
    devices: {}​
    mountPoints: {}​
    vgs: {}​
    resourceToBeInited: {}​
    spdkConfig: {}​
    nodesConfig: # The node pool-level configuration filtered by label.​
    - selector: # The filter rule.​
    matchLabels:​
    csi-local: "i4ag" # The label used for filtering nodes.​
    listConfig: # The list of storage devices that can be allocated by csi-local.​
    devices:​
    include: # The include regex.​
    - /dev/vdc # The data volume that can be allocated for exclusive use. Make sure that the data volume already exists on the ECS instance.​
    ​
  1. Wait for about one minute, and then run the following command to view the NodeLocalStorage configuration for the corresponding node. In this example, 192.168.2.6 is the IP address of the node.​
  • ​
    kubectl get nls 192.168.2.6 -oyaml​
    ​
  • The expected result is as follows: You can query the information about the dedicated disk, which indicates that the local disk has been initialized.​
  • ​
    apiVersion: csi.volcengine.com/v1alpha1​
    kind: NodeLocalStorage​
    metadata:​
    creationTimestamp: "2024-07-17T08:52:03Z"​
    generation: 1​
    name: 192.168.2.6​
    resourceVersion: "30819"​
    uid: 129012df-d9b2-41f1-bb5f-0d86fc15baf3​
    spec:​
    listConfig:​
    devices:​
    include:​
    - /dev/vdc​
    mountPoints: {}​
    vgs:​
    include:​
    - csi-local-pool-[0-9]+​
    nodeName: 192.168.2.6​
    resourceToBeInited:​
    vgs:​
    - devices:​
    - /dev/nvme0n1​
    name: csi-local-pool-0​
    spdkConfig: {}​
    status:​
    filteredStorageInfo:​
    updateStatusInfo:​
    lastUpdateTime: "2024-07-17T09:51:24Z"​
    updateStatus: accepted​
    volumeGroups:​
    - csi-local-pool-0​
    nodeStorageInfo:​
    deviceInfo: # After the local disk is initialized, you can view the partitioned dedicated disk.​
    - condition: DiskReady​
    mediaType: ssd​
    name: /dev/nvme0n1​
    readOnly: false​
    total: 3840755982336​
    - condition: DiskReady​
    mediaType: hdd​
    name: /dev/vda1​
    readOnly: false​
    total: 199229440​
    phase: Running​
    state:​
    lastHeartbeatTime: "2024-07-17T09:51:24Z"​
    status: "True"​
    type: DiskRead​
    ​
Step 4: Use a dynamic PersistentVolume based on local storage​
Local storage can be used in dynamic provisioning mode. You can select from preset StorageClasses.​
​
Built-in StorageClass​
Description​
csi-local-device-hdd​
Preconfigured StorageClass for HDD standalone disks. It uses the ext4 filesystem.​
csi-local-device-ssd​
Preconfigured StorageClass for SSD standalone disks. It uses the ext4 filesystem.​
csi-local-lvm​
Preconfigured StorageClass for LVM-managed shared storage. It uses the ext4 filesystem.​
csi-local-lvm-xfs​
Preconfigured StorageClass for LVM-managed shared storage. It uses the xfs filesystem.​
​
This example uses StatefulSet creation to demonstrate how to use a dynamic PersistentVolume created from dedicated local disks.​
  1. Create a YAML file for the StatefulSet. The following example is a file named statefulset-demo.yaml:​
  • ​
    apiVersion: apps/v1​
    kind: StatefulSet​
    metadata:​
    name: nginx-device​
    spec:​
    selector:​
    matchLabels:​
    app: nginx-device​
    podManagementPolicy: Parallel​
    serviceName: "nginx-device"​
    replicas: 1​
    volumeClaimTemplates:​
    - metadata:​
    name: html​
    spec:​
    volumeMode: Filesystem​
    accessModes:​
    - ReadWriteOnce​
    storageClassName: csi-local-device-hdd # The name of the pre-configured StorageClass. Choose one as needed.​
    resources:​
    requests:​
    storage: 5Gi​
    template:​
    metadata:​
    labels:​
    app: nginx-device​
    spec:​
    containers:​
    - name: nginx​
    image: doc-cn-beijing.cr.volces.com/vke/nginx-demo:v1.0​
    imagePullPolicy: Always​
    volumeMounts:​
    - mountPath: "/data"​
    name: html​
    command:​
    - sh​
    - "-c"​
    - |​
    while true; do​
    echo $(hostname) $(date) >> /data/test.txt;​
    sleep 10s​
    done;​
    ​
  1. Run the following command to create the workload.​
  • ​
    kubectl create -f statefulset-demo.yaml​
    ​
Result validation​
PV mounting​
After you delete the pod and create another one, you can run the exec command to enter the new pod to check whether data in the deleted pod exists.​
​
❯ kubectl delete pod nginx-device-0​
pod "nginx-device-0" deleted​
​
❯ kubectl exec -it nginx-device-0 cat /data/test.txt​
kubectl exec [POD] [COMMAND] is DEPRECATED and will be removed in a future version. Use kubectl exec [POD] -- [COMMAND] instead.​
nginx-device-0 Thu Jul 18 06:34:51 UTC 2024​
nginx-device-0 Thu Jul 18 06:35:01 UTC 2024​
nginx-device-0 Thu Jul 18 06:35:11 UTC 2024​
nginx-device-0 Thu Jul 18 06:35:21 UTC 2024​
nginx-device-0 Thu Jul 18 06:35:31 UTC 2024​
nginx-device-0 Thu Jul 18 06:35:41 UTC 2024​
nginx-device-0 Thu Jul 18 06:35:51 UTC 2024​
nginx-device-0 Thu Jul 18 06:36:01 UTC 2024​
nginx-device-0 Thu Jul 18 06:36:11 UTC 2024​
​
PV reclaim​
Delete the StatefulSet and delete the PVC. The dedicated disk vdc will be reclaimed and formatted, and the file system will be erased.​
​
root@iv-yda1sl1t***:~# mount /dev/vdc /tmp2​
mount: /tmp2: wrong fs type, bad option, bad superblock on /dev/vdc, missing codepage or helper program, or other error.​
​
​
Last updated: 2026.07.24 10:53:32