Automatically initialize local storage resources

Updated at:

Local storage resources in Kubernetes clusters are often initialized manually or in batches using Ansible. These methods are complex and unsuitable for large-scale clusters. The Node Resource Manager component can automatically initialize and update local storage resources on a node based on a ConfigMap definition. This topic describes how to use the Node Resource Manager component to automatically initialize local storage resources.

Background information

Initializing local storage resources in Kubernetes clusters presents several challenges. The primary methods, manual and batch initialization with Ansible, have the following issues:

  • With Ansible, you cannot easily use Kubernetes node information for custom deployments. You must install kubelet, run shell commands, and parse the command results.

  • Manual deployment of local storage resources is difficult in large-scale clusters.

  • Initialized resources cannot be continuously maintained. To update resources, you must log on to the node and perform operations manually. Storage resource usage information cannot be reported, which affects pod scheduling.

The Node Resource Manager component automatically initializes local storage resources, reports their usage information, and works with the scheduler to automatically schedule pods that use these resources. For more information, see node-resource-manager.

Step 1: Define the resource node in a ConfigMap

You can define the node where the resource is located using the following three parameters.

key: kubernetes.io/hostname
operator: In
value: xxxxx

Parameter

Description

key

Matches the key in the Kubernetes node labels.

operator

The label selector operator defined by Kubernetes. It includes the following four operators:

  • In: Matches if the value is the same as the value of the corresponding label key on the node.

  • NotIn: Matches only if the value is different from the value of the corresponding label on the node.

  • Exists: Matches if the key exists in the node's labels.

  • DoesNotExist: Matches if the key does not exist in the node's labels.

value

Matches the value of the corresponding key in the Kubernetes node labels.

As needed, you can define the resource topology using Logical Volume Management (LVM) or Quotapath to initialize the local storage resources on the specified nodes.

Define the resource topology using LVM

You can define the resource topology using LVM in one of the following three ways:

  • type: device: Declares a Logical Volume Manager (LVM) volume from the block devices specified in devices on the host. These block devices form a volumegroup. The name parameter specifies the name of the volumegroup. Applications use this volume group to allocate Logical Volumes at startup.

  • type: alibabacloud-local-disk: Creates a volumegroup, named by the name parameter, from all local disks on the host where the Node Resource Manager component is located. (Select an ECS instance type that has local disks.)

    Important

    For ECS instances created from Local SSD (i2) instance types, manually attached block devices are cloud disks, not local disks.

  • type: pmem: Creates a volumegroup, named by the name parameter, from the Persistent Memory (PMEM) resources on the host where the Node Resource Manager component is located. You can use the regions parameter to specify multiple PMEM region resources on the host.

Sample YAML:

apiVersion: v1
kind: ConfigMap
metadata:
  name: unified-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
    - name: volumegroup2
      key: kubernetes.io/nodetype
      operator: NotIn
      value: localdisk
      topology:
        type: alibabacloud-local-disk
    - name: volumegroup3
      key: kubernetes.io/hostname
      operator: Exists
      value: cn-beijing.192.168.XX.XX
      topology:
        type: pmem
        regions:
        - region0

Define the resource topology using Quotapath

You can define the resource topology using Quotapath in one of the following two ways:

  • type: device: Initializes a Quotapath using a block device on the host. The initialization path is the value of the name field.

  • type: pmem: Initializes a Quotapath using a PMEM device on the host. The initialization path is the value of the name field.

Sample YAML:

apiVersion: v1
kind: ConfigMap
metadata:
  name: unified-resource-topo
  namespace: kube-system
data:
  quotapath: |-
    quotapath:
    - name: /mnt/path1
      key: kubernetes.io/hostname
      operator: In
      value: cn-beijing.192.168.XX.XX
      topology:
        type: device
        options: prjquota
        fstype: ext4
        devices:
        - /dev/vdb
    - name: /mnt/path2
      key: kubernetes.io/hostname
      operator: In
      value: cn-beijing.192.168.XX.XX
      topology:
        type: pmem
        options: prjquota,shared
        fstype: ext4
        regions:
        - region0

The following table describes the related parameters.

Parameter

Description

options

The parameters used when mounting the block device.

fstype

The file system used to format the block device. The default is ext4.

devices

The block devices to mount. You can declare multiple block devices. If multiple devices are declared, the system tries to mount them in order until one is mounted successfully.

Step 2: Deploy the Node Resource Manager component

You can deploy the Node Resource Manager component by creating a DaemonSet in the cluster. The following is a sample YAML file:

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

After deployment, the component automatically applies the ConfigMap configuration to the nodes. If you update the ConfigMap, the component updates the resources within one minute.

Important

To ensure data security, the Node Resource Manager component does not delete any resources.

Contact us

If you have questions about the CSI plug-in, join the DingTalk group 33936810.