Configure automatic expansion for local volumes

Updated at:

In Container Service for Kubernetes (ACK) clusters, create and configure local volumes to store temporary data with fluctuating workloads on ECS local disks or cloud disks. Local storage is scheduled based on node capacity, and volumes automatically expand when usage reaches the configured threshold.

How it works

The local storage stack has three components:

Component Role
Node Resource Manager Reads a ConfigMap to initialize VolumeGroups and QuotaPaths on each node
CSI plugin Manages the local volume lifecycle: creation, mounting, unmounting, deletion, and expansion. For example, when a PVC uses a VolumeGroup, it automatically creates a logical volume and binds it to the PVC.
Storage Auto Expander Monitors volume usage and triggers expansion when usage exceeds the configured threshold
image

Failure behavior: When a node becomes unhealthy, the local volumes bound to it and their pods become inaccessible. Applications must tolerate this reduced availability.

Limitations

Review these constraints before you begin:

Constraint Detail
Supported volume types hostPath, local, LV (logical volume), and memory
No high availability Local volumes are node-bound. If the node fails, the volume becomes inaccessible. Use only for temporary storage or applications with built-in HA.
LVs cannot be migrated An LV is bound to physical disks on a specific node. If the node fails and the pod is rescheduled, the LV is inaccessible on the new node. Not suitable for HA scenarios.

Prerequisites

Ensure that the following requirements are met:

Step 1: Initialize a local volume

Node Resource Manager reads the node-resource-topo ConfigMap in kube-system to initialize local storage on each node. The ConfigMap defines two resource types: VolumeGroups, logical volumes managed by Logical Volume Manager (LVM), and QuotaPaths (quota-enforced directory mounts).

1.1 Define local volume resources in the ConfigMap

The value field in the ConfigMap must match the target node name — the same name used in PVC annotations in Step 2.

Replace cn-zhangjiakou.192.168.XX.XX with the actual node name.

Apply ConfigMap

cat <<EOF | kubectl apply -f -
apiVersion: v1
kind: ConfigMap
metadata:
  name: node-resource-topo
  namespace: kube-system
data:
  volumegroup: |-
    volumegroup:
    - name: volumegroup1
      key: kubernetes.io/hostname
      operator: In
      value: cn-zhangjiakou.192.168.XX.XX
      topology:
        type: device
        devices:
        - /dev/vdb
        - /dev/vdc
  quotapath: |-
    quotapath:
    - name: /mnt/path1
      key: kubernetes.io/hostname
      operator: In
      value: cn-zhangjiakou.192.168.XX.XX
      topology:
        type: device
        options: prjquota
        fstype: ext4
        devices:
        - /dev/vdd
EOF

This ConfigMap defines two resources on the cn-zhangjiakou.192.168.XX.XX node:

  • VolumeGroup (volumegroup1): Backed by block devices /dev/vdb and /dev/vdc. The CSI plugin carves logical volumes from this group on PVC creation.

  • QuotaPath (/mnt/path1): /dev/vdd is formatted with ext4 and mounted to /mnt/path1 with project quota (prjquota) enabled. Only one devices entry is allowed per QuotaPath.

1.2 Deploy the Node Resource Manager

Node Resource Manager runs as a DaemonSet on every node, watches the ConfigMap, and applies the declared storage topology.

Deploy the Node Resource Manager

cat <<EOF | kubectl apply -f -
---
apiVersion: v1
kind: ServiceAccount
metadata:
  name: node-resource-manager
  namespace: kube-system
---
kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1
metadata:
  name: node-resource-manager
rules:
  - apiGroups: [""]
    resources: ["configmaps"]
    verbs: ["get", "watch", "list", "delete", "update", "create"]
  - apiGroups: [""]
    resources: ["nodes"]
    verbs: ["get", "list", "watch"]
---
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
  name: node-resource-manager-binding
subjects:
  - kind: ServiceAccount
    name: node-resource-manager
    namespace: kube-system
roleRef:
  kind: ClusterRole
  name: node-resource-manager
  apiGroup: rbac.authorization.k8s.io
---
kind: DaemonSet
apiVersion: apps/v1
metadata:
  name: node-resource-manager
  namespace: kube-system
spec:
  selector:
    matchLabels:
      app: node-resource-manager
  template:
    metadata:
      labels:
        app: node-resource-manager
    spec:
      tolerations:
        - operator: "Exists"
      priorityClassName: system-node-critical
      serviceAccountName: node-resource-manager
      hostNetwork: true
      hostPID: true
      containers:
        - name: node-resource-manager
          securityContext:
            privileged: true
            capabilities:
              add: ["SYS_ADMIN"]
            allowPrivilegeEscalation: true
          image: registry.cn-hangzhou.aliyuncs.com/acs/node-resource-manager:v1.18.8.0-983ce56-aliyun
          imagePullPolicy: "Always"
          args:
            - "--nodeid=$(KUBE_NODE_NAME)"
          env:
            - name: KUBE_NODE_NAME
              valueFrom:
                fieldRef:
                  apiVersion: v1
                  fieldPath: spec.nodeName
          volumeMounts:
            - mountPath: /dev
              mountPropagation: "HostToContainer"
              name: host-dev
            - mountPath: /var/log/
              name: host-log
            - name: etc
              mountPath: /host/etc
            - name: config
              mountPath: /etc/unified-config
      volumes:
        - name: host-dev
          hostPath:
            path: /dev
        - name: host-log
          hostPath:
            path: /var/log/
        - name: etc
          hostPath:
            path: /etc
        - name: config
          configMap:
            name: node-resource-topo
