K8s cluster capacity expansion and contraction method and device, electronic equipment and storage medium
By pre-scaling the nodes in the resource pool in the K8s cluster and directly starting these nodes during peak periods, the problem of long resource expansion time of K8s cluster is solved, and the expansion efficiency and service stability are improved.
Patent Information
- Application Number
- CN202510101476.2
- 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 the prior art, the K8s cluster resource expansion time is long, resulting in delays in service startup during peak business periods, affecting stability.
By obtaining the amount of resources required for expansion of the target K8s cluster, the target nodes that meet the resource amount are determined in the resource pool obtained by the pre-expanding capacity, and these nodes are started to complete the cluster expansion.
The time for resources to join the K8s cluster during peak periods is shortened, the efficiency of cluster expansion is improved, and the problem of long resource expansion time is solved.
Smart Images

Figure CN120029769A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of cloud computing technology, and in particular to a K8s cluster expansion and contraction method and device, electronic device and storage medium. Background Art
[0002] At present, in order to save cloud costs and realize rapid expansion of K8s clusters during business peak periods, we have implemented a mechanism for dynamically creating and deleting cloud resources to address the situation of peak and trough usage of business resources (more resources are used during peak hours in the morning and evening, and less resources are used at other times).
[0003] Currently, it usually takes 2-3 minutes for a K8s cluster on the cloud to replenish resources from creating a machine to joining the cluster. During peak hours, when business traffic suddenly increases and more services need to be expanded, resources cannot be met immediately, so the service needs to wait 2-3 minutes to start, which affects service stability.
[0004] Therefore, there is a problem in the related technology that it takes a long time to expand the k8s resources. Summary of the invention
[0005] The present application provides a K8s cluster expansion and contraction method and device, electronic device and storage medium, so as to at least solve the problem of long K8s resource expansion time existing in the related technology.
[0006] According to one aspect of an embodiment of the present application, a K8s cluster expansion and contraction method is provided, including:
[0007] Get the amount of expansion resources required for the target K8s cluster;
[0008] Determine a target node in a resource pool that satisfies the amount of expanded resources, wherein the resource pool includes nodes obtained by pre-expanding the target K8s cluster;
[0009] Start the target node and complete the expansion of the target K8s cluster.
[0010] Optionally, as in the aforementioned method, the method further comprises:
[0011] Determine the preset resource amount of the resource pool to be configured;
[0012] The available nodes that meet the preset resource amount are placed into the resource pool.
[0013] Optionally, as in the aforementioned method, the method further comprises:
[0014] Get the amount of shrinking resources required for the target K8s cluster;
[0015] Determine a designated node in the target K8s cluster that satisfies the amount of resources to be reduced;
[0016] Shut down the designated node and add it to the resource pool to complete the scaling down of the target K8s cluster.
[0017] Optionally, as in the aforementioned method, the method further comprises:
[0018] In the case of determining that the current resource amount of the resource pool is less than the preset resource amount, determining a node to be added that satisfies a first difference resource amount, wherein the first difference resource amount is equal to the preset resource amount minus the current resource amount;
[0019] The node to be added is added to the resource pool, and the node to be added is shut down.
[0020] Optionally, as in the aforementioned method, when it is determined that the current amount of resources in the resource pool is less than a preset amount of resources, determining a node to be added that satisfies the first difference amount of resources includes:
[0021] In the case where it is determined that the current resource amount of the resource pool is less than the preset resource amount, determining the node performance of each candidate node among all the candidate nodes;
[0022] According to the node performance of each candidate node, the node to be joined that meets the first difference resource amount is determined from among all the candidate nodes, wherein the node performance of the node to be joined is higher than the node performance of other candidate nodes among all the candidate nodes except the node to be joined.
[0023] Optionally, as in the aforementioned method, the method further comprises:
[0024] In the case of determining that the current resource amount of the resource pool is greater than the preset resource amount, determining a node to be deleted in the resource pool that satisfies a second difference resource amount, wherein the second difference resource amount is equal to the current resource amount minus the preset resource amount;
[0025] The node to be deleted is deleted from the resource pool.
[0026] Optionally, as in the aforementioned method, when it is determined that the current amount of resources in the resource pool is greater than the preset amount of resources, determining in the resource pool a node to be deleted that satisfies the second difference amount of resources includes:
[0027] In the case where it is determined that the current amount of resources in the resource pool is greater than the preset amount of resources, determining the node performance of each available node in the resource pool;
[0028] According to the node performance of each available node, the node to be deleted that meets the second difference resource amount is determined among all available nodes, wherein the node performance of the node to be deleted is lower than or equal to the node performance of other available nodes among all available nodes except the node to be deleted.
[0029] According to another aspect of the embodiment of the present application, a K8s cluster expansion and contraction device is also provided, including:
[0030] The acquisition module is used to obtain the capacity expansion resources required for the target K8s cluster;
[0031] A determination module, configured to determine a target node in a resource pool that satisfies the amount of expanded resources, wherein the resource pool includes nodes obtained by pre-expanding the target K8s cluster;
[0032] The startup module is used to start the target node and complete the expansion of the target K8s cluster.
[0033] 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.
[0034] 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.
[0035] In the embodiment of the present application, the K8s cluster expansion and contraction method is adopted, by obtaining the amount of expansion resources required for the target K8s cluster to be expanded; determining the target node that meets the amount of expansion resources in the resource pool, wherein the resource pool includes the node obtained by pre-expanding the target K8s cluster; starting the target node to complete the expansion of the target K8s cluster. Since the target node that meets the amount of expansion resources required by the target K8s cluster is pre-expanded in the resource pool, when the target node is needed by the target K8s cluster, the target node is directly started, that is, the machine corresponding to the target node is turned on, thereby achieving the purpose of shortening the time for resources to join the target K8s cluster during peak periods, achieving the technical effect of improving the efficiency of expanding the target K8s cluster, and thus solving the technical problem of long k8s resource expansion time existing in the related technology. BRIEF DESCRIPTION OF THE DRAWINGS
[0036] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present application and, together with the description, serve to explain the principles of the present application.
[0037] 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.
[0038] Figure 1 It is a schematic diagram of the hardware environment of an optional K8s cluster expansion and contraction method according to an embodiment of the present application;
[0039] Figure 2 It is a flowchart of an optional K8s cluster expansion and contraction method according to an embodiment of the present application;
[0040] Figure 3 It is a flowchart of an optional K8s cluster expansion and contraction method according to another embodiment of the present application;
[0041] Figure 4 It is a flowchart of an optional K8s cluster expansion and contraction method according to another embodiment of the present application;
[0042] Figure 5 It is a flowchart of an optional K8s cluster expansion and contraction method according to the application example of this application;
[0043] Figure 6 It is a structural block diagram of an optional K8s cluster expansion and contraction device according to an embodiment of the present application;
[0044] Figure 7 It is a structural block diagram of an optional electronic device according to an embodiment of the present application. DETAILED DESCRIPTION
[0045] 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.
[0046] 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.
[0047] First, some nouns or terms that appear in the description of the embodiments of the present application are subject to the following interpretation:
[0048] 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.
[0049] 2. Capacity expansion refers to increasing the number of replicas of an application or service in K8s to accommodate higher workloads by increasing resources.
[0050] 3. Scaling refers to reducing the number of replicas of an application or service in K8s to adapt to lower workloads or save resources.
[0051] According to one aspect of an embodiment of the present application, a K8s cluster expansion and contraction method is provided. Optionally, in this embodiment, the above-mentioned K8s cluster expansion and contraction 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.
[0052] 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.
[0053] The K8s cluster expansion and contraction 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 executing the K8s cluster expansion and contraction method of the embodiment of the present application can also be executed by a client installed thereon.
[0054] Taking the K8s cluster expansion and contraction method in this embodiment executed by the server as an example, Figure 2 A K8s cluster expansion and contraction method provided in an embodiment of the present application includes the following steps:
[0055] Step S202, obtain the amount of expansion resources required for the target K8s cluster to be expanded.
[0056] The K8s cluster expansion and contraction method in this embodiment can be applied to the scenario where new resources need to be added to the K8s cluster when resources need to be expanded in the K8s cluster.
[0057] In order to determine the required resources, you need to first determine the amount of expansion resources required for the target K8s cluster to be expanded.
[0058] The target K8s cluster can be any K8s cluster that needs to be expanded. Furthermore, the method of this embodiment is applicable to all K8s clusters that need to be expanded.
[0059] In this embodiment, the amount of expanded resources refers to the amount of resources that the target K8s cluster needs to increase in order to adapt to a higher workload (for example, deploying new services, etc.). The amount of expanded resources may include but is not limited to (CPU cores, memory, storage, bandwidth, etc.).
[0060] Step S204, determine the target node that meets the expanded resource quantity in the resource pool, wherein the resource pool includes the nodes obtained by pre-expanding the target K8s cluster.
[0061] After determining the amount of expansion resources required by the target K8s cluster, in order to increase the resources that meet the expansion resources, it is necessary to determine at least one target node that meets the expansion resources in the resource pool, that is, the target node may include one or more. When there is one target node, the one target node needs to meet the expansion resources, and when there are multiple target nodes, the total amount of resources of the multiple target nodes needs to meet the expansion resources.
[0062] Optionally, the total amount of resources of each node in the resource pool may be obtained, including the CPU, memory, storage, etc. of each node.
[0063] Then, according to the above-mentioned expanded resource amount, matching can be performed among all nodes to obtain at least one target node, and the total resource amount of the target node is made greater than or equal to the expanded resource amount.
[0064] Moreover, the nodes in the resource pool are resources that have been created by the K8s cluster expansion controller of the target K8s cluster. That is, as long as the nodes in the resource pool are started and running, they can be used by the K8s cluster.
[0065] Step S206, start the target node to complete the expansion of the target K8s cluster.
[0066] After determining the target node, since the target node is a node in the resource pool, and the nodes in the resource pool are all obtained by pre-expanding the target K8s cluster, in this case, the target node can be directly started to add the target node to the target K8s cluster, thereby completing the expansion of the target K8s cluster.
[0067] In the embodiment of the present application, the K8s cluster expansion and contraction method is adopted, by obtaining the amount of expansion resources required for the target K8s cluster to be expanded; determining the target node that meets the amount of expansion resources in the resource pool, wherein the resource pool includes the node obtained by pre-expanding the target K8s cluster; starting the target node to complete the expansion of the target K8s cluster. Since the target node that meets the amount of expansion resources required by the target K8s cluster is pre-expanded in the resource pool, when the target node is needed by the target K8s cluster, the target node is directly started, that is, the machine corresponding to the target node is turned on, thereby achieving the purpose of shortening the time for resources to join the target K8s cluster during peak periods, achieving the technical effect of improving the efficiency of expanding the target K8s cluster, and thus solving the technical problem of long k8s resource expansion time existing in the related technology.
[0068] like Figure 3 As shown, as an optional implementation, as the above method, the method further includes the following steps:
[0069] Step S302: determine the preset resource amount of the resource pool to be configured.
[0070] Specifically, the preset resource amount of the resource pool may be a resource amount obtained based on business requirements, historical load trends, and future growth forecasts. The preset resource amount may be selected according to actual application scenarios and is not limited here.
[0071] Step S304: put available nodes that meet the preset resource quantity into a resource pool.
[0072] After determining the preset resource amount, you can determine the resource amount of each candidate node among all candidate nodes by using the kubectl command, and then determine at least one available node that meets the preset resource amount among all candidate nodes. Then, you can use the K8s cluster expansion controller to create resources based on the available node and add it to the resource pool until the total amount of resources in the resource pool is greater than or equal to the preset resource amount.
[0073] Through the method of this embodiment, a resource pool that meets the preset resource quantity can be quickly generated, so that the target K8s cluster can be used to expand the resource quantity of the node later.
[0074] like Figure 4 As shown, as an optional implementation, as the above method, the method further includes the following steps:
[0075] Step S402, obtain the amount of shrinking resources required for the target K8s cluster.
[0076] When the target K8s has at least one of the following conditions: low resource utilization, low CPU and memory usage, you can consider downsizing; you can downsize when business demand decreases, traffic decreases, or specific application demand decreases; cost optimization, reduce unnecessary nodes to reduce costs; resource management strategy: downsize according to automatic scaling strategy or regular review results; maintenance and upgrade, temporarily reduce the number of nodes during maintenance or upgrade; test and development environment, reduce the number of nodes after the test and development tasks are completed; seasonal demand changes, dynamically adjust the number of nodes according to seasonal demand changes. The current resources of the target K8s cluster are in surplus, and since the host is not charged after shutdown, in order to reduce the target K8s cluster's occupation of cloud computing resources and reduce the cost of using cloud computing resources, the target K8s cluster can be downsized and the amount of downsized resources required for the target K8s can be determined.
[0077] Step S404: determine the designated node in the target K8s cluster that meets the resource requirements for shrinking.
[0078] During the process of shrinking the target K8s cluster, at least one designated node that meets the shrinking resource amount can be determined, and the error between the total resource amount of the at least one designated node and the shrinking resource amount is within a preset range.
[0079] Step S406: Shut down the designated node and add it to the resource pool to complete the scaling down of the target K8s cluster.
[0080] After determining the designated node, in order to allow the designated node to be quickly used for the expansion of the target K8s cluster in the later stage, the designated node is shut down and added to the resource pool to complete the reduction of the target K8s cluster.
[0081] Through the method of this embodiment, the cluster can be quickly reduced in capacity, and the reduced nodes can also be quickly used for capacity expansion in the later stage, thereby effectively reducing resource waste and improving capacity expansion efficiency.
[0082] As an optional implementation, as the above method, the method further includes the following steps:
[0083] When it is determined that the current amount of resources in the resource pool is less than the preset amount of resources, determine the node to be added that meets the first difference amount of resources, where the first difference amount of resources is equal to the preset amount of resources minus the current amount of resources; add the node to be added to the resource pool, and shut down the node to be added. In other words, if the amount of resources in the resource pool is less than the preset amount of resources n, the first difference amount of resources can be determined by first subtracting the current amount of resources from the preset amount of resources, and then determine the node to be added whose amount of resources is greater than or equal to the first difference amount of resources, and then create resources based on the node to be added through the K8s cluster expansion controller, add the node to be added to the resource pool, and shut down the node to be added, so that the amount of resources in the resource pool is greater than or equal to n.
[0084] As an optional implementation, as in the aforementioned method, the aforementioned determination of the node to be added that meets the first difference resource amount when it is determined that the current resource amount of the resource pool is less than the preset resource amount can be achieved through the following steps: when it is determined that the current resource amount of the resource pool is less than the preset resource amount, the node performance of each candidate node among all candidate nodes is determined; according to the node performance of each candidate node, the node to be added that meets the first difference resource amount is determined among all candidate nodes, wherein the node performance of the node to be added is higher than the node performance of other candidate nodes among all candidate nodes except the node to be added. That is to say, when it is determined that the current amount of resources in the resource pool is less than the preset amount of resources, the resources of the resource pool need to be expanded. During the expansion process, the node with the best node performance is selected to join the resource pool, so as to improve the performance of the target K8s cluster, so that the node performance of each candidate node can be determined first (for example, disk IO speed, power consumption, performance of each core CPU, etc.), and then the node performance of each candidate node is selected in order from all candidate nodes until the node to be added that meets the first difference resource amount is determined, and the performance of the node to be added is the best among all candidate nodes. Through the method of this embodiment, the node performance of the nodes in the resource pool can be effectively improved, so that the expanded nodes can also have good node performance.
[0085] As an optional implementation, as in the aforementioned method, the method further includes the following steps: when it is determined that the current amount of resources in the resource pool is greater than the preset amount of resources, a node to be deleted that satisfies the second difference amount of resources is determined in the resource pool, wherein the second difference amount of resources is equal to the current amount of resources minus the preset amount of resources; and the node to be deleted is deleted in the resource pool. In other words, if the amount of resources in the resource pool is greater than the preset amount of resources n, there is no need to occupy so many nodes in the resource pool. Therefore, the second difference amount of resources can be determined by first subtracting the preset amount of resources from the current amount of resources, and then the node to be deleted whose amount of resources satisfies the second difference amount of resources can be determined in the resource pool. Then, the node to be deleted can be released through the K8s cluster shrinking controller to release the node to be deleted from the resource pool so that the amount of resources in the resource pool is greater than or equal to n. In addition, the node to be deleted can be one of the nodes that can be deleted in the resource pool, and after deletion, it satisfies the requirement that the amount of resources in the resource pool is greater than or equal to n, and is at least one node closest to n.
[0086] like Figure 5 As shown, an application example of applying any of the above embodiments is provided:
[0087] 1. Configure the resource quantity n (i.e., the preset resource quantity) of a resource pool.
[0088] 2. If the current amount of resources in the resource pool is less than n, the K8s cluster expansion controller creates resources until the amount of resources in the resource pool is greater than or equal to n.
[0089] 3. When the cluster needs to be expanded, the specified resource amount m (ie, the first difference resource amount) is obtained from the resource pool, and the machine corresponding to the resource amount m (ie, the node to be added) is powered on.
[0090] 4. When the cluster is scaled down, the machine (i.e., the node to be deleted) will be shut down and placed in the resource pool.
[0091] 5. If the current amount of resources in the resource pool is greater than n, delete some resources in the resource pool to meet the resource limit of n (if the amount of resources in the resource pool is less than n after releasing a node resource, the node will no longer be released).
[0092] As an optional implementation, as in the aforementioned method, the aforementioned steps can be implemented by the following steps: when it is determined that the current amount of resources in the resource pool is greater than the preset amount of resources, a node to be deleted that satisfies the second differential amount of resources is determined in the resource pool: when it is determined that the current amount of resources in the resource pool is greater than the preset amount of resources, the node performance of each available node in the resource pool is determined; according to the node performance of each available node, a node to be deleted that satisfies the second differential amount of resources is determined among all available nodes, wherein the node performance of the node to be deleted is lower than or equal to the node performance of other available nodes among all available nodes except the node to be deleted. That is to say, when it is determined that the current amount of resources in the resource pool is greater than the preset amount of resources, the resources in the resource pool need to be reduced. During the reduction process, the node with the worst node performance is selected in the resource pool for release. Therefore, the node performance of each available node in the resource pool (for example, disk IO speed, power consumption, performance of each core CPU, etc.) can be determined first, and then the node performance of each available node is selected in order from low to high, from all available nodes, until the node to be deleted that meets the second difference resource amount is determined, and the performance of the node to be deleted is the worst among all available nodes. Through the method of this embodiment, the node performance of the nodes in the resource pool can still be effectively guaranteed when releasing the nodes, so that the expanded nodes can also have good node performance.
[0093] 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.
[0094] 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 magnetic 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 of each embodiment of the present application.
[0095] 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 6 is a structural block diagram of an optional K8s cluster expansion and contraction device according to an embodiment of the present application, such as Figure 6 As shown, the device may include:
[0096] The acquisition module 61 is used to obtain the amount of expansion resources required for the target K8s cluster to be expanded;
[0097] A determination module 62 is used to determine a target node in a resource pool that meets the amount of expanded resources, wherein the resource pool includes nodes obtained by pre-expanding the target K8s cluster;
[0098] The startup module 63 is used to start the target node and complete the expansion of the target K8s cluster.
[0099] It should be noted that the acquisition module 61 in this embodiment can be used to execute the above step S202, the determination module 62 in this embodiment can be used to execute the above step S204, and the starting module 63 in this embodiment can be used to execute the above step S206.
[0100] Through the above modules, the K8s cluster expansion and contraction method is adopted to obtain the expansion resources required for the target K8s cluster; determine the target node that meets the expansion resources in the resource pool, wherein the resource pool includes the node obtained by pre-expanding the target K8s cluster; start the target node to complete the expansion of the target K8s cluster. Since the target node that meets the expansion resources required by the target K8s cluster is pre-expanded in the resource pool, when the target node is needed by the target K8s cluster, the target node is directly started, that is, the machine corresponding to the target node is turned on, thereby achieving the purpose of shortening the time for resources to join the target K8s cluster during peak periods, achieving the technical effect of improving the efficiency of expanding the target K8s cluster, and thus solving the technical problem of long k8s resource expansion time existing in related technologies.
[0101] As an optional implementation, as in the aforementioned device, the device further includes:
[0102] A preset resource quantity determination module is used to determine the preset resource quantity of the resource pool to be configured;
[0103] The placement module is used to place available nodes that meet the preset resource quantity into the resource pool.
[0104] As an optional implementation, as in the aforementioned device, the device further includes:
[0105] The shrinking resource acquisition module is used to obtain the shrinking resource amount required for the target K8s cluster;
[0106] The designated node determination module is used to determine the designated nodes in the target K8s cluster that meet the amount of resources to be scaled down;
[0107] The shutdown module is used to shut down the specified node and add it to the resource pool to complete the scaling down of the target K8s cluster.
[0108] As an optional implementation, as in the aforementioned device, the device further includes:
[0109] A to-be-joined node determination module, configured to determine a to-be-joined node that satisfies a first difference resource amount when it is determined that the current resource amount of the resource pool is less than the preset resource amount, wherein the first difference resource amount is equal to the preset resource amount minus the current resource amount;
[0110] The first adding module is used to add the node to be added to the resource pool and shut down the node to be added.
[0111] As an optional implementation, in the aforementioned device, the node to be added determination module is configured as follows:
[0112] When it is determined that the current amount of resources in the resource pool is less than the preset amount of resources, determining the node performance of each candidate node among all the candidate nodes;
[0113] According to the node performance of each candidate node, a node to be added that meets the first difference resource amount is determined from all candidate nodes, wherein the node performance of the node to be added is higher than the node performance of other candidate nodes except the node to be added from all candidate nodes.
[0114] As an optional implementation, as in the aforementioned device, the device further includes:
[0115] A to-be-deleted node determination module, configured to determine, in the resource pool, a to-be-deleted node that satisfies a second difference resource amount when it is determined that the current resource amount of the resource pool is greater than the preset resource amount, wherein the second difference resource amount is equal to the current resource amount minus the preset resource amount;
[0116] The deletion module is used to delete the node to be deleted in the resource pool.
[0117] As an optional implementation, in the aforementioned device, the node to be deleted determination module is configured to:
[0118] When it is determined that the current amount of resources in the resource pool is greater than the preset amount of resources, determining the node performance of each available node in the resource pool;
[0119] According to the node performance of each available node, a node to be deleted that meets the second difference resource amount is determined among all available nodes, wherein the node performance of the node to be deleted is lower than or equal to the node performance of other available nodes among all available nodes except the node to be deleted.
[0120] 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 expansion and reduction method.
[0121] 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.
[0122] According to another aspect of an embodiment of the present application, an electronic device for implementing the above-mentioned K8s cluster expansion and contraction method is also provided. The electronic device may be a server, a terminal, or a combination thereof.
[0123] According to another embodiment of the present application, there is also provided an electronic device, including: Figure 7 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 .
[0124] Memory 1503, used for storing computer programs;
[0125] The processor 1501 is used to implement the following steps when executing the program stored in the memory 1503:
[0126] Step S202, obtain the amount of expansion resources required for the target K8s cluster to be expanded.
[0127] Step S204, determine the target node that meets the expanded resource quantity in the resource pool, wherein the resource pool includes the nodes obtained by pre-expanding the target K8s cluster.
[0128] Step S206, start the target node to complete the expansion of the target K8s cluster.
[0129] 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.
[0130] 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.
[0131] As an example, the memory 1503 may include but is not limited to the acquisition module 51, determination module 52 and startup module 53 in the K8s cluster expansion and contraction device. In addition, it may also include but is not limited to other module units in the K8s cluster expansion and contraction device, which will not be repeated in this example.
[0132] 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.
[0133] 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.
[0134] 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.
[0135] 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.
[0136] 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.
[0137] 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.
[0138] 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.
[0139] 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.
[0140] 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.
[0141] 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 expansion and contraction method, characterized in that: include: Get the amount of expansion resources required for the target K8s cluster; Determine a target node in a resource pool that satisfies the amount of expanded resources, wherein the resource pool includes nodes obtained by pre-expanding the target K8s cluster; Start the target node and complete the expansion of the target K8s cluster.
2. The method according to claim 1, characterized in that The method further comprises: Determine the preset resource amount of the resource pool to be configured; The available nodes that meet the preset resource amount are placed into the resource pool.
3. The method according to claim 1, characterized in that: The method further comprises: Get the amount of shrinking resources required for the target K8s cluster; Determine a designated node in the target K8s cluster that satisfies the amount of resources to be reduced; Shut down the designated node and add it to the resource pool to complete the scaling down of the target K8s cluster.
4. The method according to claim 1, characterized in that: The method further comprises: In the case of determining that the current resource amount of the resource pool is less than the preset resource amount, determining a node to be added that satisfies a first difference resource amount, wherein the first difference resource amount is equal to the preset resource amount minus the current resource amount; The node to be added is added to the resource pool, and the node to be added is shut down.
5. The method according to claim 4, characterized in that The step of determining a node to be added that satisfies a first difference resource amount when it is determined that the current resource amount of the resource pool is less than a preset resource amount includes: In the case where it is determined that the current resource amount of the resource pool is less than the preset resource amount, determining the node performance of each candidate node among all the candidate nodes; According to the node performance of each candidate node, the node to be joined that meets the first difference resource amount is determined from among all the candidate nodes, wherein the node performance of the node to be joined is higher than the node performance of other candidate nodes among all the candidate nodes except the node to be joined.
6. The method according to claim 1, characterized in that The method further comprises: In the case of determining that the current resource amount of the resource pool is greater than the preset resource amount, determining a node to be deleted in the resource pool that satisfies a second difference resource amount, wherein the second difference resource amount is equal to the current resource amount minus the preset resource amount; The node to be deleted is deleted from the resource pool.
7. The method according to claim 6, characterized in that In the case where it is determined that the current resource amount of the resource pool is greater than the preset resource amount, determining in the resource pool a node to be deleted that satisfies the second difference resource amount includes: In the case where it is determined that the current amount of resources in the resource pool is greater than the preset amount of resources, determining the node performance of each available node in the resource pool; According to the node performance of each available node, the node to be deleted that meets the second difference resource amount is determined among all available nodes, wherein the node performance of the node to be deleted is lower than or equal to the node performance of other available nodes among all available nodes except the node to be deleted.
8. A K8s cluster expansion and contraction device, characterized in that: include: The acquisition module is used to obtain the capacity expansion resources required for the target K8s cluster; A determination module, configured to determine a target node in a resource pool that satisfies the amount of expanded resources, wherein the resource pool includes nodes obtained by pre-expanding the target K8s cluster; The startup module is used to start the target node and complete the expansion of the target K8s cluster.
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.
Citation Information
Cited By
Memory management method and device, electronic equipment and storage medium
CN120508351A