Kubernetes cluster compression method and device, equipment and medium
By acquiring and scoring resource attribute information in a Kubernetes cluster and performing simulated scheduling to determine compressible nodes, the problem of one-sided resource evaluation and lack of a global perspective in existing technologies is solved. This enables accurate evaluation of cluster resource utilization efficiency and optimization of node compression, thereby improving stability and resource utilization efficiency.
Patent Information
- Application Number
- CN202511696727.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-11-18
- Publication Date
- 2026-02-13
AI Technical Summary
Existing technologies in Kubernetes clusters offer a one-sided view of resource assessment, ignoring the actual resource usage of Pods. This leads to node resource overload and performance degradation under high load scenarios. The lack of a global perspective and node compression assessment mechanism makes it impossible to optimize cluster resource utilization efficiency.
By acquiring resource attribute information of cluster nodes and Pod container groups, comprehensive scoring and ranking are performed, and scheduling is simulated to determine compressible nodes. Cluster compression results are generated, including compressible nodes and cluster compression ratio. Scoring and scheduling are performed using Kubernetes application programming interfaces and native scheduler logic.
It enables accurate assessment of resource utilization efficiency and node compression optimization while ensuring service stability, improves the stability of node reclamation and resource utilization efficiency, and quantitatively measures the matching degree between cluster size and resource allocation.
Smart Images