EOF

1.3 Install the CSI plugin

The CSI plugin (csi-local-plugin) manages local volume lifecycle: creation, mounting, unmounting, deletion, and expansion.

cat <<EOF | kubectl apply -f -
apiVersion: storage.k8s.io/v1
kind: CSIDriver
metadata:
  name: localplugin.csi.alibabacloud.com
spec:
  attachRequired: false
  podInfoOnMount: true
---
apiVersion: apps/v1
kind: DaemonSet
metadata:
  labels:
    app: csi-local-plugin
  name: csi-local-plugin
  namespace: kube-system
spec:
  selector:
    matchLabels:
      app: csi-local-plugin
  template:
    metadata:
      labels:
        app: csi-local-plugin
    spec:
      containers:
      - args:
        - --v=5
        - --csi-address=/csi/csi.sock
        - --kubelet-registration-path=/var/lib/kubelet/csi-plugins/localplugin.csi.alibabacloud.com/csi.sock
        env:
        - name: KUBE_NODE_NAME
          valueFrom:
            fieldRef:
              apiVersion: v1
              fieldPath: spec.nodeName
        image: registry.cn-hangzhou.aliyuncs.com/acs/csi-node-driver-registrar:v1.2.0
        imagePullPolicy: Always
        name: driver-registrar
        volumeMounts:
        - mountPath: /csi
          name: plugin-dir
        - mountPath: /registration
          name: registration-dir
      - args:
        - --endpoint=$(CSI_ENDPOINT)
        - --v=5
        - --nodeid=$(KUBE_NODE_NAME)
        - --driver=localplugin.csi.alibabacloud.com
        env:
        - name: KUBE_NODE_NAME
          valueFrom:
            fieldRef:
              apiVersion: v1
              fieldPath: spec.nodeName
        - name: SERVICE_PORT
          value: "11290"
        - name: CSI_ENDPOINT
          value: unix://var/lib/kubelet/csi-plugins/localplugin.csi.alibabacloud.com/csi.sock
        image: registry.cn-hangzhou.aliyuncs.com/acs/csi-plugin:v1.14.8-40ee9518-local
        imagePullPolicy: Always
        name: csi-localplugin
        securityContext:
          allowPrivilegeEscalation: true
          capabilities:
            add:
            - SYS_ADMIN
          privileged: true
        volumeMounts:
        - mountPath: /var/lib/kubelet
          mountPropagation: Bidirectional
          name: pods-mount-dir
        - mountPath: /dev
          mountPropagation: HostToContainer
          name: host-dev
        - mountPath: /var/log/
          name: host-log
        - mountPath: /mnt
          mountPropagation: Bidirectional
          name: quota-path-dir
      hostNetwork: true
      hostPID: true
      serviceAccount: csi-admin
      tolerations:
      - operator: Exists
      volumes:
      - hostPath:
          path: /var/lib/kubelet/csi-plugins/localplugin.csi.alibabacloud.com
          type: DirectoryOrCreate
        name: plugin-dir
      - hostPath:
          path: /var/lib/kubelet/plugins_registry
          type: DirectoryOrCreate
        name: registration-dir
      - hostPath:
          path: /var/lib/kubelet
          type: Directory
        name: pods-mount-dir
      - hostPath:
          path: /dev
          type: ""
        name: host-dev
      - hostPath:
          path: /var/log/
          type: ""
        name: host-log
      - hostPath:
          path: /mnt
          type: Directory
        name: quota-path-dir
  updateStrategy:
    rollingUpdate:
      maxUnavailable: 10%
    type: RollingUpdate
EOF

Verify step 1

Confirm both DaemonSets are running before proceeding:

kubectl get daemonset -n kube-system | grep -E 'node-resource-manager|csi-local-plugin'

Expected output:

node-resource-manager   1         1         1       1            1           <none>          ...
csi-local-plugin        1         1         1       1            1           <none>          ...

Both DaemonSets should show all pods ready (desired = ready).

Step 2: Create an application using a local volume

Two volume types are available. Choose based on your workload:

Volume type Backed by Use when
LVM (LV) VolumeGroup (LVM logical volumes) Workloads needing block storage with flexible sizing
QuotaPath Formatted disk with project quota Workloads needing directory-based quota enforcement

Create an application using an LVM local volume

2.1 Create a StorageClass

The vgName parameter must match the VolumeGroup name in the node-resource-topo ConfigMap — volumegroup1 in this example.

volumeBindingMode: WaitForFirstConsumer delays PVC binding until a pod is scheduled. Without this, the PVC may bind to a wrong-node volume before pod scheduling, making the pod unschedulable.

cat <<EOF | kubectl apply -f -
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
    name: csi-local
