K8s cluster capacity reduction method and device, electronic equipment and storage medium
By obtaining the status information of the K8s cluster nodes and determining the nodes to be offline, ensuring that all pods can be evicted and then offline, the problem of resource release in the cloud computing environment affecting the stability of business services is solved, and the elegant resource release is achieved.
Patent Information
- Application Number
- CN202510101479.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-01-22
- Publication Date
- 2025-05-23
AI Technical Summary
In a cloud computing environment, the use of hybrid cloud models and business resources will experience peak and trough, resulting in the resource expansion during the peak period of business needs to be released during the business trough period. However, direct release of resources will affect the stability of business services.
By obtaining the node status information in the K8s cluster, determine the nodes to be offline that meet the preset node downlink requirements, and perform offline when all pods can be expelled to complete the cluster reduction.
It achieves the elegant release of resources without affecting the stability of business services, and solves the problem of the impact of resource release on business services stability.
Smart Images

Figure CN120034538A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of cloud computing technology, and in particular to a K8s cluster scaling method and device, an electronic device, and a storage medium. Background Art
[0002] The current hybrid cloud model and business resource usage will have peaks and troughs. For resources that are expanded during business peak periods, they need to be released during business troughs to save costs. However, during the trough period, a small number of business services will also run on the offline machines. If the machines are released directly, the availability of business services will decrease or even become unavailable during the release of the machines. Therefore, how to release resources gracefully without affecting the stability of business services is a technical problem that needs to be solved urgently.
[0003] Therefore, there is a problem in the related technology that releasing resources will affect the stability of business services. Summary of the invention
[0004] The present application provides a K8s cluster scaling method and device, an electronic device and a storage medium, so as to at least solve the problem in the related art that releasing resources may affect the stability of business services.
[0005] According to one aspect of an embodiment of the present application, a K8s cluster scaling method is provided, including:
[0006] Get the node status information of the nodes in the target K8s cluster;
[0007] Based on the node status information, determine the nodes to be offline that meet the preset node offline requirements among all nodes;
[0008] When it is determined that all Pods on the node to be taken offline can be evicted, the node to be taken offline is taken offline to complete the scaling down of the target K8s cluster.
[0009] Optionally, as in the aforementioned method, determining, based on the node status information, the node to be offline that meets the preset node offline requirement among all nodes includes:
[0010] Determine the offline priority of each node based on a preset evaluation strategy and the node status information of each node;
[0011] According to the order of offline priority from high to low and the node status information of each node, the nodes to be offline that meet the preset node offline requirements are determined in turn from all the nodes.
[0012] Optionally, as in the aforementioned method, the step of determining the node to be offline that meets the preset node offline requirement among all the nodes includes:
[0013] When it is determined that the Pod in any node meets the preset Pod eviction requirement, and the Pod in any node can be scheduled to other nodes among all the nodes except the any node, the any node is determined to be the node to be offline that meets the preset node offline requirement.
[0014] Optionally, as in the aforementioned method, the preset Pod eviction requirement includes at least one of the following:
[0015] The Pod's service is not a global single point, it can be evicted if the Pod's service is a global single point, the proportion of Pods corresponding to the same business in any node to the total number of Pods for the business does not exceed a preset proportion, and the Pod creation exceeds a preset duration T, wherein the preset duration is used to indicate the duration required for other services to start when the Pod's service is dependent on other services.
[0016] Optionally, as in the aforementioned method, the determining that all Pods on the node to be offline can be evicted includes:
[0017] Pre-evict all Pods on the node to be taken offline;
[0018] When it is determined that all the Pods are pre-evicted successfully, it is determined that all the Pods on the node to be taken offline can be evicted.
[0019] Optionally, as in the aforementioned method, taking the node to be taken offline offline comprises:
[0020] Determine whether there is a target Pod in the node to be taken offline, wherein the target Pod is a Pod that needs to run for a specific period of time before it ends;
[0021] When it is determined that the target Pod exists in the node to be taken offline, the node to be taken offline is taken offline after it is determined that the target Pod has been running for a specific time.
[0022] Optionally, as in the foregoing method, the node status information includes:
[0023] The node CPU usage, the node memory usage, the number of Pods on the node, and the node's historical offline failures, wherein the node CPU usage, the node memory usage, the number of Pods on the node, and the node's historical offline failures are negatively correlated with the offline priority.
[0024] According to another aspect of the embodiments of the present application, there is also provided a K8s cluster scaling-down device, including:
[0025] An acquisition module, configured to acquire the node status information of the nodes in the target K8s cluster;
[0026] A determination module, configured to determine, based on the node status information, the nodes to be taken offline that meet the preset node offline requirements among all the nodes;
[0027] An offline module, configured to take offline the nodes to be taken offline when it is determined that all the Pods on the nodes to be taken offline can be evicted, and complete the scaling-down of the target K8s cluster.
[0028] According to yet another aspect of the embodiments of the present application, there is also provided an electronic device, including a processor, a communication interface, a memory, and a communication bus. Among them, the processor, the communication interface, and the memory complete communication with each other through the communication bus; among them, the memory is used to store a computer program; the processor is configured to execute the method steps in any of the above embodiments by running the computer program stored on the memory.
[0029] According to yet another aspect of the embodiments of the present application, there is also provided a computer-readable storage medium, in which a computer program is stored. Among them, the computer program is set to execute the method steps in any of the above embodiments when running.
[0030] In the embodiments of the present application, by acquiring the node status information of the nodes in the target K8s cluster; determining, based on the node status information, the nodes to be taken offline that meet the preset node offline requirements among all the nodes; and taking offline the nodes to be taken offline when it is determined that all the Pods on the nodes to be taken offline can be evicted, the scaling-down of the K8s cluster is completed. Since in the K8s cluster, services run in Pods, the nodes to be taken offline are determined based on the node status information, and the nodes to be taken offline are taken offline only when all the Pods on the nodes to be taken offline can be evicted, so as to achieve the purpose that the offline of the nodes will not affect the services, and achieve the technical effect that releasing resources will not affect the stability of the business services, thereby solving the problem in the related art that releasing resources will affect the stability of the business services. BRIEF DESCRIPTION OF THE DRAWINGS
[0031] The accompanying drawings here are incorporated into the specification and constitute a part of this specification, showing the embodiments consistent with the present application, and are used together with the specification to explain the principles of the present application.
[0032] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, for ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative labor.
[0033] Figure 1 It is a schematic diagram of a hardware environment of an optional K8s cluster scaling method according to an embodiment of the present application;
[0034] Figure 2 It is a flowchart of an optional K8s cluster scaling method according to an embodiment of the present application;
[0035] Figure 3 It is a flowchart of an optional K8s cluster scaling method according to another embodiment of the present application;
[0036] Figure 4 It is a structural block diagram of an optional K8s cluster capacity reduction device according to an embodiment of the present application;
[0037] Figure 5 It is a structural block diagram of an optional electronic device according to an embodiment of the present application. DETAILED DESCRIPTION
[0038] In order to enable those skilled in the art to better understand the solution of the present application, the technical solution in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work should fall within the scope of protection of the present application.
[0039] It should be noted that the terms "first", "second", etc. in the specification and claims of the present application and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchangeable where appropriate, so that the embodiments of the present application described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any of their variations are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device comprising a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.
[0040] First, some nouns or terms that appear in the description of the embodiments of the present application are subject to the following interpretation:
[0041] 1. K8s, or Kubernetes, is an open source container orchestration system that automates the deployment, expansion, and management of containerized applications. The main goal of Kubernetes is to simplify the management and operation of containerized applications and improve the reliability and scalability of applications.
[0042] 2. Pod: Pod is the smallest deployable unit in Kubernetes. A Pod encapsulates one or more containers, which share storage and network resources and are scheduled and managed as a whole. Pod is designed to support multiple collaborative processes (containers) running together and sharing the same context and resources.
[0043] 3. Scaling refers to reducing the number of replicas of an application or service in K8s to adapt to lower workloads or save resources.
[0044] According to one aspect of an embodiment of the present application, a K8s cluster scaling method is provided. Optionally, in this embodiment, the K8s cluster scaling method can be applied to Figure 1 In the hardware environment composed of terminal 1402 and server 1404 shown in FIG. Figure 1 As shown, server 1404 is connected to terminal 1402 via a network, and can be used to provide services (such as game services, application services, etc.) for the terminal or a client installed on the terminal. A database can be set up on the server or independently of the server to provide data storage services for server 1404.
[0045] The above network may include but is not limited to at least one of the following: wired network, wireless network. The above wired network may include but is not limited to at least one of the following: wide area network, metropolitan area network, local area network, and the above wireless network may include but is not limited to at least one of the following: WIFI (Wireless Fidelity), Bluetooth. The terminal may not be limited to a PC, a mobile phone, a tablet computer, etc.
[0046] The K8s cluster shrinking method of the embodiment of the present application can be executed by a server, or by a terminal, or by both a server and a terminal. The terminal can execute the K8s cluster shrinking method of the embodiment of the present application, or it can be executed by a client installed thereon.
[0047] Taking the K8s cluster scaling method in this embodiment executed by the server as an example, Figure 2 A K8s cluster scaling method provided in an embodiment of the present application includes the following steps:
[0048] Step S202, obtain node status information of nodes in the target K8s cluster.
[0049] The K8s cluster scaling method in this embodiment can be applied to scenarios where it is necessary to determine in the K8s cluster the nodes that can be taken offline when scaling down without affecting the stability of business services.
[0050] In this embodiment, in order to accurately determine which node in the target K8s can be offline, it is necessary to determine the status of each node, and therefore, it is necessary to obtain the node status information of each node.
[0051] In this embodiment, the target K8s cluster is any K8s cluster that needs to determine whether a node can be taken offline.
[0052] As an optional implementation, such as the aforementioned method, the node status information includes: node CPU usage, node memory usage, the number of Pods on the node, and the node's historical offline failures, among which the node CPU usage, node memory usage, the number of Pods on the node, and the node's historical offline failures are negatively correlated with the offline priority.
[0053] Optionally, you can use the kubectl top command to obtain the node CPU usage and node memory usage of the target K8s cluster node, and use the kubectl get pods command to obtain the number of Pods on the node. You can use the kubectl describe command to display the node's event log to find the node offline failure record, thereby obtaining the node's historical lower limit failure situation.
[0054] In this embodiment, when the node CPU usage is higher, it means that the node is busier, so the node offline priority is lower, and vice versa, the lower the node CPU usage is, the idler the node is, so the node offline priority is higher. Optionally, the lower the node CPU usage is, the higher the score of the scoring item corresponding to the node CPU usage is; when the node memory usage is higher, it means that the node is busier, so the node offline priority is lower, and vice versa, the lower the node memory usage is, the idler the node is, so the node offline priority is higher. Optionally, the lower the node memory usage is, the higher the score of the scoring item corresponding to the node memory usage is; when the number of Pods on a node is more, it means that the node is used The more services provided, the lower the node offline priority. On the contrary, the fewer Pods on the node, the fewer services the node provides. Therefore, the higher the node offline priority. Optionally, the fewer Pods on the node, the higher the score of the scoring item corresponding to the number of Pods on the node. When the node has more historical offline failures, it means that the utilization rate of the services provided by the node is high and it is not easy to go offline. Therefore, the lower the node offline priority. On the contrary, the fewer historical offline failures of the node, the lower the utilization rate of the services provided by the node. Therefore, the higher the node offline priority, the fewer historical offline failures of the node, the higher the score of the scoring item corresponding to the number of Pods on the node. Therefore, the total score corresponding to each node can be determined based on the score of the scoring item corresponding to the node CPU usage, the score of the scoring item corresponding to the node memory usage, the score of the scoring item corresponding to the number of Pods on the node, and the sum of the scores of the scoring items corresponding to the number of Pods on the node, and the higher the score, the higher the priority to go offline.
[0055] Step S204: Based on the node status information, determine the nodes to be taken offline that meet the preset node offline requirements among all nodes.
[0056] After determining the node status information of each node, the status of the service currently provided by each node can be determined. Therefore, based on the node status information of each node, the nodes to be offline that meet the preset node offline requirements can be determined among all nodes.
[0057] The preset node offline requirement may be a preset requirement for indicating that the node can be offline, and the preset node offline requirement may be a pre-set condition, including but not limited to: the node CPU usage is lower than a first preset value, the node memory usage is lower than a second preset value, the number of Pods on the node is lower than a preset number, and the number of historical offline failures of the node is lower than a preset number, etc.
[0058] like Figure 3As shown, as an optional implementation, the aforementioned step S204 can be implemented by determining the nodes to be offline that meet the preset node offline requirements among all nodes based on the node status information through the following steps S302 and S304:
[0059] Step S302: Determine the offline priority of each node based on a preset evaluation strategy and the node status information of each node.
[0060] That is, a preset evaluation strategy including at least one evaluation index may be pre-set, and then the node status information of each node is evaluated by the evaluation strategy to determine the offline priority of each node. Since the offline priority of each node needs to be determined, the node status information of each node needs to be compared to determine the offline priority of each node.
[0061] In this embodiment, when the node status information in the aforementioned steps includes the node CPU usage, the node memory usage, the number of Pods on the node, and the node's historical offline failures, the total score corresponding to each node status information can be obtained based on the above information, and then the total score corresponding to each node can be obtained, and each node can be sorted according to the total score, for example, sorted in order from high to low in terms of the total score. When a higher total score indicates a higher offline priority, the offline priority of each node can be determined in order from high to low.
[0062] Step S304 , according to the order of offline priority from high to low and the node status information of each node, determine the nodes to be offline that meet the preset node offline requirements from all nodes in turn.
[0063] After determining the offline priority of each node, determine whether each node meets the preset node offline requirements based on the node status information of each node in order of offline priority from high to low. If so, determine it as a node to be offline. For example, first determine whether the node with the highest priority meets the preset node offline requirements based on the node status information of the node with the highest priority. If so, determine it as a node to be offline. If not, do not determine it as a node to be offline. Then determine the node status information of the node with the second highest priority to determine whether the node with the second highest priority meets the preset node offline requirements. If so, determine it as a node to be offline. If not, do not determine it as a node to be offline. This order is followed until the node with the lowest priority is determined to be a node to be offline, or until it is determined that the number of nodes to be offline meets the preset number of nodes to be offline.
[0064] As an optional implementation, as in the aforementioned method, the determination of the node to be offline that meets the preset node offline requirements among all nodes in step S304 can be implemented by the following steps: when it is determined that the Pod in any node meets the preset Pod eviction requirements, and the Pod in any node can be scheduled to other nodes among all nodes except any node, determine that any node is a node to be offline that meets the preset node offline requirements. In this embodiment, any node is any node in the target K8s cluster, and the method of this embodiment can be used to determine whether any node is a node to be offline. For any node, when all Pods in the node meet the Pod eviction requirements, and all Pods can be scheduled to other nodes among all nodes except the node, determine that the node is a node to be offline that meets the preset node offline requirements. The preset Pod eviction requirements include at least one of the following: the Pod's service is not a global single point, the Pod can be evicted if the Pod's service is a global single point, the proportion of Pods corresponding to the same business in any node to the total number of Pods for the business does not exceed the preset proportion, and the Pod creation exceeds the preset duration T, where the preset duration is used to indicate the duration required for other services to start when the Pod's service is dependent on other services. Specifically, when the Pod's service is not a global single point, it means that the service exists in multiple different Pods and can be evicted. Conversely, when the Pod's service is a global single point, it is necessary to determine separately whether it can be evicted; for a certain type of business, the proportion p of Pods that the business needs to retain at least can be pre-set, so the proportion q of Pods corresponding to the business in the node to the total number of Pods for the business can be determined. If q<(1-p), even if all Pods of the business in the node are evicted, it will not affect the stability of the business. Therefore, all Pods of the business in the node can be evicted. After the Pod is created for more than the preset time T, the service of the Pod has been dependent on other services and will not affect the startup of other services. It can be evicted. Otherwise, it will affect the startup of other services and cannot be evicted.
[0065] Step S206: When it is determined that all Pods on the node to be taken offline can be evicted, the node to be taken offline is taken offline to complete the scaling down of the target K8s cluster.
[0066] After the node to be taken offline is determined, the node can be taken offline. In order to avoid the situation where the node to be taken offline cannot be taken offline due to the inability to evict individual Pods, the node to be taken offline is taken offline only when it is determined that all Pods on the node to be taken offline can be evicted.
[0067] As an optional implementation, as in the aforementioned method, determining that all Pods on the node to be taken offline can be evicted is achieved by the following method: pre-evict all Pods on the node to be taken offline; when it is determined that all Pods are successfully pre-evoked, determining that all Pods on the node to be taken offline can be evicted. In other words, for all Pods on the node to be taken offline, if one of the Pods cannot be successfully evicted, then all Pods on the node to be taken offline will not be evicted. Therefore, first try to pre-evict all Pods on the node to be taken offline. Pre-eviction means that before formally evicting the Pods on the node, a series of checks and preparations are performed to ensure that there will be no eviction failure during formal eviction. Only when it is determined that all Pods on the node to be taken offline have been successfully pre-evoked, it is determined that all Pods on the node to be taken offline can be evicted.
[0068] After determining that all Pods on the node to be taken offline can be evicted, the node to be taken offline can be taken offline. As an optional implementation method, the node to be taken offline can be taken offline by the following method: determine whether there is a target Pod in the node to be taken offline, wherein the target Pod is a Pod that needs to run for a specific length of time before it ends; when it is determined that there is a target Pod in the node to be taken offline, after determining that the target Pod has run for a specific length of time, the node to be taken offline is taken offline. In this embodiment, the target Pod is a Pod that has special requirements and needs to be waited for, for example: a Pod that ends after running for a specific length of time. Furthermore, the specific length of time is the length of time that the target Pod needs to run to end, and after determining that the target Pod has run for a specific length of time, the node to be taken offline is taken offline.
[0069] Furthermore, after all Pods on the node to be taken offline are actually evicted, the Pods on the node to be taken offline can be rebuilt on other nodes that do not need to be taken offline and whose resources meet the requirements for rebuilding the Pods.
[0070] In an embodiment of the present application, the node status information of the nodes in the target K8s cluster is obtained; based on the node status information, the nodes to be taken offline that meet the preset node offline requirements are determined among all nodes; when it is determined that all Pods on the nodes to be taken offline can be evicted, the nodes to be taken offline are taken offline to complete the scaling down of the K8s cluster. Since in the K8s cluster, the service is run in the Pod, the nodes to be taken offline are determined based on the node status information, and the nodes to be taken offline are lowered only when all Pods on the nodes to be taken offline can be evicted, so that the purpose of the offline of the node will not affect the service can be achieved, and the technical effect of releasing resources will not affect the stability of business services is achieved, thereby solving the problem that releasing resources will affect the stability of business services in related technologies.
[0071] According to another aspect of the embodiments of the present application, there is also provided an electronic device, including a processor, a communication interface, a memory and a communication bus, wherein the processor, the communication interface and the memory communicate with each other via the communication bus; wherein the memory is used to store a computer program; and the processor is used to execute the method steps in any of the above embodiments by running the computer program stored in the memory.
[0072] According to another aspect of the embodiments of the present application, a computer-readable storage medium is provided, in which a computer program is stored, wherein the computer program is configured to execute the method steps in any of the above embodiments when executed.
[0073] In an embodiment of the present application, the node status information of the nodes in the target K8s cluster is obtained; based on the node status information, the nodes to be taken offline that meet the preset node offline requirements are determined among all nodes; when it is determined that all Pods on the nodes to be taken offline can be evicted, the nodes to be taken offline are taken offline to complete the scaling down of the K8s cluster. Since in the K8s cluster, the services are run in Pods, the nodes to be taken offline are determined based on the node status information, and the nodes to be taken offline are lowered only when all Pods on the nodes to be taken offline can be evicted, so that the purpose of the offline of the nodes will not affect the services can be achieved, and the technical effect of releasing resources will not affect the stability of business services is achieved, thereby solving the problem that the release of resources in the related technologies will affect the stability of business services.
[0074] It should be noted that, for the aforementioned method embodiments, for the sake of simplicity, they are all expressed as a series of action combinations, but those skilled in the art should be aware that the present application is not limited by the described order of actions, because according to the present application, certain steps can be performed in other orders or simultaneously. Secondly, those skilled in the art should also be aware that the embodiments described in the specification are all preferred embodiments, and the actions and modules involved are not necessarily required by the present application.
[0075] Through the description of the above implementation methods, those skilled in the art can clearly understand that the method according to the above embodiment can be implemented by means of software plus a necessary general hardware platform, and of course it can also be implemented by hardware, but in many cases the former is a better implementation method. Based on such an understanding, the technical solution of the present application, or the part that contributes to the prior art, can be embodied in the form of a software product, which is stored in a storage medium (such as ROM (Read-Only Memory) / RAM (Random Access Memory), a disk, or an optical disk), and includes a number of instructions for a terminal device (which can be a mobile phone, a computer, a server, or a network device, etc.) to execute the methods described in each embodiment of the present application.
[0076] According to another aspect of an embodiment of the present application, a K8s cluster scaling device for implementing the above-mentioned K8s cluster scaling method is also provided. Figure 4 is a structural block diagram of an optional K8s cluster capacity reduction device according to an embodiment of the present application, such as Figure 4 As shown, the device may include:
[0077] The acquisition module 41 is used to obtain the node status information of the nodes in the target K8s cluster;
[0078] A determination module 42 is used to determine, based on the node status information, the nodes to be offline that meet the preset node offline requirements among all the nodes;
[0079] The offline module 43 is used to offline the node to be offline when it is determined that all Pods on the node to be offline can be evicted, so as to complete the reduction of the target K8s cluster.
[0080] It should be noted that the acquisition module 41 in this embodiment can be used to execute the above step S202, the determination module 42 in this embodiment can be used to execute the above step S204, and the offline module 43 in this embodiment can be used to execute the above step S206.
[0081] Through the above module, the node to be taken offline is determined based on the node status information, and the node to be taken offline is lowered only when all Pods on the node to be taken offline can be evicted, so that the purpose of the node going offline without affecting the service can be achieved, and the technical effect of releasing resources without affecting the stability of business services is achieved, thereby solving the problem that releasing resources will affect the stability of business services in related technologies.
[0082] The device in this embodiment, in addition to the above-mentioned modules, may also include a module for executing any method in any of the aforementioned embodiments of the K8s cluster scaling method.
[0083] It should be noted that the examples and application scenarios implemented by the above modules and corresponding steps are the same, but are not limited to the contents disclosed in the above embodiments. It should be noted that the above modules as part of the device can be run in Figure 1 In the hardware environment shown, it can be implemented by software or by hardware, wherein the hardware environment includes a network environment.
[0084] According to another aspect of an embodiment of the present application, an electronic device for implementing the above-mentioned K8s cluster scaling method is also provided. The electronic device may be a server, a terminal, or a combination thereof.
[0085] According to another embodiment of the present application, there is also provided an electronic device, including: Figure 5 As shown, the electronic device may include: a processor 1501 , a communication interface 1502 , a memory 1503 and a communication bus 1504 , wherein the processor 1501 , the communication interface 1502 , and the memory 1503 communicate with each other via the communication bus 1504 .
[0086] Memory 1503, used for storing computer programs;
[0087] The processor 1501 is used to implement the following steps when executing the program stored in the memory 1503:
[0088] Step S202, obtain node status information of nodes in the target K8s cluster.
[0089] Step S204: Based on the node status information, determine the nodes to be taken offline that meet the preset node offline requirements among all nodes.
[0090] Step S206: When it is determined that all Pods on the node to be taken offline can be evicted, the node to be taken offline is taken offline to complete the scaling down of the target K8s cluster.
[0091] Optionally, in this embodiment, the above-mentioned communication bus can be a PCI (Peripheral Component Interconnect) bus, or an EISA (Extended Industry Standard Architecture) bus, etc. The communication bus can be divided into an address bus, a data bus, a control bus, etc. For ease of representation, only one thick line is used in the figure, but it does not mean that there is only one bus or one type of bus. The communication interface is used for communication between the above-mentioned electronic device and other devices.
[0092] The memory may include a random access memory (RAM) or a non-volatile memory (NVM), such as at least one disk memory. Optionally, the memory may also be at least one storage device located away from the aforementioned processor.
[0093] As an example, the memory 1503 may include, but is not limited to, the acquisition module 41, determination module 42, and offline module 43 in the K8s cluster shrinking device. In addition, it may also include, but is not limited to, other module units in the K8s cluster shrinking device, which will not be repeated in this example.
[0094] The above-mentioned processor can be a general-purpose processor, which can include but not be limited to: CPU (Central Processing Unit), NP (Network Processor), etc.; it can also be DSP (Digital Signal Processor), ASIC (Application Specific Integrated Circuit), FPGA (Field-Programmable Gate Array) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components.
[0095] An embodiment of the present application further provides a computer-readable storage medium, the storage medium including a stored program, wherein the method steps of the above method embodiment are executed when the program is run.
[0096] Optionally, in this embodiment, the storage medium may include, but is not limited to, various media that can store program codes, such as a USB flash drive, a ROM, a RAM, a mobile hard disk, a magnetic disk, or an optical disk.
[0097] The serial numbers of the above-mentioned embodiments of the present application are for description only and do not represent the advantages or disadvantages of the embodiments.
[0098] If the integrated units in the above embodiments are implemented in the form of software functional units and sold or used as independent products, they can be stored in the above computer-readable storage medium. Based on this understanding, the technical solution of the present application, or the part that contributes to the prior art, or all or part of the technical solution can be embodied in the form of a software product, which is stored in a storage medium and includes several instructions for enabling one or more computer devices (which may be personal computers, servers, or network devices, etc.) to execute all or part of the steps of the methods described in the various embodiments of the present application.
[0099] In the above embodiments of the present application, the description of each embodiment has its own emphasis. For parts that are not described in detail in a certain embodiment, please refer to the relevant description of other embodiments.
[0100] In the several embodiments provided in the present application, it should be understood that the disclosed client can be implemented in other ways. Among them, the device embodiments described above are only schematic. For example, the division of the units is only a logical function division. There may be other division methods in actual implementation. For example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of units or modules, which can be electrical or other forms.
[0101] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution provided in this embodiment.
[0102] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.
[0103] The above is only a preferred implementation of the present application. It should be pointed out that for ordinary technicians in this technical field, several improvements and modifications can be made without departing from the principles of the present application. These improvements and modifications should also be regarded as the scope of protection of the present application.
Claims
1. A K8s cluster scaling method, characterized in that: include: Get the node status information of the nodes in the target K8s cluster; Based on the node status information, determine the nodes to be offline that meet the preset node offline requirements among all nodes; When it is determined that all Pods on the node to be taken offline can be evicted, the node to be taken offline is taken offline to complete the scaling down of the target K8s cluster.
2. The method according to claim 1, characterized in that The step of determining, based on the node status information, a node to be offline that meets a preset node offline requirement among all nodes includes: Determine the offline priority of each node based on a preset evaluation strategy and the node status information of each node; According to the order of offline priority from high to low and the node status information of each node, the nodes to be offline that meet the preset node offline requirements are determined in turn from all the nodes.
3. The method according to claim 2, characterized in that The step of determining the node to be offline that meets the preset node offline requirement from among all the nodes includes: When it is determined that the Pod in any node meets the preset Pod eviction requirement, and the Pod in any node can be scheduled to other nodes among all the nodes except the any node, the any node is determined to be the node to be offline that meets the preset node offline requirement.
4. The method according to claim 3, characterized in that The preset Pod eviction requirement includes at least one of the following: The Pod's service is not a global single point, it can be evicted if the Pod's service is a global single point, the proportion of Pods corresponding to the same business in any node to the total number of Pods for the business does not exceed a preset proportion, and the Pod creation exceeds a preset duration T, wherein the preset duration is used to indicate the duration required for other services to start when the Pod's service is dependent on other services.
5. The method according to claim 1, characterized in that The step of determining that all Pods on the node to be offline can be evicted includes: Pre-evict all Pods on the node to be taken offline; When it is determined that all the Pods are pre-evicted successfully, it is determined that all the Pods on the node to be taken offline can be evicted.
6. The method according to claim 1, characterized in that The step of taking the node to be taken offline offline comprises: Determine whether there is a target Pod in the node to be taken offline, wherein the target Pod is a Pod that needs to run for a specific period of time before it ends; When it is determined that the target Pod exists in the node to be taken offline, the node to be taken offline is taken offline after it is determined that the target Pod has been running for a specific time.
7. The method according to any one of claims 1 to 6, characterized in that The node status information includes: The node CPU usage, the node memory usage, the number of Pods on the node, and the node's historical offline failures, wherein the node CPU usage, the node memory usage, the number of Pods on the node, and the node's historical offline failures are negatively correlated with the offline priority.
8. A K8s cluster capacity reduction device, characterized in that: include: The acquisition module is used to obtain the node status information of the nodes in the target K8s cluster; A determination module, configured to determine, based on the node status information, nodes to be taken offline that meet preset node offline requirements among all nodes; The offline module is used to offline the node to be offline and complete the scaling down of the target K8s cluster when it is determined that all Pods on the node to be offline can be evicted.
9. An electronic device comprising a processor, a communication interface, a memory and a communication bus, wherein: The processor, the communication interface and the memory communicate with each other via the communication bus, wherein: The memory is used to store computer programs; The processor is configured to execute the method according to any one of claims 1 to 7 by running the computer program stored in the memory.
10. A computer-readable storage medium, characterized in that: The storage medium stores a computer program, wherein the computer program is configured to execute the method according to any one of claims 1 to 7 when executed.