Figure CN121523802A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of computer technology, and in particular to a Kubernetes cluster compression method, apparatus, device, and medium. Background Technology
[0002] Against the backdrop of the rapid development of cloud-native technologies, Kubernetes (K8S) has become the de facto standard in the field of container orchestration, widely used in the deployment and management of enterprise applications. As cluster size continues to expand, issues such as low resource utilization and node redundancy become increasingly prominent, leading to a significant increase in operational costs. Currently, cluster resource optimization mainly relies on static threshold judgments of node resource utilization or simple scheduling strategies based on resource request volume, lacking a systematic evaluation of the overall cluster resource allocation efficiency.
[0003] In existing technologies, some solutions attempt to optimize cluster resource allocation through simulated scheduling or resource estimation, such as scheduling methods based on resource request volume. However, these methods generally suffer from the following problems: One-sided resource assessment: Relying solely on resource request volume for scheduling decisions ignores the actual resource usage of Pods, leading to node resource overload under high load scenarios, causing OOM (Out of Memory) or performance degradation. Lack of a global perspective: Existing methods focus primarily on the resource status of individual nodes, failing to evaluate resource allocation efficiency from the perspective of the entire cluster, making it difficult to detect system-level resource waste. Lack of compression evaluation mechanisms: Existing technologies mainly focus on resource scheduling and scaling, lacking simulation verification and quantitative evaluation mechanisms for cluster node compression, thus failing to provide a reliable basis for cluster scaling optimization.
[0004] As can be seen from the above, how to accurately assess the efficiency of Kubernetes cluster resource utilization and optimize node compression while ensuring service stability is an urgent problem to be solved. Summary of the Invention
[0005] In view of this, the purpose of this invention is to provide a Kubernetes cluster compression method, apparatus, device, and medium that can accurately assess the resource utilization efficiency of a Kubernetes cluster and optimize node compression while ensuring service stability. The specific solution is as follows:
[0006] Firstly, this application provides a Kubernetes cluster compression method, including:
[0007] The resource attribute information of all nodes and Pod container groups in the current cluster is obtained through the Kubernetes application programming interface. Based on the resource attribute information of the nodes and Pod container groups, the nodes are comprehensively scored and sorted to obtain a node list. The resource attribute information of the nodes includes the amount of node resources that can be allocated, the amount of node resources that have been allocated, and the amount of node resources actually used. The resource attribute information of the Pod container groups includes the amount of Pod container group resources requested and the amount of Pod container group resources actually used.
[0008] Based on the node list, the Pod container groups in the nodes are simulated and scheduled sequentially to obtain the simulation scheduling results;
[0009] Based on the simulation scheduling results, compressible nodes are determined from the nodes, and cluster compression results are generated based on the compressible nodes; the cluster compression results include the compressible nodes and the cluster compression ratio.
[0010] Optionally, the step of comprehensively scoring and sorting the nodes based on the resource attribute information of the nodes and the Pod container groups to obtain a node list includes:
[0011] Calculate the available memory capacity ratio and available commitment ratio of the node based on the resource attribute information of the node and the Pod container group in the node;
[0012] The available memory capacity ratio and the available commitment ratio are mapped to a preset scoring range, and a comprehensive score for the node is generated based on the mapping result using preset weighting coefficients; the comprehensive score for the node includes a memory resource score and a central processing unit resource score.
[0013] The nodes are sorted based on their comprehensive scores to obtain a node list.
[0014] Optionally, the node's available memory capacity ratio is the difference between 1 and a first target ratio; the available commitment ratio is the difference between 1 and a second target ratio.
[0015] Wherein, the first target ratio is the ratio of the actual usage of node resources to the allocatable amount of node resources; the second target ratio is the ratio of the sum of resource requests of all Pod container groups to the allocatable amount of node resources.
[0016] Optionally, the step of simulating scheduling of Pod container groups in the nodes sequentially based on the node list to obtain simulation scheduling results includes:
[0017] Based on the node list, the resource request amount and actual resource usage of the Pod container group in the current node are compared. If the actual resource usage of the Pod container group is greater than the resource request amount, the value of the resource request amount of the Pod container group is temporarily updated to the value of the actual resource usage of the Pod container group during the simulation scheduling process.
[0018] Based on the native Kubernetes scheduler logic, any Pod container group of the current node is simulated to be scheduled to other nodes. A preset scoring plugin is used to give a comprehensive score to the scheduled node based on the resource attribute information of the node and the Pod container group in the node. Based on the comprehensive score of the scheduled node, it is determined whether the current Pod container group can be successfully scheduled.
[0019] If there are no successfully scheduled Pod container groups in the current node, the current node is marked as an incompressible node, and the Pod container groups in the next node in the node list are simulated for scheduling until all nodes in the node list are traversed to obtain the simulation scheduling result.
[0020] Optionally, before performing simulated scheduling on the Pod container groups in the nodes sequentially based on the node list to obtain the simulated scheduling result, the method further includes:
[0021] Initialize all nodes to an incompressible state and create a full snapshot of the current cluster nodes and Pod container group information;
[0022] If the Pod container group in the node cannot be successfully simulated and scheduled, the cluster state is restored using the full snapshot.
[0023] Optionally, the cluster compression ratio is the ratio of the number of compressible nodes to the total number of cluster nodes.
[0024] Optionally, the Kubernetes cluster compression method further includes:
[0025] The cluster compression result is output in a preset format;
[0026] The preset formats include JSON, YAML, and table formats.
[0027] Secondly, this application provides a Kubernetes cluster compression device, comprising:
[0028] The node list generation module is used to obtain resource attribute information of all nodes and Pod container groups in the current cluster through the Kubernetes application programming interface, and to perform comprehensive scoring and sorting of the nodes based on the resource attribute information of the nodes and Pod container groups to obtain a node list; the resource attribute information of the nodes includes the node's allocable resources, the node's allocated resources, and the node's actual resource usage; the resource attribute information of the Pod container groups includes the Pod container group's resource request volume and the Pod container group's actual resource usage.
[0029] The simulation scheduling module is used to simulate scheduling the Pod container groups in the nodes sequentially based on the node list, so as to obtain the simulation scheduling result;
[0030] The cluster compression result generation module is used to determine compressible nodes from the nodes based on the simulation scheduling results, and generate cluster compression results based on the compressible nodes; the cluster compression results include the compressible nodes and the cluster compression ratio.
[0031] Thirdly, this application provides an electronic device, comprising:
[0032] Memory, used to store computer programs;
[0033] A processor is used to execute the computer program to implement the aforementioned Kubernetes cluster compression method.
[0034] Fourthly, this application provides a computer-readable storage medium for storing a computer program, wherein the computer program, when executed by a processor, implements the aforementioned Kubernetes cluster compression method.
[0035] This application provides a Kubernetes cluster compression method. It obtains resource attribute information of all nodes and Pod container groups in the current cluster through the Kubernetes application programming interface (API), and performs a comprehensive scoring and sorting of the nodes based on the resource attribute information to obtain a node list. The node resource attribute information includes the node's allocable resources, the amount of resources already allocated, and the actual amount of resources used. The Pod container group resource attribute information includes the Pod container group's resource request amount and the actual amount of resources used. Based on the node list, the Pod container groups in the nodes are simulated and scheduled sequentially to obtain a simulation scheduling result. Based on the simulation scheduling result, compressible nodes are determined from the nodes, and a cluster compression result is generated based on the compressible nodes. The cluster compression result includes the compressible nodes and the cluster compression ratio.
[0036] As shown above, this application proposes a quantitative metric called "cluster compression ratio," which can intuitively reflect the resource utilization efficiency of a Kubernetes cluster. It also allows for a simple, convenient, fast, and efficient determination of the number of redundant nodes in the cluster and quantitatively measures the degree of matching between the cluster size and actual resource allocation and load. By adding a scoring and scheduling function for actual resource usage, the stability of cluster node reclamation is improved. This achieves accurate assessment of Kubernetes cluster resource utilization efficiency and node compression optimization while ensuring service stability. Attached Figure Description
[0037] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on the provided drawings without creative effort.
[0038] Figure 1 This is a flowchart of a Kubernetes cluster compression method disclosed in this application;
[0039] Figure 2 This application discloses a specific Kubernetes cluster compression method flowchart;
[0040] Figure 3 This is a schematic diagram of a Kubernetes cluster compression device disclosed in this application;
[0041] Figure 4 This is a structural diagram of an electronic device disclosed in this application. Detailed Implementation
[0042] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0043] In existing technologies, some solutions attempt to optimize cluster resource allocation through simulated scheduling or resource estimation, such as scheduling methods based on resource request volume. However, these methods generally suffer from the following problems: One-sided resource assessment: Relying solely on resource request volume for scheduling decisions ignores the actual resource usage of Pods, leading to node resource overload under high load scenarios, causing OOM (Out of Memory) or performance degradation. Lack of a global perspective: Existing methods focus primarily on the resource status of individual nodes, failing to assess resource allocation efficiency from the perspective of the entire cluster, making it difficult to detect system-level resource waste. Lack of compression evaluation mechanisms: Existing technologies mainly focus on resource scheduling and scaling, lacking simulation verification and quantitative evaluation mechanisms for cluster node compression, thus failing to provide a reliable basis for cluster scaling optimization. Therefore, this application provides a Kubernetes cluster compression scheme that can achieve accurate evaluation of Kubernetes cluster resource utilization efficiency and node compression optimization while ensuring service stability.
[0044] See Figure 1 As shown in the figure, this application discloses a Kubernetes cluster compression method, including:
[0045] Step S11: Obtain the resource attribute information of all nodes and Pod container groups in the current cluster through the Kubernetes application programming interface, and perform comprehensive scoring and sorting on the nodes based on the resource attribute information of the nodes and Pod container groups to obtain a node list.
[0046] In this embodiment, the cluster compression assessment begins with an initialization process. This involves initializing the assessment variables used for statistics and tracking, and mapping node resource information into the memory of the compression assessment program. Subsequently, by calling the Kubernetes application programming interface (API), the attribute information of all nodes in the current cluster is obtained, including but not limited to the node's available resources, allocated resources, and actual resource usage. Simultaneously, the attribute information of all Pod container groups is obtained, including the Pod container group's resource request volume and actual resource usage. Obtaining the key indicator of actual resource usage lays the foundation for accurate node load assessment and stable simulation scheduling. The node resource attribute information includes, but is not limited to, the node's available resources, allocated resources, and actual resource usage; the Pod container group resource attribute information includes, but is not limited to, the Pod container group's resource request volume and actual resource usage.
[0047] Furthermore, all nodes are marked as incompressible; then, a weighted geometric mean scoring model is used to comprehensively score the actual use of CPU and memory resources allocated to each node, and the nodes are sorted according to their scores. A higher score indicates that the node has more allocable and usable resources. Specifically, the comprehensive scoring and sorting of nodes based on the resource attribute information of the nodes and the Pod container groups to obtain a node list may include: calculating the available memory capacity ratio and available commitment ratio of the node based on the resource attribute information of the node and the Pod container groups within the node; mapping the available memory capacity ratio and the available commitment ratio to a preset scoring range, and generating a comprehensive score for the node based on the mapping result using preset weighting coefficients; the comprehensive score of the node includes a memory resource score and a CPU resource score; and sorting the nodes based on the comprehensive score to obtain a node list. That is, first, the available memory capacity ratio and available commitment ratio are calculated. Then, the above ratios are mapped to a scoring range of 0-100, and the memory resource score and CPU resource score are calculated using a weighted geometric mean based on preset capacity weights and commitment weights. The weight coefficients are values greater than 0, and the sum of the capacity weight and commitment weight is 1. Finally, the node's overall score is the sum of its memory resource score and CPU resource score. Specifically, the node's available memory capacity ratio is the difference between 1 and a first target ratio; the available commitment ratio is the difference between 1 and a second target ratio; the first target ratio is the ratio of the node's actual resource usage to its allocatable resources; and the second target ratio is the ratio of the sum of resource requests from all Pod container groups to the node's allocatable resources. A higher overall score indicates more resources available for allocation and use, making the node a more likely candidate for compression.
[0048] Step S12: Based on the node list, simulate scheduling the Pod container groups in the nodes in sequence to obtain the simulation scheduling results.
[0049] In this embodiment, all PODs on a node are traversed and simulated for scheduling to other incompressible nodes. Before scheduling, the resource request and usage of the POD are compared. If the actual resource usage is greater than the resource request, the POD's resource request is updated to the actual resource usage; otherwise, it remains unchanged. Then, the POD is simulated for scheduling. The POD simulation scheduling integrates the native Kubernetes scheduling logic and adds a score for the actual resource usage of the node. In other words, an actual resource usage scoring plugin is added to the scheduler plugin system. The specific scoring logic is consistent with the comprehensive scoring logic in step S11. This allows for a more comprehensive assessment of the node's load and pressure, avoiding scheduling risks caused by focusing only on the resource request and ignoring the resources already used. Specifically, the step of simulating scheduling Pod container groups in the nodes sequentially based on the node list to obtain simulation scheduling results may include: comparing the resource request amount and actual resource usage of Pod container groups in the current node based on the node list; if the actual resource usage of the Pod container group is greater than the resource request amount, the value of the resource request amount is temporarily updated to the value of the actual resource usage during the simulation scheduling process; simulating scheduling any Pod container group in the current node to other nodes based on the native Kubernetes scheduler logic, and using a preset scoring plugin to comprehensively score the scheduled nodes based on the node and the resource attribute information of the Pod container groups in the node, and determining whether the current Pod container group can be successfully scheduled based on the comprehensive score of the scheduled nodes; if there are no successfully scheduled Pod container groups in the current node, the current node is marked as an incompressible node, and the Pod container groups in the next node in the node list are simulated for scheduling, until all nodes in the node list are traversed to obtain simulation scheduling results.
[0050] Furthermore, a full snapshot of node and POD information is taken. This snapshot data includes all attributes and resource allocation and usage of the current nodes and PODs. If a POD within a node cannot be successfully scheduled in the simulation, the node is ultimately rendered incompressible, and the node and POD information snapshot is restored first; then, compression simulation is performed on the next node. Specifically, before simulating scheduling of Pod container groups within a node based on the node list to obtain the simulation scheduling result, the process may further include: initializing all nodes to an incompressible state and creating a full snapshot of the current cluster node and Pod container group information; if the Pod container group within a node cannot be successfully scheduled in the simulation, the cluster state is restored using the full snapshot. The full snapshot and restoration mechanism is a key technical guarantee for achieving "safe, accurate, and reliable" cluster compression simulation evaluation in this solution. It ensures that the evaluation process itself does not introduce new unstable factors, thus making the final compression recommendations more credible.
[0051] Step S13: Based on the simulation scheduling results, determine the compressible nodes from the nodes, and generate cluster compression results based on the compressible nodes.
[0052] In this embodiment, the cluster compression result includes the compressible nodes and the cluster compression ratio, whereby the cluster compression ratio is the ratio of the number of compressible nodes to the total number of nodes in the cluster. That is, by calculating the cluster compression ratio, the resource utilization efficiency of the Kubernetes cluster is reflected, the number of redundant nodes in the cluster is determined, and the degree of matching between the cluster size and the actual resource allocation and load is quantitatively measured.
[0053] Furthermore, the cluster compression results are output in a preset format, which can display only the names of compressible nodes, the compression ratio of nodes, or the cluster resource usage. The preset format includes, but is not limited to, JSON, YAML, and table formats.
[0054] As can be seen from the above, this application proposes a quantitative indicator of "cluster compression ratio," which can intuitively reflect the resource utilization efficiency of a Kubernetes cluster. It also allows for a simple, convenient, fast, and efficient determination of the number of redundant nodes in the cluster and quantitatively measures the degree of matching between the cluster size and actual resource allocation and load. By adding a score and scheduling based on actual resource usage, the stability of cluster node reclamation is improved. This achieves accurate assessment of Kubernetes cluster resource utilization efficiency and node compression optimization while ensuring service stability.
[0055] See Figure 2 As shown in the figure, this application discloses a specific Kubernetes cluster compression method, including:
[0056] In this embodiment, a cluster compression assessment is performed, and a node compression simulation assessment of the current cluster is conducted; compression assessment variables and resource mappings are initialized, variables used for statistics and tracking are initialized, and node resources are mapped into the memory of the compression assessment program; the current cluster node and POD information is loaded, and all attributes of the current cluster nodes, as well as the allocable, allocated, and actual usage of resources, are obtained through the Kubernetes API, and all attributes of the current cluster PODs, as well as the POD resource request and actual usage are obtained.
[0057] Furthermore, a comprehensive scoring and ranking of nodes is performed based on the current cluster node and POD information. First, all nodes are marked as incompressible; then, a weighted geometric mean scoring model is used to comprehensively score the actual use of CPU and memory resources allocated to each node, and the nodes are ranked according to their scores. The higher the score, the more resources that the node can allocate and use.
[0058] Furthermore, node compression simulation is performed on the sorted node list; a full snapshot of node and POD information is taken, containing all attributes and resource allocation and usage of the current node and POD; all PODs on a node are traversed and simulated for scheduling to other incompressible nodes. Before scheduling, the resource request and usage of the POD are compared. If the actual resource usage is greater than the resource request, the POD's resource request is updated to the actual resource usage; otherwise, it remains unchanged. Then, the POD is simulated for scheduling. The POD simulation scheduling integrates the native Kubernetes scheduling logic and adds an additional score for the actual resource usage of the node. In other words, an actual resource usage scoring plugin is added to the scheduler plugin system, with the specific scoring logic as described above. This allows for a more comprehensive assessment of the node's load and pressure, avoiding scheduling risks caused by focusing only on resource request and ignoring the resources already used. If a POD on a node cannot be successfully simulated for scheduling, the node is ultimately incompressible, and a snapshot of the node and POD information is restored. Then, compression simulation is performed on the next node. The cluster compression ratio is the ratio of the number of compressible nodes to the total number of nodes in the cluster.
[0059] Furthermore, after traversing all nodes, the cluster compression evaluation results are output. The results can be output in a custom format, such as json, yaml, table, etc. The results can show only the names of the compressible nodes, or the compression ratio of the nodes, or the cluster resource usage.
[0060] As can be seen from the above, this application proposes a quantitative indicator of "cluster compression ratio," which can intuitively reflect the resource utilization efficiency of a K8S cluster. It also allows for a simple, convenient, fast, and efficient determination of the number of redundant nodes in the cluster and quantitatively measures the degree of matching between the cluster size and actual resource allocation and load. By adding a score and scheduling based on actual resource usage, the stability of cluster node reclamation is improved. Performing cluster compression evaluation via command line further facilitates the addition of a score and scheduling based on actual resource usage, resulting in higher cluster stability after node reclamation.
[0061] See Figure 3 As shown in the figure, this application discloses a Kubernetes cluster compression device, including:
[0062] The node list generation module 11 is used to obtain resource attribute information of all nodes and Pod container groups in the current cluster through the Kubernetes application programming interface, and to perform comprehensive scoring and sorting of the nodes based on the resource attribute information of the nodes and Pod container groups to obtain a node list; the resource attribute information of the nodes includes the amount of node resources that can be allocated, the amount of node resources that have been allocated, and the amount of node resources actually used; the resource attribute information of the Pod container groups includes the amount of Pod container group resource requests and the amount of Pod container group resources actually used.
[0063] The simulation scheduling module 12 is used to perform simulated scheduling on the Pod container groups in the nodes in sequence based on the node list, so as to obtain the simulation scheduling result.
[0064] The cluster compression result generation module 13 is used to determine compressible nodes from the nodes based on the simulation scheduling results, and generate cluster compression results based on the compressible nodes; the cluster compression result includes the compressible nodes and the cluster compression ratio; the cluster compression ratio is the ratio of the number of compressible nodes to the total number of cluster nodes.
[0065] In some specific embodiments, the node list generation module 11 may specifically include:
[0066] A ratio calculation unit is used to calculate the memory available capacity ratio and available commitment ratio of the node based on the node and the resource attribute information of the Pod container groups in the node; the memory available capacity ratio of the node is the difference between 1 and a first target ratio; the available commitment ratio is the difference between 1 and a second target ratio; the first target ratio is the ratio of the actual resource usage of the node to the allocatable resource of the node; the second target ratio is the ratio of the sum of the resource requests of all Pod container groups to the allocatable resource of the node;
[0067] A ratio mapping unit is used to map the available memory capacity ratio and the available commitment ratio to a preset scoring range, and to generate a comprehensive score for the node based on the mapping result using preset weighting coefficients; the comprehensive score for the node includes a memory resource score and a central processing unit resource score.
[0068] The list generation unit is used to sort the nodes based on their comprehensive scores to obtain a list of nodes.
[0069] In some specific embodiments, the simulation scheduling module 12 may specifically include:
[0070] The resource request update unit is used to compare the resource request of the Pod container group in the current node with the actual resource usage of the Pod container group based on the node list. If the actual resource usage of the Pod container group is greater than the resource request of the Pod container group, the value of the resource request of the Pod container group is temporarily updated to the value of the actual resource usage of the Pod container group during the simulation scheduling process.
[0071] The simulation scheduling unit is used to simulate scheduling any Pod container group of the current node to other nodes based on the native Kubernetes scheduler logic, and to use a preset scoring plugin to give a comprehensive score to the scheduled node based on the resource attribute information of the node and the Pod container group in the node, and to determine whether the current Pod container group can be successfully scheduled based on the comprehensive score of the scheduled node.
[0072] The result generation unit is used to mark the current node as an incompressible node if there is no successfully schedulable Pod container group in the current node, and to simulate scheduling the Pod container group in the next node in the node list until all nodes in the node list are traversed to obtain the simulation scheduling result.
[0073] In some specific embodiments, the Kubernetes cluster compression device may further include:
[0074] The node initialization unit is used to initialize all nodes to an incompressible state and create a full snapshot of the current cluster nodes and Pod container group information.
[0075] The node restoration unit is used to restore the cluster state using the full snapshot if the Pod container group in the node fails to be successfully simulated for scheduling.
[0076] The result output unit is used to output the cluster compression result in a preset format; the preset format includes JSON format, YAML format and table format.
[0077] Furthermore, embodiments of this application also disclose an electronic device, Figure 4 This is a structural diagram of an electronic device 20 according to an exemplary embodiment. The content of the diagram should not be construed as limiting the scope of this application. The electronic device 20 may specifically include: at least one processor 21, at least one memory 22, a power supply 23, a communication interface 24, an input / output interface 25, and a communication bus 26. The memory 22 stores a computer program, which is loaded and executed by the processor 21 to implement the relevant steps in the Kubernetes cluster compression method disclosed in any of the foregoing embodiments. Furthermore, the electronic device 20 in this embodiment may specifically be an electronic computer.
[0078] In this embodiment, the power supply 23 is used to provide operating voltage for each hardware device on the electronic device 20; the communication interface 24 can create a data transmission channel between the electronic device 20 and external devices, and the communication protocol it follows can be any communication protocol applicable to the technical solution of this application, and is not specifically limited here; the input / output interface 25 is used to acquire external input data or output data to the outside world, and its specific interface type can be selected according to specific application needs, and is not specifically limited here.
[0079] In addition, the memory 22, as a carrier for resource storage, can be a read-only memory, random access memory, disk or optical disk, etc. The resources stored thereon can include operating system 221, computer program 222, etc., and the storage method can be temporary storage or permanent storage.
[0080] The operating system 221 is used to manage and control the various hardware devices on the electronic device 20 and the computer program 222, which may be Windows Server, Netware, Unix, Linux, etc. In addition to including a computer program capable of performing the Kubernetes cluster compression method executed by the electronic device 20 as disclosed in any of the foregoing embodiments, the computer program 222 may further include computer programs capable of performing other specific tasks.
[0081] Furthermore, this application also discloses a computer-readable storage medium for storing a computer program; wherein, when the computer program is executed by a processor, it implements the aforementioned disclosed Kubernetes cluster compression method. Specific steps of this method can be found in the corresponding content disclosed in the foregoing embodiments, and will not be repeated here.
[0082] The various embodiments in this specification are described in a progressive manner, with each embodiment focusing on its differences from other embodiments. Similar or identical parts between embodiments can be referred to interchangeably. For the apparatus disclosed in the embodiments, since it corresponds to the method disclosed in the embodiments, the description is relatively simple; relevant parts can be referred to in the method section.
[0083] Those skilled in the art will further recognize that the units and algorithm steps of the various examples described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of both. To clearly illustrate the interchangeability of hardware and software, the components and steps of the various examples have been generally described in terms of functionality in the foregoing description. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of this application.
[0084] The steps of the methods or algorithms described in conjunction with the embodiments disclosed herein can be implemented directly by hardware, a software module executed by a processor, or a combination of both. The software module can be located in random access memory (RAM), main memory, read-only memory (ROM), electrically programmable ROM, electrically erasable programmable ROM, registers, hard disk, removable disk, CD-ROM, or any other form of storage medium known in the art.
[0085] Finally, it should be noted that in this document, relational terms such as "first" and "second" are used only to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element.
[0086] The technical solutions provided in this application have been described in detail above. Specific examples have been used to illustrate the principles and implementation methods of this application. The descriptions of the above embodiments are only for the purpose of helping to understand the methods and core ideas of this application. At the same time, for those skilled in the art, there will be changes in the specific implementation methods and application scope based on the ideas of this application. Therefore, the content of this specification should not be construed as a limitation of this application.
Claims
1. A compression method for a Kubernetes cluster, characterized in that, include: The resource attribute information of all nodes and Pod container groups in the current cluster is obtained through the Kubernetes application programming interface. Based on the resource attribute information of the nodes and Pod container groups, the nodes are comprehensively scored and sorted to obtain a node list. The resource attribute information of the nodes includes the amount of node resources that can be allocated, the amount of node resources that have been allocated, and the amount of node resources that have actually been used. The resource attribute information of the Pod container group includes the resource request amount of the Pod container group and the actual resource usage of the Pod container group. Based on the node list, the Pod container groups in the nodes are simulated and scheduled sequentially to obtain the simulation scheduling results; Based on the simulation scheduling results, compressible nodes are determined from the nodes, and cluster compression results are generated based on the compressible nodes. The cluster compression result includes the compressible nodes and the cluster compression ratio.
2. The Kubernetes cluster compression method according to claim 1, characterized in that, The nodes are comprehensively scored and sorted based on the resource attribute information of the nodes and the Pod container groups to obtain a node list, including: Calculate the memory availability ratio and available commitment ratio of the node based on the resource attribute information of the node and the Pod container group in the node; The available memory capacity ratio and the available commitment ratio are mapped to a preset scoring range, and a comprehensive score for the node is generated based on the mapping result using preset weighting coefficients; the comprehensive score for the node includes a memory resource score and a central processing unit resource score. The nodes are sorted based on their comprehensive scores to obtain a node list.
3. The Kubernetes cluster compression method according to claim 2, characterized in that, The node's available memory capacity ratio is the difference between 1 and the first target ratio; the available commitment ratio is the difference between 1 and the second target ratio; Wherein, the first target ratio is the ratio of the actual usage of node resources to the allocatable amount of node resources; the second target ratio is the ratio of the sum of resource requests of all Pod container groups to the allocatable amount of node resources.
4. The Kubernetes cluster compression method according to claim 1, characterized in that, The simulated scheduling of Pod container groups in the nodes is performed sequentially based on the node list to obtain the simulated scheduling results, including: Based on the node list, the resource request amount and actual resource usage of the Pod container group in the current node are compared. If the actual resource usage of the Pod container group is greater than the resource request amount, the value of the resource request amount of the Pod container group is temporarily updated to the value of the actual resource usage of the Pod container group during the simulation scheduling process. Based on the native Kubernetes scheduler logic, any Pod container group of the current node is simulated to be scheduled to other nodes. A preset scoring plugin is used to give a comprehensive score to the scheduled node based on the resource attribute information of the node and the Pod container group in the node. Based on the comprehensive score of the scheduled node, it is determined whether the current Pod container group can be successfully scheduled. If there are no successfully scheduled Pod container groups in the current node, the current node is marked as an incompressible node, and the Pod container groups in the next node in the node list are simulated for scheduling until all nodes in the node list are traversed to obtain the simulation scheduling result.
5. The Kubernetes cluster compression method according to claim 1, characterized in that, Before performing simulated scheduling on the Pod container groups in the nodes sequentially based on the node list to obtain the simulated scheduling result, the process also includes: Initialize all nodes to an incompressible state and create a full snapshot of the current cluster nodes and Pod container group information; If the Pod container group in the node cannot be successfully simulated and scheduled, the cluster state is restored using the full snapshot.
6. The Kubernetes cluster compression method according to claim 1, characterized in that, The cluster compression ratio is the ratio of the number of compressible nodes to the total number of nodes in the cluster.
7. The Kubernetes cluster compression method according to any one of claims 1 to 6, characterized in that, Also includes: The cluster compression result is output in a preset format; The preset formats include JSON, YAML, and table formats.
8. A Kubernetes cluster compression device, characterized in that, include: The node list generation module is used to obtain resource attribute information of all nodes and Pod container groups in the current cluster through the Kubernetes application programming interface, and to perform comprehensive scoring and sorting of the nodes based on the resource attribute information of the nodes and Pod container groups to obtain a node list; the resource attribute information of the nodes includes the node's allocable resources, the node's allocated resources, and the node's actual resource usage; the resource attribute information of the Pod container groups includes the Pod container group's resource request volume and the Pod container group's actual resource usage. The simulation scheduling module is used to perform simulated scheduling on the Pod container groups in the nodes in sequence based on the node list, so as to obtain the simulation scheduling result; The cluster compression result generation module is used to determine compressible nodes from the nodes based on the simulation scheduling results, and generate cluster compression results based on the compressible nodes; The cluster compression result includes the compressible nodes and the cluster compression ratio.
9. An electronic device, characterized in that, include: Memory, used to store computer programs; A processor for executing the computer program to implement the Kubernetes cluster compression method as described in any one of claims 1 to 7.
10. A computer-readable storage medium, characterized in that, Used to store computer programs, wherein the computer programs, when executed by a processor, implement the Kubernetes cluster compression method as described in any one of claims 1 to 7.