provisioner: localplugin.csi.alibabacloud.com
parameters:
    volumeType: LVM
    vgName: volumegroup1
    fsType: ext4
    lvmType: "striping"
reclaimPolicy: Delete
volumeBindingMode: WaitForFirstConsumer
allowVolumeExpansion: true
EOF

See Use LVs.

2.2 Create a PVC

The volume.kubernetes.io/selected-node annotation pins the PVC to the VolumeGroup's node. Set it to the same node name in the ConfigMap value field.

cat << EOF | kubectl apply -f -
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: lvm-pvc
  annotations:
    volume.kubernetes.io/selected-node: cn-zhangjiakou.192.168.XX.XX
spec:
  accessModes:
  - ReadWriteOnce
  resources:
    requests:
      storage: 2Gi
  storageClassName: csi-local
EOF

2.3 Deploy the application

Create a sample application

cat << EOF | kubectl apply -f -
apiVersion: apps/v1
kind: Deployment
metadata:
  name: deployment-lvm
  labels:
    app: nginx
spec:
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: anolis-registry.cn-zhangjiakou.cr.aliyuncs.com/openanolis/nginx:1.14.1-8.6
        volumeMounts:
          - name: lvm-pvc
            mountPath: "/data"
      volumes:
        - name: lvm-pvc
          persistentVolumeClaim:
            claimName: lvm-pvc
EOF

Create an application using a QuotaPath local volume

2.4 Create a StorageClass

The rootPath parameter must match the QuotaPath mount path in the node-resource-topo ConfigMap — /mnt/path1 in this example.

cat << EOF | kubectl apply -f -
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
  name: alicloud-local-quota
parameters:
  volumeType: QuotaPath
  rootPath: /mnt/path1
provisioner: localplugin.csi.alibabacloud.com
reclaimPolicy: Delete
allowVolumeExpansion: true
volumeBindingMode: WaitForFirstConsumer
EOF

See Use QuotaPath volumes.

2.5 Create a PVC

The app: web-quota label is required — the auto-expansion policy in Step 3 uses this label to select PVCs for monitoring.

cat << EOF | kubectl apply -f -
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: csi-quota
  annotations:
    volume.kubernetes.io/selected-node: cn-zhangjiakou.192.168.XX.XX
  labels:
    app: web-quota
spec:
  accessModes:
  - ReadWriteOnce
  resources:
    requests:
      storage: 2Gi
  storageClassName: alicloud-local-quota
EOF

2.6 Deploy the application

Create a sample application

cat << EOF | kubectl apply -f -
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: web-quota
spec:
  selector:
    matchLabels:
      app: nginx
  serviceName: "nginx"
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: anolis-registry.cn-zhangjiakou.cr.aliyuncs.com/openanolis/nginx:1.14.1-8.6
        volumeMounts:
        - name: disk-ssd
          mountPath: /data
      volumes:
        - name: "disk-ssd"
          persistentVolumeClaim:
            claimName: csi-quota
EOF

After the pod starts, /data has 2 GiB per the PVC request.

Verify step 2

Check that the PVC is bound and the pod is running:

kubectl get pvc
kubectl get pod

Expected output (LVM example):

NAME      STATUS   VOLUME                                     CAPACITY   ACCESS MODES   STORAGECLASS   AGE
lvm-pvc   Bound    pvc-xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx  2Gi        RWO            csi-local      1m

The PVC status must be Bound before proceeding. If it stays Pending, verify the node name in the PVC annotation matches the ConfigMap value field.

Step 3: Automatically expand a local volume

Note

Local volumes support expansion only. They cannot be shrunk.

Storage Auto Expander monitors PVC usage and triggers expansion based on a StorageAutoScalerPolicy. Install the plugin and configure a policy that expands PVCs labeled app: web-quota by 50% when usage exceeds 80%, up to 15 GiB.

3.1 Install the storage-auto-expander plugin

Full installation details are in Use storage-operator to deploy and upgrade storage components.

  1. Edit the storage-operator ConfigMap to enable the plugin:

    kubectl edit cm storage-operator -n kube-system

    Set the following:

      storage-auto-expander: |
        # deploy config
        install: true
        imageTag: "v1.18.8.1-d4301ee-aliyun"
  2. Verify the plugin is running:

    kubectl get pod -n kube-system | grep storage-auto-expander

    Expected output:

    storage-auto-expander-6bb575b68c-tt4hh               1/1     Running     0          2m41s

3.2 Configure an auto-expansion policy

cat << EOF | kubectl apply -f -
apiVersion: storage.alibabacloud.com/v1alpha1
kind: StorageAutoScalerPolicy
metadata:
  name: hybrid-expand-policy
spec:
  pvcSelector:
    matchLabels:
      app: web-quota
  namespaces:
    - default
  conditions:
    - name: condition1
      key: volume-capacity-used-percentage
      operator: Gt
      values:
        - "80"
  actions:
    - name: action
      type: volume-expand
      params:
        scale: 50%
        limits: 15Gi
EOF

This policy targets PVCs labeled app: web-quota in the default namespace. When usage exceeds 80%, the volume expands by 50%. Expansion stops at 15 GiB.

Next steps