Agent management method, device, electronic device and storage medium in cluster
Through the collector and controller in the cluster management component, the affinity configuration of DaemonSet is modified in batches, the problem of Agent management in K8S cluster affecting other services is solved, and convenient and efficient Agent installation and uninstallation is achieved.
Patent Information
- Application Number
- CN202510179892.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-02-19
- Publication Date
- 2025-08-22
- Estimated Expiration
- 2045-02-19
AI Technical Summary
In K8S cluster, Agent's management affects other services, resulting in high traffic, poor convenience and flexibility.
Through the collector and controller in the cluster management component, the Pod is collected and the target node is determined according to the Agent identification, and the DaemonSet affinity configuration is used to modify it in batches to realize the installation or uninstallation of the Agent.
It reduces the impact on other businesses, improves management convenience and flexibility, and avoids sudden surge in instantaneous traffic.
Smart Images

Figure CN119676045B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of computers, and in particular to a method, device, electronic device and storage medium for managing an Agent in a cluster. Background Art
[0002] With the development of container technology, more and more enterprises and individuals are adopting Kubernetes as their deployment environment. Within a Kubernetes cluster, agents are typically deployed to monitor, manage, and control server operations and functions to improve server security and reliability. These agents are deployed within the cluster as DaemonSets. DaemonSets operate at the cluster level, so the DaemonSet controller can centrally manage all agent pods, allowing simultaneous operations on all agents. However, in actual use, operations may need to be performed on multiple agents, which is not possible with the DaemonSet controller.
[0003] The Agent program deployed in the current cluster is usually completed by loading the cluster's kubeconfig file on the server and then directly calling the K8S API.
[0004] The cluster agent runs in the cluster as a DaemonSet, ensuring that an agent program runs on each node. However, if you directly use DaemonSet deployment at the beginning, all agents will pull configurations and some data from the server at startup, resulting in high instantaneous traffic and possibly affecting other services in the cluster. In addition, you cannot operate multiple agents in the cluster, making it inconvenient and inflexible.
[0005] In summary, when managing Agents in a cluster, how to reduce the impact on other businesses and improve the convenience and flexibility of management has become a technical problem that urgently needs to be solved. Summary of the Invention
[0006] In view of this, the purpose of the present invention is to provide a cluster Agent management method, device, electronic device and storage medium to alleviate the technical problems of the existing technology in affecting other services in the cluster and poor management convenience and flexibility when managing the Agent in the cluster.
[0007] In a first aspect, an embodiment of the present invention provides an Agent management method in a cluster, which is applied to a cluster management component installed in the cluster, wherein the cluster management component includes a collector and a controller. The method includes:
[0008] The collector collects the Pods running in the cluster, and determines the Agents running in the cluster according to the running Pods and the predefined Agent identifiers in the cluster, and then obtains the target node to which the running Agents belong;
[0009] The controller receives an Agent management task sent by the server, wherein the Agent management task carries information about items to be managed and nodes to be managed;
[0010] If the item to be managed is to restart the Pod, the controller directly calls the K8S API to delete the target Pod corresponding to the node to be managed;
[0011] If the item to be managed is installation or uninstallation, the controller determines the target node to be managed based on the node to be managed and the target node, and then implements the installation or uninstallation of the Agent on the target node to be managed by modifying the affinity configuration of the target node to be managed in DaemonSet. When modifying the affinity configuration of the target node to be managed in DaemonSet, the affinity configuration of the target node to be managed is modified in batches until the modification of the affinity configuration of all target nodes to be managed is completed.
[0012] Furthermore, determining the Agent running in the cluster according to the running Pod and the Agent identifier in the predefined cluster, and then obtaining the target node to which the running Agent belongs, includes:
[0013] Get the identification field corresponding to the running Pod;
[0014] Match the identification field with the Agent identification in the cluster;
[0015] Determine the running Agent in the running Pod according to the matching result;
[0016] The target node to which the running Agent belongs is determined according to the running Agent.
[0017] Further, determining the running Agent in the running Pod according to the matching result includes:
[0018] If the matching result is that the identification field of the first running Pod in the running Pods matches the Agent identification in the cluster, then determining that the first running Pod in the running Pods is the running Agent;
[0019] If the matching result is that the identification field of the second running Pod in the running Pod does not match the Agent identification in the cluster, it is determined that the second running Pod in the running Pod is not the running Agent.
[0020] Furthermore, the controller determines a target node to be managed according to the node to be managed and the target node, including:
[0021] The target node to be managed is obtained by calculating the difference between the node to be managed and the target node.
[0022] Furthermore, the Agent on the target node to be managed is installed or uninstalled by modifying the affinity configuration of the target node to be managed in DaemonSet, including:
[0023] Grouping the target nodes to be managed according to a preset number to obtain multiple groups of target nodes to be managed;
[0024] Traverse the multiple groups of target nodes to be managed and perform the following operations;
[0025] Modify the affinity configuration of the target node to be managed in the current group of target nodes to be managed to achieve installation or uninstallation of the Agent on the target node to be managed in the current group of target nodes to be managed;
[0026] Determining whether the installation or uninstallation of the Agent on the target node to be managed in the current group of target nodes to be managed is successful based on the running status of the Agent collected by the collector;
[0027] If successful, obtain the next group of target nodes to be managed, and use the next group of target nodes to be managed as the current group of target nodes to be managed, return to execute the step of modifying the affinity configuration of the target nodes to be managed in the current group of target nodes to be managed, until traversing the multiple groups of target nodes to be managed, and completing the Agent management task.
[0028] Furthermore, the method further comprises:
[0029] If unsuccessful, the log information and failure message will be sent to the server, and the next group of target nodes to be managed will be obtained, and the next group of target nodes to be managed will be used as the current group of target nodes to be managed, and the step of modifying the affinity configuration of the target nodes to be managed in the current group of target nodes to be managed will be returned to execute until the multiple groups of target nodes to be managed are traversed.
[0030] Furthermore, the collector collects the Pods running in the cluster, including:
[0031] The collector collects the Pods running in the cluster in a watch manner.
[0032] In a second aspect, an embodiment of the present invention further provides an Agent management device in a cluster, which is applied to a cluster management component installed in the cluster. The cluster management component includes: a collector and a controller. The device includes:
[0033] A collection and determination unit, configured to collect the Pods running in the cluster by the collector, and determine the Agents running in the cluster according to the running Pods and predefined Agent identifiers in the cluster, thereby obtaining the target node to which the running Agents belong;
[0034] A receiving unit, configured for the controller to receive an Agent management task sent by a server, wherein the Agent management task carries information on items to be managed and nodes to be managed;
[0035] A calling unit, configured to, if the item to be managed is to restart a Pod, cause the controller to directly call the K8S API to delete the target Pod corresponding to the node to be managed;
[0036] A determination and modification unit, configured to: if the item to be managed is installation or uninstallation, the controller determines a target node to be managed based on the node to be managed and the target node, and then implements the installation or uninstallation of the Agent on the target node to be managed by modifying the affinity configuration of the target node to be managed in the DaemonSet; wherein, when modifying the affinity configuration of the target node to be managed in the DaemonSet, the affinity configuration of the target node to be managed is modified in batches until the modification of the affinity configuration of all target nodes to be managed is completed.
[0037] In a third aspect, an embodiment of the present invention further provides an electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the steps of any one of the methods described in the first aspect when executing the computer program.
[0038] In a fourth aspect, an embodiment of the present invention further provides a computer-readable storage medium, wherein the computer-readable storage medium stores machine-executable instructions. When the machine-executable instructions are called and executed by a processor, the machine-executable instructions prompt the processor to execute any method described in the first aspect above.
[0039] In an embodiment of the present invention, a method for managing an agent in a cluster is provided, which is applied to a cluster management component installed in the cluster. The cluster management component includes: a collector and a controller. The method includes: the collector collecting Pods running in the cluster, and determining the Agent running in the cluster based on the running Pods and a predefined Agent identifier in the cluster, and then obtaining a target node to which the running Agent belongs; the controller receiving an Agent management task sent by a server, wherein the Agent management task carries information about a to-be-managed item and a to-be-managed node; if the to-be-managed item is to restart the Pod, the controller directly calls a K8S API to delete the target Pod corresponding to the to-be-managed node; if the to-be-managed item is to install or uninstall, the controller determines a target to-be-managed node based on the to-be-managed node and the target node, and then installs or uninstalls the Agent on the target to-be-managed node by modifying the affinity configuration of the target to-be-managed node in a DaemonSet, wherein when modifying the affinity configuration of the target to-be-managed node in the DaemonSet, the affinity configuration of the target to-be-managed node is modified in batches until the affinity configuration of all target to-be-managed nodes is modified. From the above description, it can be seen that in the Agent management method in the cluster of the present invention, the Agent on any node in the cluster can be managed based on the Agent management task, which is easy to use and flexible. In addition, when managing, the installation or uninstallation of the Agent on the target node to be managed is achieved by modifying the affinity configuration of the target node to be managed in DaemonSet, and this is achieved in batches. This avoids sudden increases in instantaneous traffic and reduces the impact on other businesses. This alleviates the technical problems of the existing technology in managing the Agent in the cluster, which affects other businesses in the cluster and has poor management convenience and flexibility. BRIEF DESCRIPTION OF THE DRAWINGS
[0040] In order to more clearly illustrate the specific embodiments of the present invention or the technical solutions in the prior art, the following briefly introduces the drawings required for use in the specific embodiments or the description of the prior art. Obviously, the drawings described below are some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.
[0041] Figure 1 A flowchart of an Agent management method in a cluster provided by an embodiment of the present invention;
[0042] Figure 2 A flowchart of another method for managing agents in a cluster provided by an embodiment of the present invention;
[0043] Figure 3A schematic diagram of an Agent management device in a cluster provided by an embodiment of the present invention;
[0044] Figure 4 A schematic diagram of an electronic device provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0045] The following will clearly and completely describe the technical solutions of the present invention in conjunction with the embodiments. Obviously, the embodiments described are only some embodiments of the present invention, not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without making creative efforts are within the scope of protection of the present invention.
[0046] When managing Agents in a cluster, traditional technologies affect other services in the cluster and have poor management convenience and flexibility.
[0047] Based on this, the Agent management method in the cluster of the present invention can manage the Agent on any node in the cluster based on the Agent management task, which is easy to use and flexible. In addition, when managing, the installation or uninstallation of the Agent on the target node to be managed is achieved by modifying the affinity configuration of the target node to be managed in DaemonSet, and it is implemented in batches, avoiding sudden increases in instantaneous traffic and reducing the impact on other services.
[0048] To facilitate understanding of this embodiment, a method for managing an Agent in a cluster disclosed in an embodiment of the present invention is first introduced in detail.
[0049] Example 1:
[0050] According to an embodiment of the present invention, an embodiment of an agent management method in a cluster is provided. It should be noted that the steps shown in the flowcharts of the accompanying drawings can be executed in a computer system such as a set of computer-executable instructions, and although a logical order is shown in the flowcharts, in some cases, the steps shown or described can be executed in an order different from that shown here.
[0051] Figure 1 FIG. 1 is a flow chart of an Agent management method in a cluster according to an embodiment of the present invention. Figure 1 As shown, the method includes the following steps:
[0052] Step S102: The collector collects the Pods running in the cluster, and determines the Agents running in the cluster based on the running Pods and the predefined Agent identifiers in the cluster, and then obtains the target node to which the running Agents belong;
[0053] In an embodiment of the present invention, the above-described cluster agent management method can be applied to a cluster management component, which includes a collector and a controller. It should be noted that when performing management operations on agents in a cluster, the cluster management component must first be installed in the cluster. After the cluster management component is installed in the cluster, the cluster management component has the authority to manage the cluster. For example, the component can directly call the K8S API to perform related operations.
[0054] After obtaining the Agent running in the cluster, we can further obtain the target node to which the running Agent belongs, and then send the obtained target node to the controller.
[0055] Step S104: The controller receives the Agent management task sent by the server, wherein the Agent management task carries information about the items to be managed and the nodes to be managed;
[0056] Step S106: If the item to be managed is to restart the Pod, the controller directly calls the K8S API to delete the target Pod corresponding to the node to be managed;
[0057] In step S108, if the item to be managed is installation or uninstallation, the controller determines the target node to be managed based on the node to be managed and the target node, and then installs or uninstalls the Agent on the target node to be managed by modifying the affinity configuration of the target node to be managed in the DaemonSet. When modifying the affinity configuration of the target node to be managed in the DaemonSet, the affinity configuration of the target node to be managed is modified in batches until the affinity configuration of all target nodes to be managed is modified.
[0058] Specifically, traditional technologies use affinity configuration primarily to address emergencies. For example, if a node experiences a temporary problem, the node's affinity configuration can be modified to prevent programs (such as pods or agents) from running on the problematic node. However, in the present invention, the inventors apply affinity configuration to the installation and uninstallation management of agents, breaking with traditional techniques. This is a unique innovation of the present invention. In this implementation, if an agent is about to run on a node, it is considered to be installed; if the agent on a node no longer runs on that node, it is considered to be uninstalled.
[0059] In addition, to reduce the impact of instantaneous traffic surges caused by the simultaneous installation and startup of a large number of agents, modify the affinity of only a portion of the target nodes to be managed in the DaemonSet each time (that is, modify in batches). After the modification is complete, check the running status of the agents of these target nodes to be managed in the collector. After all are running normally, modify the remaining target nodes to be managed until the affinity configuration of all target nodes to be managed is modified.
[0060] In an embodiment of the present invention, a method for managing an agent in a cluster is provided, which is applied to a cluster management component installed in the cluster. The cluster management component includes: a collector and a controller. The method includes: the collector collecting Pods running in the cluster, and determining the Agent running in the cluster based on the running Pods and a predefined Agent identifier in the cluster, and then obtaining a target node to which the running Agent belongs; the controller receiving an Agent management task sent by a server, wherein the Agent management task carries information about a to-be-managed item and a to-be-managed node; if the to-be-managed item is to restart the Pod, the controller directly calls a K8S API to delete the target Pod corresponding to the to-be-managed node; if the to-be-managed item is to install or uninstall, the controller determines a target to-be-managed node based on the to-be-managed node and the target node, and then installs or uninstalls the Agent on the target to-be-managed node by modifying the affinity configuration of the target to-be-managed node in a DaemonSet, wherein when modifying the affinity configuration of the target to-be-managed node in the DaemonSet, the affinity configuration of the target to-be-managed node is modified in batches until the affinity configuration of all target to-be-managed nodes is modified. From the above description, it can be seen that in the Agent management method in the cluster of the present invention, the Agent on any node in the cluster can be managed based on the Agent management task, which is easy to use and flexible. In addition, when managing, the installation or uninstallation of the Agent on the target node to be managed is achieved by modifying the affinity configuration of the target node to be managed in DaemonSet, and this is achieved in batches. This avoids sudden increases in instantaneous traffic and reduces the impact on other businesses. This alleviates the technical problems of the existing technology in managing the Agent in the cluster, which affects other businesses in the cluster and has poor management convenience and flexibility.
[0061] The above content briefly introduces the Agent management method in the cluster of the present invention. The specific contents involved are described in detail below.
[0062] In an optional embodiment of the present invention, determining the Agent running in the cluster according to the running Pod and the predefined Agent identifier in the cluster, and then obtaining the target node to which the running Agent belongs, specifically includes the following steps:
[0063] (1) Get the identification field corresponding to the running Pod;
[0064] (2) Match the identification field with the Agent identification in the cluster;
[0065] (3) Determine the running Agent in the running Pod based on the matching results;
[0066] Specifically, if the matching result is that the identification field of the first running Pod in the running Pod matches the Agent identification in the cluster, then it is determined that the first running Pod in the running Pod is the running Agent; if the matching result is that the identification field of the second running Pod in the running Pod does not match the Agent identification in the cluster, then it is determined that the second running Pod in the running Pod is not the running Agent.
[0067] The first running Pod is any running Pod among the running Pods; the second running Pod is any running Pod among the running Pods, and the first running Pod and the second running Pod are not the same running Pod.
[0068] (4) Determine the target node to which the running Agent belongs based on the running Agent.
[0069] In an optional embodiment of the present invention, the controller determines the target node to be managed according to the node to be managed and the target node, specifically including the following steps:
[0070] The target node to be managed is obtained by calculating the difference between the node to be managed and the target node.
[0071] In an optional embodiment of the present invention, the Agent is installed or uninstalled on the target node to be managed by modifying the affinity configuration of the target node to be managed in DaemonSet, which specifically includes the following steps:
[0072] (1) Grouping the target nodes to be managed according to a preset number to obtain multiple groups of target nodes to be managed;
[0073] The above-mentioned preset number may be fixed, periodic, or increase according to a preset step size, and the embodiment of the present invention does not impose any specific limitation on it.
[0074] (2) Traverse multiple groups of target nodes to be managed and perform the following operations;
[0075] (21) Modify the affinity configuration of the target node to be managed in the current group of target nodes to be managed to achieve the installation or uninstallation of the Agent on the target node to be managed in the current group of target nodes to be managed;
[0076] (22) Determine whether the installation or uninstallation of the Agent on the target to-be-managed node in the current group of target to-be-managed nodes is successful based on the running status of the Agent collected by the collector;
[0077] (23) If successful, obtain the next set of target nodes to be managed, and use the next set of target nodes to be managed as the current set of target nodes to be managed. Return to the step of modifying the affinity configuration of the target nodes to be managed in the current set of target nodes to be managed, until multiple sets of target nodes to be managed are traversed, and the Agent management task is completed.
[0078] (24) If unsuccessful, the log information and failure message are sent to the server, and the next set of target nodes to be managed is obtained, and the next set of target nodes to be managed is used as the current set of target nodes to be managed. The process returns to the step of modifying the affinity configuration of the target nodes to be managed in the current set of target nodes to be managed, until multiple sets of target nodes to be managed are traversed.
[0079] In an optional embodiment of the present invention, the collector collects Pods running in the cluster, specifically including the following steps:
[0080] The collector collects data about Pods running in the cluster through watch.
[0081] Specifically, the collector obtains the Agent Pod in the cluster through the K8S watch interface, and then obtains the running Pod based on the Pod information.
[0082] Figure 2 The specific flow chart of the Agent management method in the cluster is shown in FIG.
[0083] If you operate certain Agent Pods directly by calling the K8S interface from the server, the server needs to load the kubeconfig file and then call the K8S interface to manually adjust the cluster Agent configuration (node affinity). This manual adjustment process is inaccurate and prone to errors. In addition, the server and cluster should belong to the same network, but sometimes due to security requirements, the server cannot directly access the cluster network. Moreover, directly loading kubeconfig on the server itself poses certain security risks. Therefore, the inventors invented the cluster management component of the present invention. The cluster management component manages the Agents in the cluster and controls the rate of cluster Agent operations by modifying the affinity of the DaemonSet (i.e., batch modification), reducing the potential impact on the business. At the same time, some management operations are completed by the program, which is highly secure, error-prone, and versatile because the server does not need to directly access the cluster network and there are no permission restrictions.
[0084] The present invention's cluster agent management method can complete the installation and uninstallation of agents in a cluster environment. This method introduces additional cluster management components into the cluster, including a collector and a controller. The collector is responsible for collecting pods running in the cluster and automatically identifying the agents running in the cluster environment and their target nodes based on the pod's identification field and the node where the pod is located. The controller identifies the target node to be managed based on the target node and the node where the agent is expected to be installed (i.e., the node to be managed). The controller then adjusts the affinity to ensure that the agent's operating status is consistent with that of the server. Furthermore, the cluster management component controls the rate at which node affinities are modified, enabling gradual installation and uninstallation of cluster agents, reducing the impact of the cluster agent on other services during management.
[0085] Example 2:
[0086] The embodiment of the present invention further provides an Agent management device in a cluster, which is mainly used to execute the Agent management method in a cluster provided in the first embodiment of the present invention. The Agent management device in a cluster provided in the embodiment of the present invention is specifically introduced below.
[0087] Figure 3 FIG. 1 is a schematic diagram of an Agent management device in a cluster according to an embodiment of the present invention. Figure 3 As shown, the device mainly includes: a collection and determination unit 10, a receiving unit 20, a calling unit 30, and a determination and modification unit 40, wherein:
[0088] The collection and determination unit is used to collect the Pods running in the cluster and determine the Agents running in the cluster based on the running Pods and the predefined Agent identifiers in the cluster, and then obtain the target node to which the running Agent belongs;
[0089] The receiving unit is used for the controller to receive the Agent management task sent by the server, wherein the Agent management task carries information about the items to be managed and the nodes to be managed;
[0090] The calling unit is used to call the K8S API to delete the target Pod corresponding to the node to be managed if the item to be managed is to restart the Pod;
[0091] A determination and modification unit is configured to determine the target node to be managed based on the node to be managed and the target node if the management item is installation or uninstallation, and then install or uninstall the Agent on the target node to be managed by modifying the affinity configuration of the target node to be managed in the DaemonSet. When modifying the affinity configuration of the target node to be managed in the DaemonSet, the affinity configuration of the target node to be managed is modified in batches until the affinity configuration of all target nodes to be managed is modified.
[0092] In an embodiment of the present invention, an agent management device in a cluster is provided, which is applied to a cluster management component installed in the cluster, the cluster management component including: a collector and a controller, and the method including: the collector collecting Pods running in the cluster, and determining the Agent running in the cluster based on the running Pods and a predefined Agent identifier in the cluster, and then obtaining the target node to which the running Agent belongs; the controller receiving an Agent management task sent by a server, wherein the Agent management task carries information about the item to be managed and the node to be managed; if the item to be managed is restarting the Pod, the controller directly calls the K8S API to delete the target Pod corresponding to the node to be managed; if the item to be managed is installation or uninstallation, the controller determines the target node to be managed based on the node to be managed and the target node, and then installs or uninstalls the Agent on the target node to be managed by modifying the affinity configuration of the target node to be managed in DaemonSet, wherein when modifying the affinity configuration of the target node to be managed in DaemonSet, the affinity configuration of the target node to be managed is modified in batches until the modification of the affinity configuration of all target nodes to be managed is completed. From the above description, it can be seen that in the Agent management device in the cluster of the present invention, the Agent on any node in the cluster can be managed based on the Agent management task, which is easy to use and flexible. In addition, when managing, the installation or uninstallation of the Agent on the target node to be managed is achieved by modifying the affinity configuration of the target node to be managed in DaemonSet, and it is implemented in batches. The sudden increase in instantaneous traffic is avoided and the impact on other businesses is reduced, which alleviates the technical problems of the existing technology in managing the Agent in the cluster, affecting other businesses in the cluster, and having poor management convenience and flexibility.
[0093] Optionally, the collection and determination unit is further configured to: obtain an identification field corresponding to the running Pod; match the identification field with an Agent identification in the cluster; determine the running Agent in the running Pod according to the matching result; and determine a target node to which the running Agent belongs according to the running Agent.
[0094] Optionally, the collection and determination unit is further used to: if the matching result is that the identification field of the first running Pod in the running Pod matches the Agent identification in the cluster, then determine that the first running Pod in the running Pod is the running Agent; if the matching result is that the identification field of the second running Pod in the running Pod does not match the Agent identification in the cluster, then determine that the second running Pod in the running Pod is not the running Agent.
[0095] Optionally, the determining and modifying unit is further configured to: calculate the difference between the node to be managed and the target node to obtain the target node to be managed.
[0096] Optionally, the determination and modification unit is further used to: group the target nodes to be managed according to a preset number to obtain multiple groups of target nodes to be managed; traverse the multiple groups of target nodes to be managed and perform the following operations; modify the affinity configuration of the target nodes to be managed in the current group of target nodes to be managed to achieve the installation or uninstallation of the Agent on the target nodes to be managed in the current group of target nodes to be managed; determine whether the installation or uninstallation of the Agent on the target nodes to be managed in the current group of target nodes to be managed is successful through the running status of the Agent collected by the collector; if successful, obtain the next group of target nodes to be managed, and use the next group of target nodes to be managed as the current group of target nodes to be managed, and return to the step of modifying the affinity configuration of the target nodes to be managed in the current group of target nodes to be managed, until the multiple groups of target nodes to be managed are traversed to complete the Agent management task.
[0097] Optionally, the determination and modification unit is also used to: if unsuccessful, send log information and failure message to the server, and then obtain the next group of target nodes to be managed, and use the next group of target nodes to be managed as the current group of target nodes to be managed, and return to execute the step of modifying the affinity configuration of the target nodes to be managed in the current group of target nodes to be managed, until multiple groups of target nodes to be managed are traversed.
[0098] Optionally, the collection and determination unit is further configured to: the collector collects Pods running in the cluster by watching.
[0099] The device provided in the embodiment of the present invention has the same implementation principle and technical effects as those in the aforementioned method embodiment. For the sake of brief description, for matters not mentioned in the device embodiment, reference can be made to the corresponding content in the aforementioned method embodiment.
[0100] like Figure 4 As shown, an electronic device 600 provided in an embodiment of the present application includes: a processor 601, a memory 602 and a bus, wherein the memory 602 stores machine-readable instructions executable by the processor 601. When the electronic device is running, the processor 601 communicates with the memory 602 through the bus, and the processor 601 executes the machine-readable instructions to perform the steps of the Agent management method in the above-mentioned cluster.
[0101] Specifically, the memory 602 and the processor 601 can be general-purpose memories and processors, which are not specifically limited here. When the processor 601 runs the computer program stored in the memory 602 , the Agent management method in the cluster can be executed.
[0102] The processor 601 may be an integrated circuit chip with signal processing capabilities. During implementation, each step of the above method can be completed by an integrated logic circuit of hardware in the processor 601 or by instructions in the form of software. The above-mentioned processor 601 can be a general-purpose processor, including a central processing unit (CPU), a network processor (NP), etc.; it can also be a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field-programmable gate array (FPGA), or other programmable logic devices, discrete gates or transistor logic devices, discrete hardware components. The various methods, steps, and logic block diagrams disclosed in the embodiments of the present application can be implemented or executed. The general-purpose processor can be a microprocessor or the processor can also be any conventional processor, etc. The steps of the method disclosed in conjunction with the embodiments of the present application can be directly embodied as being executed by a hardware decoding processor, or can be executed by a combination of hardware and software modules in the decoding processor. The software module can be located in a storage medium well-known in the art, such as random access memory, flash memory, read-only memory, programmable read-only memory, electrically erasable programmable memory, registers, etc. The storage medium is located in memory 602, and processor 601 reads the information in memory 602 and performs the steps of the above method in conjunction with its hardware.
[0103] Corresponding to the above-mentioned agent management method in the cluster, an embodiment of the present application further provides a computer-readable storage medium, which stores machine-executable instructions. When the computer-executable instructions are called and executed by a processor, the computer-executable instructions prompt the processor to execute the steps of the above-mentioned agent management method in the cluster.
[0104] The Agent management device in the cluster provided in the embodiment of the present application can be specific hardware on the device or software or firmware installed on the device. The implementation principle and technical effects of the device provided in the embodiment of the present application are the same as those of the aforementioned method embodiment. For the sake of brief description, any part not mentioned in the device embodiment can be referred to the corresponding content in the aforementioned method embodiment. Those skilled in the art can clearly understand that for the convenience and brevity of description, the specific working processes of the systems, devices, and units described above can all refer to the corresponding processes in the aforementioned method embodiment and will not be repeated here.
[0105] In the embodiments provided in this application, it should be understood that the disclosed devices and methods can be implemented in other ways. The device embodiments described above are merely 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 communication interface, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms.
[0106] For another example, the flowcharts and block diagrams in the accompanying drawings show the possible architectures, functions and operations of the devices, methods and computer program products according to multiple embodiments of the present application. In this regard, each box in the flowchart or block diagram can represent a module, a program segment or a part of code, and the module, program segment or a part of code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in an order different from that marked in the accompanying drawings. For example, two consecutive boxes can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram and / or flowchart, and the combination of the boxes in the block diagram and / or flowchart, can be implemented with a dedicated hardware-based system that performs the specified function or action, or can be implemented with a combination of dedicated hardware and computer instructions.
[0107] The units described as separate components may or may not be physically separate, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed across multiple network units. Some or all of these units may be selected to achieve the purpose of this embodiment according to actual needs.
[0108] In addition, each functional unit in the embodiments provided in 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.
[0109] If the functions are implemented as software functional units and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this application, or the portion that contributes to the prior art, or the portion of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions for enabling an electronic device (which can be a personal computer, server, or network device, etc.) to execute all or part of the steps of the agent management method in the cluster described in each embodiment of this application. The aforementioned storage medium includes various media that can store program code, such as a USB flash drive, a mobile hard drive, a read-only memory (ROM), a random access memory (RAM), a magnetic disk, or an optical disk.
[0110] It should be noted that similar numbers and letters represent similar items in the following figures. Therefore, once an item is defined in one figure, it does not need to be further defined and explained in subsequent figures. In addition, the terms "first", "second", "third", etc. are only used to distinguish the description and are not to be understood as indicating or implying relative importance.
[0111] Finally, it should be noted that the above-described embodiments are only specific implementation methods of the present application, which are used to illustrate the technical solutions of the present application, rather than to limit them. The scope of protection of the present application is not limited thereto. Although the present application has been described in detail with reference to the above-mentioned embodiments, those skilled in the art should understand that any person skilled in the art can modify or easily conceive of changes to the technical solutions described in the above-mentioned embodiments within the technical scope disclosed in the present application, or perform equivalent replacements for some of the technical features thereof. However, these modifications, changes, or replacements do not deviate the essence of the corresponding technical solutions from the scope of the technical solutions of the embodiments of the present application. They should all be included in the scope of protection of the present application. Therefore, the scope of protection of the present application should be based on the scope of protection of the claims.
Claims
1. A method for managing agents in a cluster, characterized in that: Applied to a cluster management component installed in a cluster, the cluster management component includes: a collector and a controller, the method includes: The collector collects the Pods running in the cluster, and determines the Agents running in the cluster according to the running Pods and the predefined Agent identifiers in the cluster, and then obtains the target node to which the running Agents belong; The controller receives an Agent management task sent by the server, wherein the Agent management task carries information about items to be managed and nodes to be managed; If the item to be managed is to restart the Pod, the controller directly calls the K8S API to delete the target Pod corresponding to the node to be managed; If the item to be managed is installation or uninstallation, the controller determines the target node to be managed based on the node to be managed and the target node, and then implements the installation or uninstallation of the Agent on the target node to be managed by modifying the affinity configuration of the target node to be managed in DaemonSet. When modifying the affinity configuration of the target node to be managed in DaemonSet, the affinity configuration of the target node to be managed is modified in batches until the modification of the affinity configuration of all target nodes to be managed is completed.
2. The method according to claim 1, characterized in that Determining the Agent running in the cluster according to the running Pod and the Agent identifier in the predefined cluster, and then obtaining the target node to which the running Agent belongs, including: Get the identification field corresponding to the running Pod; Match the identification field with the Agent identification in the cluster; Determine the running Agent in the running Pod according to the matching result; The target node to which the running Agent belongs is determined according to the running Agent.
3. The method according to claim 2, characterized in that Determining the running Agent in the running Pod according to the matching result includes: If the matching result is that the identification field of the first running Pod in the running Pods matches the Agent identification in the cluster, then determining that the first running Pod in the running Pods is the running Agent; If the matching result is that the identification field of the second running Pod in the running Pod does not match the Agent identification in the cluster, it is determined that the second running Pod in the running Pod is not the running Agent.
4. The method according to claim 1, wherein The controller determines a target node to be managed according to the node to be managed and the target node, including: The target node to be managed is obtained by calculating the difference between the node to be managed and the target node.
5. The method according to claim 1, wherein The Agent on the target node to be managed is installed or uninstalled by modifying the affinity configuration of the target node in DaemonSet, including: Grouping the target nodes to be managed according to a preset number to obtain multiple groups of target nodes to be managed; Traverse the multiple groups of target nodes to be managed and perform the following operations; Modify the affinity configuration of the target node to be managed in the current group of target nodes to be managed to achieve installation or uninstallation of the Agent on the target node to be managed in the current group of target nodes to be managed; Determining whether the installation or uninstallation of the Agent on the target node to be managed in the current group of target nodes to be managed is successful based on the running status of the Agent collected by the collector; If successful, obtain the next group of target nodes to be managed, and use the next group of target nodes to be managed as the current group of target nodes to be managed, return to execute the step of modifying the affinity configuration of the target nodes to be managed in the current group of target nodes to be managed, until traversing the multiple groups of target nodes to be managed, and completing the Agent management task.
6. The method according to claim 5, characterized in that The method further comprises: If unsuccessful, the log information and failure message will be sent to the server, and the next group of target nodes to be managed will be obtained, and the next group of target nodes to be managed will be used as the current group of target nodes to be managed, and the step of modifying the affinity configuration of the target nodes to be managed in the current group of target nodes to be managed will be returned to execute until the multiple groups of target nodes to be managed are traversed.
7. The method according to claim 1, characterized in that The collector collects Pods running in the cluster, including: The collector collects the Pods running in the cluster in a watch manner.
8. An Agent cluster management component installed in a cluster, characterized in that: The cluster management components include: a collector and a controller; The collector collects the Pods running in the cluster, and determines the Agent running in the cluster according to the running Pods and the predefined Agent identifiers in the cluster, and then obtains the target node to which the running Agent belongs; The controller receives an Agent management task sent by the server, wherein the Agent management task carries information about items to be managed and nodes to be managed; If the item to be managed is to restart the Pod, the controller directly calls the K8S API to delete the target Pod corresponding to the node to be managed; If the item to be managed is installation or uninstallation, the controller determines the target node to be managed based on the node to be managed and the target node, and then implements the installation or uninstallation of the Agent on the target node to be managed by modifying the affinity configuration of the target node to be managed in DaemonSet. When modifying the affinity configuration of the target node to be managed in DaemonSet, the affinity configuration of the target node to be managed is modified in batches until the modification of the affinity configuration of all target nodes to be managed is completed.
9. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 7 are implemented.
10. A computer-readable storage medium, characterized in that The computer-readable storage medium stores machine-executable instructions. When the machine-executable instructions are called and executed by a processor, the machine-executable instructions prompt the processor to execute the method according to any one of claims 1 to 7.
Citation Information
Patent Citations
K8s cluster evaluation method and system thereof and storage medium
CN113986465A
Software package installation method and system, electronic equipment and storage medium
CN118605900A