Resource allocation method and device for container cluster, equipment, medium and program product
By optimizing the resource allocation strategy in the container cluster based on multi-dimensional resource feature vectors and cluster analysis, the problem of low resource utilization in the container cluster is solved, and multi-dimensional resource optimization and stability improvement are achieved.
Patent Information
- Application Number
- CN202510624522.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-05-15
- Publication Date
- 2025-09-19
AI Technical Summary
In the existing technology of container cluster resource management, resource allocation is only based on a single-dimensional indicator, resulting in low resource utilization, insufficient resources for some applications affecting performance, and excess resources for some applications causing waste, and a lack of optimization and dynamic adjustment capabilities for multi-dimensional resources.
By determining the feature vector based on the multi-dimensional resource utilization, allocation rate and fragmentation rate of each node in the cluster, the K-Means clustering algorithm is used to cluster the nodes. Combined with the priority and migration cost of POD, a scheduling strategy is generated to optimize resource allocation to reduce fragmentation and improve resource utilization.
It achieves multi-dimensional resource optimization, evenly distributes resources such as CPU, memory, GPU and storage bandwidth, reduces resource waste, improves resource utilization and management efficiency of container clusters, and ensures the stability and flexible adaptability of the cluster.
Smart Images

Figure CN120670082A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of container cluster resource management, and in particular to a resource allocation method, apparatus, device, medium, and program product for a container cluster. Background Art
[0002] In the field of container cluster resource management, resource allocation is usually based on a single-dimensional indicator, which makes it difficult to fully take into account the diverse needs of different applications in the cluster. At the same time, insufficient resources for some applications affect performance, while excess resources for some applications cause waste, resulting in low resource utilization of the container cluster. Summary of the Invention
[0003] The present invention provides a resource allocation method, apparatus, device, medium and program product for a container cluster, which are used to solve the defect of low resource utilization of container clusters in the prior art and improve the resource utilization of container clusters.
[0004] The present invention provides a resource allocation method for a container cluster, comprising the following steps: Determine the feature vector of each node based on the utilization rate, allocation rate, and fragmentation rate of the multi-dimensional resources of each node in the cluster; Clustering the nodes based on the feature vectors of each node to obtain a node clustering result; Determine a POD scheduling strategy based on the node clustering result, the fragmented node set, and the priority of each container group POD in the cluster; A scheduling operation of the POD is performed based on the scheduling policy to allocate resources in the cluster.
[0005] According to a resource allocation method for a container cluster provided by the present invention, determining a POD scheduling strategy based on the node clustering result, the fragmented node set, and the priority of each container group POD in the cluster includes: Calculate the migration cost of each POD in each fragmented node in the fragmented node set based on the priority of each POD; Determining a POD to be migrated for each of the fragmented nodes based on the ranking information of the migration costs of the PODs; Determine the resource matching node of the POD to be migrated based on the node clustering result; A scheduling policy for the POD is generated based on the POD to be migrated and the resource matching node.
[0006] According to a resource allocation method for a container cluster provided by the present invention, the migration cost of any Pod is determined based on the following method: Obtaining the priority weight corresponding to the priority of the POD; The ratio of the resource demand of the POD to the priority weight of the POD is used as the migration cost of the POD.
[0007] According to a resource allocation method for a container cluster provided by the present invention, clustering the nodes based on the feature vectors of the nodes to obtain node clustering results includes: Initializing clustering of the nodes based on the feature vectors of each node to obtain multiple clusters; Based on the distance between the feature vector of each node and the cluster center of each cluster, the node is assigned to the cluster with the shortest distance; updating the cluster center of each cluster based on the mean of the feature vectors of all nodes in each cluster; The cluster center update operation is iteratively performed until the number of clustering times reaches the maximum number of clustering times, thereby obtaining the node clustering result.
[0008] According to a resource allocation method for a container cluster provided by the present invention, updating the cluster center of each cluster based on the mean of the feature vectors of all nodes in each cluster includes: The mean of the feature vectors of all nodes in each cluster is used as the new cluster center of each cluster.
[0009] According to a resource allocation method for a container cluster provided by the present invention, the fragmentation rate of the node includes the fragmentation rate of each resource of the node and the multi-dimensional resource fragmentation rate of the node; the fragmentation rate of each resource of the node and the multi-dimensional resource fragmentation rate are determined based on the following method: The ratio of the allocated amount of each resource to the total amount of each resource is taken as the fragmentation rate of each resource; The fragmentation rates of various resources in the node are weighted and summed to obtain the multi-dimensional resource fragmentation rate of the node.
[0010] The present invention also provides a resource allocation device for a container cluster, comprising the following modules: A feature vector determination module is used to determine the feature vector of each node based on the utilization rate, allocation rate and fragmentation rate of the multi-dimensional resources of each node in the cluster; A clustering module, configured to cluster the nodes based on the feature vectors of the nodes to obtain node clustering results; A scheduling strategy determination module is used to determine the scheduling strategy of the POD based on the node clustering result, the fragmented node set and the priority of each container group POD in the cluster; The scheduling module is used to perform a scheduling operation of the POD based on the scheduling policy to allocate resources in the cluster.
[0011] The present invention also provides an electronic device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the computer program, the resource allocation method for the container cluster as described above is implemented.
[0012] The present invention also provides a non-transitory computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements any of the above-described methods for allocating resources for a container cluster.
[0013] The present invention also provides a computer program product, comprising a computer program, wherein when the computer program is executed by a processor, the computer program implements any of the above-mentioned resource allocation methods for a container cluster.
[0014] The resource allocation method, apparatus, device, medium, and program product for a container cluster provided by the present invention determine the characteristic vector of each node based on the utilization rate, allocation rate, and fragmentation rate of the multi-dimensional resources of each node in the cluster; cluster the nodes based on the characteristic vectors of each node to obtain a node clustering result; determine the scheduling strategy of the POD based on the node clustering result, the fragmented node set, and the priority of each container group POD in the cluster; and execute the scheduling operation of the POD based on the scheduling strategy to allocate resources in the cluster. The present invention analyzes the utilization rate, allocation rate, and fragmentation rate of the multi-dimensional resources of the nodes and optimizes the fragmented nodes to achieve multi-dimensional resource optimization, evenly allocate resources such as CPU, memory, GPU, and storage bandwidth, reduce resource waste, thereby improving the resource utilization of the container cluster and further improving the efficiency and stability of cluster resource management. BRIEF DESCRIPTION OF THE DRAWINGS
[0015] In order to more clearly illustrate the technical solutions in the present invention or the prior art, a brief introduction is given below to the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings described below are some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.
[0016] Figure 1 This is a flow chart of the resource allocation method for a container cluster provided by the present invention.
[0017] Figure 2 This is a schematic diagram of the architecture of the resource allocation optimization system based on the Kubernetes custom controller provided by the present invention.
[0018] Figure 3 It is a flow chart of the node clustering operation performed by the analysis module provided by the present invention.
[0019] Figure 4It is a structural diagram of the resource allocation device for the container cluster provided by the present invention.
[0020] Figure 5 It is a structural schematic diagram of the electronic device provided by the present invention. DETAILED DESCRIPTION
[0021] To make the objectives, technical solutions, and advantages of the present invention more clear, the technical solutions of the present invention will be clearly and completely described below in conjunction with the accompanying drawings. Obviously, the embodiments described are only some of the embodiments of the present invention, not all of them. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without making creative efforts shall fall within the scope of protection of the present invention.
[0022] In related technologies, container cluster resource management primarily includes the following solutions: The default scheduler of Kubernetes (K8s, a container orchestration platform) schedules container groups (Pods) to appropriate nodes through pre-selection and optimization strategies, focusing primarily on the availability of CPU (Central Processing Unit) and memory resources; resource quotas and limits prevent over-allocation of resources but fail to address resource fragmentation; custom schedulers are optimized for specific scenarios (such as GPU (Graphics Processing Unit) resource scheduling) but lack universal applicability; resource recycling and rescheduling tools (such as Descheduler) optimize resource usage through simple rules but lack in-depth analysis and dynamic adjustment capabilities for resource fragmentation. Consequently, related technologies lack the ability to optimize multi-dimensional resources, minimize business impact, and dynamically respond to cluster changes.
[0023] Furthermore, container cluster resource management in related technologies focuses solely on CPU and memory resources, neglecting the optimization of other resources (such as GPUs and storage bandwidth). This leads to uneven resource utilization and fragmented resources. Even if a node has sufficient resources, resource fragmentation can still prevent pods from being scheduled. Optimizing fragmented resources can result in the migration of a large number of pods, significantly impacting business operations. Related technologies typically use static scheduling and optimization rules, failing to adapt policies in real time to dynamic changes in the cluster, such as fluctuations in resource utilization and changes in pod status.
[0024] To address key issues in container cluster resource management, the present invention proposes a resource allocation method for container clusters, specifically a multi-dimensional resource allocation optimization method for container clusters. This method focuses on the following core objectives: by analyzing node resource utilization and allocation rates, identifying and optimizing resource fragmentation nodes to reduce resource waste; achieving multi-dimensional resource optimization, evenly allocating resources such as CPU, memory, GPU, and storage bandwidth, and improving overall resource utilization. During the optimization process, PODs with less impact on business are prioritized for migration, and the migration scale is controlled to minimize disruption to business. At the same time, the cluster status is monitored in real time, and the optimization strategy is dynamically adjusted to ensure that resource allocation can flexibly adapt to the dynamic changes of the cluster, thereby improving the efficiency and stability of cluster resource management.
[0025] The following combination Figure 1-Figure 5 The present invention describes a method, apparatus, device, medium, and program product for allocating resources in a container cluster.
[0026] Figure 1 This is a flow chart of the resource allocation method for the container cluster provided by the present invention, such as Figure 1 As shown, the method includes the following: Step 101 : determining a feature vector of each node based on the utilization rate, allocation rate, and fragmentation rate of the multi-dimensional resources of each node in the cluster.
[0027] It should be understood that multi-dimensional resources refer to various heterogeneous resource types that affect task scheduling and performance, which may include CPU, memory, GPU, storage bandwidth, storage capacity, network bandwidth, port resources, etc.
[0028] It should be understood that resource utilization measures the actual proportion of resource consumption and reflects the current load pressure. For example, utilization = (used resource amount / total resource amount) × 100%. Assuming the total memory is 100GB and the process occupies 40GB, the memory utilization is 40%.
[0029] It should be understood that the resource allocation ratio measures the proportion of resources occupied by a pod (via requests), reflecting scheduling commitments. For example, allocation ratio = (pod resource requests / total resources) × 100%. Assuming the total memory is 100GB and the total requests.memory of a pod is 60GB, the allocation ratio is 60%.
[0030] It should be understood that the resource fragmentation rate is used to measure the degree of dispersion of resources that remain but cannot be utilized by large tasks, reflecting the potential for resource utilization. The fragmentation rate of a node includes the fragmentation rate of each resource and the node's multi-dimensional resource fragmentation rate. The fragmentation rate of each resource and the multi-dimensional resource fragmentation rate are determined by taking the ratio of the allocated amount of each resource to the total amount of each resource as the fragmentation rate of each resource; and taking the weighted sum of the fragmentation rates of various resources in the node to obtain the node's multi-dimensional resource fragmentation rate.
[0031] For example, for each node, calculate the fragmentation rate of each resource type. Assume that the node has Resource type, Fragmentation rate of resources It can be expressed as: ; in, Indicates the The amount of resources allocated to a resource, Indicates the The total amount of resources of a resource.
[0032] The weighted average method is used to calculate the overall fragmentation rate of the node, that is, the multi-dimensional resource fragmentation rate: ; in, Indicates the The weight of the resource satisfies ,The weight setting can be dynamically adjusted according to business needs.,For example, CPU-intensive applications can give the CPU a higher weight.
[0033] Combine the utilization, allocation, and fragmentation rates of each node's multi-dimensional resources into a feature vector. For example, feature vector = [CPU utilization, memory utilization, GPU utilization, storage bandwidth utilization, CPU allocation rate, memory allocation rate, GPU allocation rate, storage bandwidth allocation rate, CPU fragmentation rate, memory fragmentation rate, GPU fragmentation rate, storage bandwidth fragmentation rate, multi-dimensional resource fragmentation rate].
[0034] Step 102: cluster the nodes based on the feature vectors of the nodes to obtain node clustering results.
[0035] The feature vector of each node is used as the input of the clustering algorithm (such as K-Means), and the nodes are clustered based on the clustering algorithm to obtain the node clustering results.
[0036] Step 103 : Determine a POD scheduling strategy based on the node clustering result, the fragmented node set, and the priority of each container group POD in the cluster.
[0037] It should be understood that Pod is the smallest schedulable and manageable unit in Kubernetes (K8s), which is used to encapsulate and run one or more closely associated containers (such as Docker containers).
[0038] Fragmented nodes in the fragmented node set can be understood as nodes with uneven resource allocation (for example, the remaining GPUs are scattered and occupied). For example, nodes with a multi-dimensional resource fragmentation rate greater than a set threshold can be regarded as fragmented nodes.
[0039] The priority of a POD is used to mark the importance of the POD (e.g., priorities include high, medium, and low). It should be understood that the priority of a POD can be determined based on the POD's resource requirements and business type. For example, a POD can be given a higher priority for business-critical applications (such as online trading systems) or resource-intensive applications (such as big data analysis tasks).
[0040] Resource fragmentation exists in the cluster (for example, GPU monopoly leading to resource waste), but directly migrating pods can impact business stability. Based on this, a pod scheduling policy can be determined based on node clustering results, the set of fragmented nodes, and the priority of each pod in the cluster. This allows for resource fragmentation to be optimized by dynamically migrating low-priority pods, thereby reducing fragmentation and minimizing the impact on business. By selectively migrating low-priority pods with low resource requirements, fragmentation can be alleviated while avoiding disruption to high-priority businesses.
[0041] Step 104: Execute a scheduling operation of the POD based on the scheduling policy to allocate resources in the cluster.
[0042] It should be understood that the core goals of the scheduling strategy are: maximizing resource utilization (avoiding waste); meeting business needs (such as GPU acceleration, low latency, etc.); and ensuring system stability (avoiding node overload).
[0043] Based on the scheduling policy, the POD to be scheduled and the resource matching node of the POD to be scheduled are determined, and then the POD to be scheduled is scheduled to the resource matching node so that the business in the POD to be scheduled is executed through the resource matching node.
[0044] The resource allocation method for a container cluster provided in an embodiment of the present invention determines the characteristic vector of each node based on the utilization rate, allocation rate, and fragmentation rate of the multi-dimensional resources of each node in the cluster; clusters the nodes based on the characteristic vectors of each node to obtain a node clustering result; determines the scheduling strategy of the POD based on the node clustering result, the fragmented node set, and the priority of each container group POD in the cluster; and executes the scheduling operation of the POD based on the scheduling strategy to allocate resources in the cluster. The present invention achieves multi-dimensional resource optimization by analyzing the utilization rate, allocation rate, and fragmentation rate of the multi-dimensional resources of the nodes and optimizing the fragmented nodes, thereby evenly allocating resources such as CPU, memory, GPU, and storage bandwidth, reducing resource waste, thereby improving the resource utilization of the container cluster and further improving the efficiency and stability of cluster resource management.
[0045] Based on the above embodiment, step 102 specifically includes: Initializing clustering of the nodes based on the feature vectors of each node to obtain multiple clusters; Based on the distance between the feature vector of each node and the cluster center of each cluster, the node is assigned to the cluster with the shortest distance; updating the cluster center of each cluster based on the mean of the feature vectors of all nodes in each cluster; The cluster center update operation is iteratively performed until the number of clustering times reaches the maximum number of clustering times, thereby obtaining the node clustering result.
[0046] It should be understood that node clustering can be achieved by the following steps: Step 1: Initialize clustering: You can use the K-Means clustering algorithm to initialize the clustering of nodes. Specifically, the input of the K-Means clustering algorithm is the feature vectors of all nodes; the clustering rule is to divide the nodes into three categories based on the similarity of the feature vectors (such as the combined pattern of CPU / GPU usage). For example, the three clusters obtained by initial clustering are: Cluster 1: nodes with high CPU usage and low GPU usage; Cluster 2: nodes with high GPU usage and low CPU usage; Cluster 3: Nodes with balanced resource usage.
[0047] It should be understood that the purpose of initial clustering is to preliminarily identify the resource usage characteristics of nodes and provide a coarse-grained classification basis for the scheduler. At the same time, it avoids misscheduling GPU-intensive PODs to high-CPU nodes, reducing resource waste.
[0048] Step 2: Iterative Optimization: The goal is to dynamically adjust node resource usage patterns to adapt to changes in cluster resources (such as changes in resource distribution after node expansion). This ensures that clustering results reflect the current state of resources, improves the accuracy of POD node selection, and optimizes resource utilization. This also reduces resource fragmentation and ensures cluster stability and efficiency.
[0049] 2.1) Assign nodes to the nearest cluster center: Calculate the distance between each node's feature vector and the cluster center of each cluster, and then assign the node to the cluster with the shortest distance. For example, the Euclidean distance formula can be used to calculate the distance: ; in, Indicates the The feature vector of each node, Indicates the The characteristic vectors of cluster centers, Represents the dimension of the feature vector.
[0050] 2.2) Update Cluster Centers: For each cluster, calculate the mean of the feature vectors of all nodes within the cluster, and then update the cluster center based on this mean. In one embodiment, the mean of the feature vectors of all nodes within each cluster is used as the new cluster center for each cluster.
[0051] The mean calculation formula is: ; in, represents a set of nodes that form clusters. Indicates the number of nodes in the cluster. The feature vector representing the nodes in the cluster.
[0052] 2.3) Repeat the iterations and continuously update the cluster centers until the resource usage pattern of the nodes stabilizes (e.g., the cluster centers no longer change significantly), or the maximum number of iterations is reached, or the cluster center movement distance between two consecutive iterations is less than a threshold (e.g., 0.01).
[0053] Optionally, the changes in node resource usage are monitored in real time. When changes in the node resource usage patterns of more than 30% are detected, iterative optimization of node clustering is triggered.
[0054] It should be understood that as the cluster runs, the resource usage of the nodes will change dynamically. For example, the GPU utilization of a GPU node in Cluster 2 may drop from 90% to 10% due to the completion of a task; or a CPU node in Cluster 1 may suddenly increase its GPU task. Based on this, continuous iterative optimization is required to ensure that the clustering results reflect the real-time status of the cluster. Specifically, the distance between each node's current feature vector (CPU / GPU utilization, etc.) and each cluster center is calculated, and the node is assigned to the cluster that currently best matches the cluster. For example, a node with a GPU utilization rate that drops to 10% will be reassigned from Cluster 2 to Cluster 3. Based on the actual status of all nodes in the current cluster, the cluster center of the cluster is recalculated. For example, the new standard for Cluster 2 may be adjusted from "GPU>80%" to "GPU>60%."
[0055] Clustering identifies "high GPU usage nodes" to ensure that GPU-intensive pods are assigned to the correct cluster, reducing fragmentation caused by exclusivity. When node resources change (such as reduced GPU load), re-clustering may move them from "Cluster 2" to "Cluster 3", freeing up GPU resources for other pods. Balanced pods are preferentially scheduled to "Cluster 3" to avoid competing for resources with CPU / GPU-intensive pods.
[0056] The embodiment of the present invention identifies resource usage patterns through dynamic clustering, reducing allocation conflicts of exclusive resources such as GPUs. Euclidean distance calculation ensures accurate matching of the multi-dimensional resource requirements of PODs and nodes. In addition, the iterative update mechanism ensures that the clustering results reflect the real-time status of the cluster.
[0057] In one embodiment, step 103 specifically includes: Calculate the migration cost of each POD in each fragmented node in the fragmented node set based on the priority of each POD; Determining a POD to be migrated for each of the fragmented nodes based on the ranking information of the migration costs of the PODs; Determine the resource matching node of the POD to be migrated based on the node clustering result; A scheduling policy for the POD is generated based on the POD to be migrated and the resource matching node.
[0058] It should be understood that the POD to be migrated may be a newly created POD or a POD that needs to be rescheduled.
[0059] Specifically, the scheduling policy for a POD can be generated based on the following steps: Step 1: Obtain node analysis data: including node clustering results, fragmented node set, and POD priority list.
[0060] Step 2: Develop an optimization strategy: The core principles of the optimization strategy are: 1) Minimize the number of POD adjustments: migrate as few PODs as possible; 2) Reduce the amount of migration: prioritize migrating PODs that have little impact on the business.
[0061] Step 3: Identify the pods that can be migrated (i.e. the pods to be migrated): 3.1) Screening criteria: Low priority: PODs with higher weights are migrated first (low priority = 3, the higher the weight, the easier it is to be migrated); Small resource requirements: Select a POD with smaller combined CPU, memory, and GPU requirements (low migration cost).
[0062] 3.2) For each fragmented node in the fragmented node set, calculate the migration cost of the POD within it. In one embodiment, obtain the priority weight corresponding to the POD priority; and use the ratio of the POD's resource demand to the POD's priority weight as the POD's migration cost. The calculation formula for the migration cost is: ; The resource requirement of a POD is the total amount of CPU, memory, GPU, and other resources requested by the POD (the smaller the value, the lower the migration cost). POD priority weights can be understood as high priority = 1 (difficult to migrate) and low priority = 3 (easy to migrate). For example, a high-priority POD (such as an online service) has a weight of 1, indicating a high migration cost and will not be easily migrated. A low-priority POD (such as a batch processing task) has a weight of 3, indicating a low migration cost and can be prioritized.
[0063] After determining the migration cost of each POD in each fragmented node, PODs that meet the following conditions can be selected as PODs to be migrated in order of migration cost from small to large: 1) the migration cost is less than the preset threshold; the priority weight is ≥ 2.
[0064] It should be understood that migrating a POD with low resource requirements frees up a continuous resource block (such as an entire GPU), facilitating the scheduling of PODs with high resource requirements. Furthermore, PODs with low resource requirements migrate quickly, minimizing the impact on nodes.
[0065] Step 4: Target node selection (i.e. resource matching node): Based on the node clustering results, resource matching nodes are determined for each pod to be migrated. Specifically, nodes with complementary resource types are selected based on the resource requirements of the pod to be migrated. For example, pods with GPU requirements are preferentially matched with nodes in clusters with high GPU utilization; pods with CPU requirements are preferentially matched with nodes in clusters with high CPU utilization; and pods with balanced requirements are preferentially matched with nodes in balanced clusters.
[0066] Optionally, nodes with low fragmentation and matching resource demand characteristics (remaining resources are continuously available) can be preferentially selected as resource matching nodes for the POD to be migrated.
[0067] Step 5: Scheduling strategy generation: Based on the pod to be migrated and the resource matching node, a scheduling strategy for the pod is generated. For example, the scheduling strategy for the pod can be generated based on the identifier of the pod to be migrated, the identifier of the resource matching node, and the expected amount of resource release.
[0068] The embodiment of the present invention can alleviate fragmentation and avoid interruption of high-priority services by selectively migrating PODs with low priority and small resource requirements.
[0069] To further illustrate the resource allocation method for a container cluster proposed in the present invention, refer to the following examples.
[0070] Related technologies, such as the Kubernetes default scheduler, resource quota mechanism, custom schedulers, and rescheduling tools, primarily focus on the availability of CPU and memory resources. However, these technologies suffer from resource fragmentation, a lack of multi-dimensional resource optimization, significant business impact, and insufficient dynamic adjustment capabilities. To address these issues, embodiments of the present invention propose a resource allocation optimization system based on a Kubernetes custom resource controller. This system can be used to implement the resource allocation method for container clusters provided in the embodiments above. The core of this system primarily includes: 1. Multi-dimensional resource monitoring and fragmentation detection: Expands the monitoring scope to cover multi-dimensional resources such as CPU, memory, GPU, storage bandwidth, etc., analyzes resource utilization and allocation rates in real time, and identifies resource fragmentation nodes; 2. Dynamic optimization and scheduling: Introducing the K-Means clustering analysis algorithm, dynamically adjusting resource allocation strategies, supporting multi-dimensional resource optimization and priority scheduling, ensuring that critical business pods are not affected; 3. Minimize business impact: Through the pod priority mechanism and batch migration strategy, low-priority pods are migrated first to reduce disruption to the business. 4. Real-time feedback and adaptability: Combining Prometheus and the Kubernetes Informer mechanism, cluster status is monitored in real time, and optimization strategies are dynamically adjusted to adapt to dynamic cluster changes. Prometheus is an open-source monitoring system and time series database that collects and stores metrics—numeric values about system, service, or application performance. Kubernetes Informer is a mechanism in the Kubernetes client library that allows applications to dynamically track changes in Kubernetes resource objects (such as pods, services, and deployments).
[0071] refer to Figure 2 , the custom resource controller mainly includes the following modules: 1. Monitoring Module: This module uses Kubernetes' Informer mechanism to monitor changes in cluster resource objects (such as nodes and pods) and obtain real-time resource usage data for nodes and pods. The monitoring scope is expanded to cover multiple resources, including CPU, memory, GPU, and storage bandwidth. Data is collected using Prometheus and Metrics Server. Metrics Server is a component of the Kubernetes cluster that provides a centralized way to collect and expose resource metrics for cluster nodes and pods, such as CPU and memory usage.
[0072] 2. Analysis Module: Leveraging the data cached by Informer, the K-Means clustering analysis algorithm is used to cluster multidimensional data. Through iterative optimization, nodes are divided into K clusters, ensuring that nodes within each cluster are as similar as possible and nodes between clusters are as different as possible. Through a comprehensive evaluation of multidimensional resource utilization and allocation rates, resource fragmentation nodes and potential optimization opportunities are identified. This module mainly includes the following: 2.1 Data Preparation a) Assign weights to different types of resources, and dynamically adjust weights based on business needs. For example, for AI training tasks, GPU weight > CPU weight > memory weight; for big data processing tasks, CPU weight > memory weight > storage bandwidth weight.
[0073] b) Resource fragmentation detection: For each node, calculate the fragmentation rate of each resource type. Assume that the node has Resource type, Fragmentation rate of resources It can be expressed as: ; in, Indicates the The amount of resources allocated to a resource, Indicates the The total amount of resources of a resource.
[0074] Multi-dimensional resource fragmentation rate: The weighted average method is used to calculate the overall fragmentation rate of the node, that is, the multi-dimensional resource fragmentation rate: ; in, Indicates the The weight of the resource satisfies ,The weight setting can be dynamically adjusted according to business needs.,For example, CPU-intensive applications can give the CPU a higher weight.
[0075] c) Eigenvector: Combine the resource usage, allocation rate, and fragmentation rate of each node into a feature vector. For example, feature vector = [CPU usage, memory usage, GPU usage, storage bandwidth usage, CPU allocation rate, memory allocation rate, GPU allocation rate, storage bandwidth allocation rate, CPU fragmentation rate, memory fragmentation rate, GPU fragmentation rate, storage bandwidth fragmentation rate, multi-dimensional resource fragmentation rate].
[0076] 2.2, Node Clustering: refer to Figure 3 , Figure 3 Node clustering can be achieved based on the following steps: 2.21) Initialize Clustering: Use the K-Means algorithm to cluster nodes into three clusters. For example, Cluster 1: nodes with high CPU usage and low GPU usage; Cluster 2: nodes with high GPU usage and low CPU usage; Cluster 3: nodes with balanced resource usage.
[0077] 2.22) Iterative Clustering: The goal is to dynamically adjust node resource usage patterns to adapt to changes in cluster resources, improve the accuracy of POD node selection, and optimize resource utilization; at the same time, it reduces resource fragmentation and ensures cluster stability and efficiency.
[0078] Step 1: Assign nodes to the nearest cluster center using the Euclidean distance formula: ; in, Indicates the The feature vector of each node, Indicates the The characteristic vectors of cluster centers, Represents the dimension of the feature vector.
[0079] Step 2: Update the cluster center: For each cluster, calculate the mean of the feature vectors of all nodes in the cluster as the new cluster center. The mean calculation formula is: ; in, represents a set of nodes that form clusters. Indicates the number of nodes in the cluster. The feature vector representing the nodes in the cluster.
[0080] 2.23) Repeat the iteration until the resource usage pattern of the node stabilizes or the maximum number of iterations is reached.
[0081] Optimization Module: Based on the Kubernetes scheduling framework, this module implements custom scheduling policies and supports multi-dimensional resource optimization. It also introduces a priority mechanism to ensure that mission-critical pods are not affected by migration, prioritizing the migration of low-priority or non-critical pods.
[0082] 3.1) Obtain the results of the analysis module, including node clustering results, fragmented node list, and POD priority list; 3.2) Develop an optimization strategy to minimize the number of POD adjustments. During the optimization process, minimize the number of PODs that need to be migrated. Identify the PODs that can be migrated. For each resource fragmentation node, identify the low-priority PODs that can be migrated, and prioritize PODs with smaller resource requirements for migration. The migration cost is calculated as follows: ; The resource requirement of a POD is the sum of its CPU, memory, GPU and other resource requirements. The priority weights of a POD can include high priority = 1, medium priority = 2, and low priority = 3. 3.3) Return the optimized scheduling results.
[0083] 4. Scheduling Module: Based on the results of the analysis and optimization modules, the module calls the Kubernetes API to evict and reschedule pods, implementing a batch migration strategy to avoid impacting the cluster caused by migrating a large number of pods at once. This module mainly includes the following: Migrate in batches: Divide the pods to be migrated into multiple batches, migrating a certain number of pods in each batch. For example, migrate 5 pods in each batch. Priority sorting: Sort by POD priority, migrating low-priority PODs first, then medium-priority PODs. Interval: Set a certain interval (such as 30 seconds) between each batch of migrations to reduce the impact on the cluster.
[0084] The specific steps are as follows: 4.1) Listening to the Scheduling Queue: Obtain unscheduled POD deployment requests from the scheduling queue and obtain the deployment information, mainly the POD's resource information and tags. Identify the POD's resource type based on the tag, such as GPU-intensive or CPU-intensive.
[0085] 4.2) Resource Scheduling Analysis and Optimization: Based on the acquired POD resources and tag information, the analysis module is called to filter out the optimal node. The specific steps are as follows: Step 1: Pass the POD information to the analysis module. The analysis module performs K-Means calculations to obtain the node information suitable for the POD; Step 2: Optimize scheduling. Based on the node information collected by the monitoring module, the optimization module updates the scheduling strategy according to the POD's SLA (Service Level Agreement). Step 3: Scheduling and binding: According to the optimized scheduling strategy, the optimal match is performed and the pod is evicted or bound.
[0086] The core goal of the embodiment of the present invention is to optimize the resource utilization of the container cluster, reduce the problem of resource fragmentation, and ensure the stability and efficiency of key services. Based on this, a multi-dimensional resource allocation optimization method for container clusters is proposed, which can support the optimization of multi-dimensional resources such as CPU, memory, GPU, storage bandwidth, etc. Multi-dimensional resource optimization can meet the needs of diversified business scenarios and improve the utilization of cluster resources. At the same time, by matching resources according to the POD business type, the cluster of mixed resources can maximize the use of nodes and reduce the node resource fragmentation rate. It can also dynamically adjust the resources according to the application type and reschedule the business on the node according to the application type.
[0087] The resource allocation device for a container cluster provided by the present invention is described below. The resource allocation device for a container cluster described below and the resource allocation method for a container cluster described above can be referenced to each other.
[0088] refer to Figure 4 , Figure 4 4. The resource allocation device for a container cluster provided by the present invention comprises: a feature vector determination module 401, a clustering module 402, a scheduling strategy determination module 403 and a scheduling module 404.
[0089] A feature vector determination module 401 is configured to determine a feature vector of each node based on the utilization rate, allocation rate, and fragmentation rate of the multi-dimensional resources of each node in the cluster; A clustering module 402 is configured to cluster the nodes based on the feature vectors of the nodes to obtain node clustering results; A scheduling strategy determination module 403 is configured to determine a POD scheduling strategy based on the node clustering result, the fragmented node set, and the priority of each container group POD in the cluster; The scheduling module 404 is configured to execute a scheduling operation of the POD based on the scheduling policy to allocate resources in the cluster.
[0090] The resource allocation device for a container cluster provided by an embodiment of the present invention determines the characteristic vector of each node based on the utilization rate, allocation rate, and fragmentation rate of the multi-dimensional resources of each node in the cluster; clusters the nodes based on the characteristic vectors of each node to obtain a node clustering result; determines the scheduling strategy of the POD based on the node clustering result, the fragmented node set, and the priority of each container group POD in the cluster; and executes the scheduling operation of the POD based on the scheduling strategy to allocate resources in the cluster. The present invention realizes multi-dimensional resource optimization by analyzing the utilization rate, allocation rate, and fragmentation rate of the multi-dimensional resources of the nodes and optimizing the fragmented nodes, thereby evenly allocating resources such as CPU, memory, GPU, and storage bandwidth, reducing resource waste, thereby improving the resource utilization of the container cluster and further improving the efficiency and stability of cluster resource management.
[0091] In one embodiment, the scheduling strategy determination module 403 is specifically configured to: Calculate the migration cost of each POD in each fragmented node in the fragmented node set based on the priority of each POD; Determining a POD to be migrated for each of the fragmented nodes based on the ranking information of the migration costs of the PODs; Determine the resource matching node of the POD to be migrated based on the node clustering result; A scheduling policy for the POD is generated based on the POD to be migrated and the resource matching node.
[0092] In one embodiment, the scheduling strategy determination module 403 is specifically configured to: Obtaining the priority weight corresponding to the priority of the POD; The ratio of the resource demand of the POD to the priority weight of the POD is used as the migration cost of the POD.
[0093] In one embodiment, the clustering module 402 is specifically configured to: Initializing clustering of the nodes based on the feature vectors of each node to obtain multiple clusters; Based on the distance between the feature vector of each node and the cluster center of each cluster, the node is assigned to the cluster with the shortest distance; updating the cluster center of each cluster based on the mean of the feature vectors of all nodes in each cluster; The cluster center update operation is iteratively performed until the number of clustering times reaches the maximum number of clustering times, thereby obtaining the node clustering result.
[0094] In one embodiment, the clustering module 402 is specifically configured to: The mean of the feature vectors of all nodes in each cluster is used as the new cluster center of each cluster.
[0095] In one embodiment, the fragmentation rate of the node includes the fragmentation rate of each resource of the node and the multi-dimensional resource fragmentation rate of the node; the fragmentation rate of each resource of the node and the multi-dimensional resource fragmentation rate are determined based on the following method: The ratio of the allocated amount of each resource to the total amount of each resource is taken as the fragmentation rate of each resource; The fragmentation rates of various resources in the node are weighted and summed to obtain the multi-dimensional resource fragmentation rate of the node.
[0096] Figure 5 An example of a physical structure diagram of an electronic device is shown below. Figure 5 As shown, the electronic device may include: a processor 510, a communication interface 520, a memory 530, and a communication bus 540, wherein the processor 510, the communication interface 520, and the memory 530 communicate with each other via the communication bus 540. The processor 510 may call logic instructions in the memory 530 to execute a resource allocation method for a container cluster, the method comprising: determining a feature vector of each node based on the utilization rate, allocation rate, and fragmentation rate of multi-dimensional resources of each node in the cluster; clustering the nodes based on the feature vectors of each node to obtain a node clustering result; determining a POD scheduling policy based on the node clustering result, the fragmented node set, and the priority of each container group POD in the cluster; and executing a POD scheduling operation based on the scheduling policy to allocate resources in the cluster.
[0097] Furthermore, the logic instructions in the aforementioned memory 530 can be implemented as software functional units and, when sold or used as independent products, can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention, or the portion that contributes to the prior art, or a portion of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions for causing a computer device (which can be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in various embodiments of the present invention. The aforementioned storage medium includes various media capable of storing program code, such as a USB flash drive, a mobile hard drive, a read-only memory (ROM), a random access memory (RAM), a magnetic disk, or an optical disk.
[0098] On the other hand, the present invention also provides a computer program product, which includes a computer program, which can be stored on a non-transitory computer-readable storage medium. When the computer program is executed by a processor, the computer can execute the resource allocation method for the container cluster provided by the above methods, the method including: determining the characteristic vector of each node based on the utilization rate, allocation rate and fragmentation rate of the multi-dimensional resources of each node in the cluster; clustering the nodes based on the characteristic vector of each node to obtain a node clustering result; determining the scheduling strategy of the POD based on the node clustering result, the fragmented node set and the priority of each container group POD in the cluster; and performing the scheduling operation of the POD based on the scheduling strategy to allocate resources in the cluster.
[0099] On the other hand, the present invention also provides a non-transitory computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, is implemented to execute the resource allocation method for the container cluster provided by the above-mentioned methods, the method comprising: determining the characteristic vector of each node based on the utilization rate, allocation rate and fragmentation rate of the multi-dimensional resources of each node in the cluster; clustering the nodes based on the characteristic vector of each node to obtain a node clustering result; determining the scheduling strategy of the POD based on the node clustering result, the fragmented node set and the priority of each container group POD in the cluster; and performing the scheduling operation of the POD based on the scheduling strategy to allocate resources in the cluster.
[0100] The device embodiments described above are merely illustrative. The units described as separate components may or may not be physically separate, and the components shown as units may or may not be physical units, i.e., they may be located in one location or distributed across multiple network units. Some or all of the modules may be selected based on actual needs to achieve the objectives of the present embodiment. Persons of ordinary skill in the art will be able to understand and implement the present invention without inventive effort.
[0101] Through the above description of the embodiments, those skilled in the art will clearly understand that each embodiment can be implemented using software plus a necessary general-purpose hardware platform, or of course, hardware. Based on this understanding, the essence of the above technical solution, or the portion that contributes to the prior art, can be embodied in the form of a software product. This computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, a magnetic disk, or an optical disk, and includes a number of instructions for causing a computer device (such as a personal computer, server, or network device) to execute the methods described in each embodiment or certain portions of the embodiments.
[0102] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit it. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the various embodiments of the present invention.
Claims
1. A resource allocation method for a container cluster, characterized in that: include: Determine the feature vector of each node based on the utilization rate, allocation rate, and fragmentation rate of the multi-dimensional resources of each node in the cluster; Clustering the nodes based on the feature vectors of each node to obtain a node clustering result; Determine a POD scheduling strategy based on the node clustering result, the fragmented node set, and the priority of each container group POD in the cluster; A scheduling operation of the POD is performed based on the scheduling policy to allocate resources in the cluster.
2. The resource allocation method for a container cluster according to claim 1, characterized in that: The determining of the POD scheduling strategy based on the node clustering result, the fragmented node set, and the priority of each container group POD in the cluster includes: Calculate the migration cost of each POD in each fragmented node in the fragmented node set based on the priority of each POD; Determining a POD to be migrated for each of the fragmented nodes based on the ranking information of the migration costs of the PODs; Determine the resource matching node of the POD to be migrated based on the node clustering result; A scheduling policy for the POD is generated based on the POD to be migrated and the resource matching node.
3. The resource allocation method for a container cluster according to claim 2, characterized in that: The migration cost of any POD is determined based on the following: Obtaining the priority weight corresponding to the priority of the POD; The ratio of the resource demand of the POD to the priority weight of the POD is used as the migration cost of the POD.
4. The resource allocation method for a container cluster according to claim 1, characterized in that: Clustering the nodes based on the feature vectors of the nodes to obtain node clustering results includes: Initializing clustering of the nodes based on the feature vectors of each node to obtain multiple clusters; Based on the distance between the feature vector of each node and the cluster center of each cluster, the node is assigned to the cluster with the shortest distance; updating the cluster center of each cluster based on the mean of the feature vectors of all nodes in each cluster; The cluster center update operation is iteratively performed until the number of clustering times reaches the maximum number of clustering times, thereby obtaining the node clustering result.
5. The resource allocation method for a container cluster according to claim 4, characterized in that: The updating of the cluster center of each cluster based on the mean of the feature vectors of all nodes in each cluster includes: The mean of the feature vectors of all nodes in each cluster is used as the new cluster center of each cluster.
6. The resource allocation method for a container cluster according to claim 1, characterized in that: The fragmentation rate of the node includes the fragmentation rate of each resource of the node and the multi-dimensional resource fragmentation rate of the node; the fragmentation rate of each resource of the node and the multi-dimensional resource fragmentation rate are determined based on the following method: The ratio of the allocated amount of each resource to the total amount of each resource is taken as the fragmentation rate of each resource; The fragmentation rates of various resources in the node are weighted and summed to obtain the multi-dimensional resource fragmentation rate of the node.
7. A resource allocation device for a container cluster, characterized in that: include: A feature vector determination module is used to determine the feature vector of each node based on the utilization rate, allocation rate and fragmentation rate of the multi-dimensional resources of each node in the cluster; A clustering module, configured to cluster the nodes based on the feature vectors of the nodes to obtain node clustering results; A scheduling strategy determination module is used to determine the scheduling strategy of the POD based on the node clustering result, the fragmented node set and the priority of each container group POD in the cluster; The scheduling module is used to perform a scheduling operation of the POD based on the scheduling policy to allocate resources in the cluster.
8. An electronic device comprising a memory, a processor, and a computer program stored in the memory and running on the processor, characterized in that: When the processor executes the computer program, the resource allocation method for the container cluster according to any one of claims 1 to 6 is implemented.
9. A non-transitory computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the resource allocation method for the container cluster is implemented.
10. A computer program product comprising a computer program, characterized in that When the computer program is executed by a processor, the resource allocation method for the container cluster is implemented.