Agent management method and device in cluster, electronic equipment and storage medium

By introducing cluster management components into the K8S cluster, and using the collector and controller in combination, the problem of Agent management affecting other services, poor convenience and flexibility is solved, and flexible management and efficient management processes for Agents of any node in the cluster are realized.

CN119676045AActive Publication Date: 2025-03-21BEIJING SHENGXIN NETWORK TECH CO LTD
View PDF 4 Cites 0 Cited by

Patent Information

Application Number
CN202510179892.4
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-02-19
Publication Date
2025-03-21
Estimated Expiration
2045-02-19

AI Technical Summary

Technical Problem

In K8S cluster environment, the management of Agent has problems affecting other services, convenience and flexibility.

Method used

By introducing cluster management components composed of collectors and controllers into the cluster, the collector collects Pod information and determines the agent. The controller receives management tasks and implements installation or uninstallation of the agent by modifying the DaemonSet affinity configuration, and uses batch modifications to reduce instantaneous traffic.

Benefits of technology

It realizes flexible management of any node agent in the cluster, reduces the impact on other services, and improves management convenience and flexibility.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119676045A_ABST
    Figure CN119676045A_ABST
Patent Text Reader

Abstract

The invention provides an Agent management method and device in a cluster, electronic equipment and a storage medium, and belongs to the technical field of computers, in the method, Agents on any node in the cluster can be managed based on an Agent management task, use is convenient, flexibility is good, and in addition, during management, the Agent management efficiency is improved. According to the method, the Agent on the target to-be-managed node is installed or uninstalled by modifying the affinity configuration of the target to-be-managed node in the Daemon Set in a batch modification mode, sudden increase of instantaneous flow is avoided, and the influence on other services is reduced.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of computers, and in particular to an Agent management method, device, electronic equipment and storage medium in a cluster. Background Art

[0002] With the development of container technology, more and more companies or individuals are using K8S as a deployment environment. In the K8S cluster environment, a type of Agent is usually deployed, which plays the role of monitoring, managing and controlling server operations and functions to improve the security and reliability of the server. This type of Agent is deployed in the cluster as DaemonSet. DaemonSet is cluster-dimensional, so the DaemonSet controller can uniformly manage the Pods of all Agents, that is, operate all Agents at the same time. However, in actual use, it may be necessary to operate several of the Agents. At this time, the DaemonSet controller cannot be implemented.

[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 DaemonSet, ensuring that an agent program runs on each node. However, for the installation of the agent, if DaemonSet is used directly at the beginning, all agents will pull configurations and some data from the server at the same time when they are started, which will cause high instantaneous traffic and may affect other services in the cluster. In addition, it is impossible to operate several agents in the cluster, which is inconvenient to use and has poor flexibility.

[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 an Agent management method, device, electronic device and storage medium in a cluster to alleviate the technical problems of the prior art in that when managing Agents in a cluster, other services in the cluster are affected and the management convenience and flexibility are poor.

[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, and 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 Agent identifiers predefined 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 of 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, 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 the target nodes to be managed is completed.

[0008] Further, 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: Get the identification field corresponding to the running Pod; Matching 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.

[0009] Further, 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 Pods does not match the Agent identification in the cluster, it is determined that the second running Pod in the running Pods is not the running Agent.

[0010] Further, 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 subtracting the node to be managed from the target node.

[0011] Furthermore, 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, 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 the 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 through the running status of the Agent collected by the collector; If successful, the next group of target nodes to be managed is obtained, and the next group of target nodes to be managed is 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 is returned to execute until the multiple groups of target nodes to be managed are traversed, and the Agent management task is completed.

[0012] Furthermore, the method further comprises: If unsuccessful, the log information and failure message are sent to the server, and the next group of target nodes to be managed is obtained, and the next group of target nodes to be managed is 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 is returned until the multiple groups of target nodes to be managed are traversed.

[0013] Furthermore, the collector collects the Pods running in the cluster, including: The collector collects the Pods running in the cluster in a watch manner.

[0014] 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 a cluster, wherein the cluster management component includes: a collector and a controller, and the device includes: A collection and determination unit, used for the collector to collect the Pods running in the cluster, and determine the Agents running in the cluster according to the running Pods and the Agent identifiers predefined in the cluster, and then obtain the target node to which the running Agents belong; A receiving unit, used for the controller to receive an Agent management task sent by a server, wherein the Agent management task carries information of items to be managed and nodes to be managed; A calling unit, configured to, if the item to be managed is to restart the Pod, cause the controller to directly call the K8S API to delete the target Pod corresponding to the node to be managed; A determination and modification unit, for, if the item to be managed is installation or uninstallation, the controller determines the target node to be managed according to the node to be managed and the target node, and then realizes 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, 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 the target nodes to be managed is completed.

[0015] 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.

[0016] 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.

[0017] 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, wherein the cluster management component comprises: a collector and a controller, wherein the method comprises: the collector collects Pods running in the cluster, and determines the Agents running in the cluster according to the running Pods and a predefined Agent identifier in the cluster, and then obtains a target node to which the running Agent belongs; the controller receives an Agent management task sent by a 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 API of K8S to delete the target Pod corresponding to the node to be managed; if the item to be managed is to install or uninstall, the controller determines the target node to be managed according to 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 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 it is achieved in batches. The sudden increase in instantaneous traffic is avoided, the impact on other businesses is reduced, and the technical problems of the prior art affecting other businesses in the cluster, the convenience of management and poor flexibility when managing the Agent in the cluster are alleviated. BRIEF DESCRIPTION OF THE DRAWINGS

[0018] In order to more clearly illustrate the specific implementation methods of the present invention or the technical solutions in the prior art, the drawings required for use in the specific implementation methods or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are some implementation methods of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.

[0019] Figure 1 A flowchart of an Agent management method in a cluster provided by an embodiment of the present invention; Figure 2 A flowchart of another Agent management method in a cluster provided by an embodiment of the present invention; Figure 3 A schematic diagram of an Agent management device in a cluster provided by an embodiment of the present invention; Figure 4 A schematic diagram of an electronic device provided by an embodiment of the present invention. DETAILED DESCRIPTION

[0020] The technical solution of the present invention will be clearly and completely described below in conjunction with the embodiments. Obviously, the described embodiments are part of the embodiments of the present invention, rather than all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0021] When managing Agents in a cluster, traditional technologies affect other services in the cluster and have poor management convenience and flexibility.

[0022] Based on this, 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 it is achieved in batches, avoiding the sudden increase of instantaneous traffic and reducing the impact on other businesses.

[0023] 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.

[0024] Embodiment 1: 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 flowchart 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 flowchart, in some cases, the steps shown or described can be executed in an order different from that shown here.

[0025] 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 comprises the following steps: Step S102, 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; In an embodiment of the present invention, the Agent management method in the above cluster can be applied to a cluster management component, which includes a collector and a controller. It should be noted that when it is necessary to perform some management operations on the Agent in the cluster, it is first necessary to install the cluster management component in the cluster. After the cluster management component is installed in the cluster, the cluster management component has the authority to manage the cluster, such as the component can directly call the K8S API to perform related operations.

[0026] After obtaining the Agent running in the cluster, the target node to which the running Agent belongs can be further obtained, and then the obtained target node is sent to the controller.

[0027] Step S104, the controller receives the Agent management task sent by the server, wherein the Agent management task carries information of items to be managed and nodes to be managed; 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; Step S108, if the item to be managed is installation or uninstallation, the controller determines the target node to be managed according to the node to be managed and the target node, and then realizes 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.

[0028] Specifically, the application of affinity configuration in traditional technology is mainly to deal with some emergencies. For example, if a node has a temporary problem, the affinity configuration of the node can be modified to prohibit the program (such as Pod or Agent) from running on the node with the problem. In the present invention, the inventor applies affinity configuration to the installation and uninstallation management of Agent, breaking the application of affinity configuration in traditional technology. This is original to the present invention. When implemented, if an Agent is to run on a node, it is considered to be installed; if the Agent on a node no longer runs on the node, it is considered to be uninstalled.

[0029] In addition, to reduce the impact of instantaneous traffic surges caused by the simultaneous installation and startup of a large number of agents, only a portion of the target nodes to be managed are modified in the affinity of DaemonSet each time (that is, batch modification). After the modification is completed, 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.

[0030] 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, wherein the cluster management component comprises: a collector and a controller, wherein the method comprises: the collector collects Pods running in the cluster, and determines the Agents running in the cluster according to the running Pods and a predefined Agent identifier in the cluster, and then obtains a target node to which the running Agent belongs; the controller receives an Agent management task sent by a 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 API of K8S to delete the target Pod corresponding to the node to be managed; if the item to be managed is to install or uninstall, the controller determines the target node to be managed according to 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 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 it is achieved in batches. The sudden increase in instantaneous traffic is avoided, the impact on other businesses is reduced, and the technical problems of the prior art affecting other businesses in the cluster, the convenience of management and poor flexibility when managing the Agent in the cluster are alleviated.

[0031] 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.

[0032] In an optional embodiment of the present invention, the Agent running in the cluster is determined according to the running Pod and the Agent identifier in the predefined cluster, and then the target node to which the running Agent belongs is obtained, which specifically includes the following steps: (1) Get the identification field corresponding to the running Pod; (2) Match the identification field with the Agent identification in the cluster; (3) Determine the running Agent in the running Pod based on the matching results; Specifically, 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, it is determined 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 Pods does not match the Agent identification in the cluster, it is determined that the second running Pod in the running Pods is not the running Agent.

[0033] 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.

[0034] (4) Determine the target node to which the running Agent belongs based on the running Agent.

[0035] 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: The target node to be managed is obtained by subtracting the node to be managed from the target node.

[0036] In an optional embodiment of the present invention, 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, which specifically includes the following steps: (1) Grouping the target nodes to be managed according to a preset number to obtain multiple groups of target nodes to be managed; The above-mentioned preset number may be fixed, periodic, or increasing according to a preset step size, and the embodiment of the present invention does not impose any specific limitation on it.

[0037] (2) Traverse multiple groups of target nodes to be managed and perform the following operations; (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; (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 through the running status of the Agent collected by the collector; (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 execute 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. (24) If unsuccessful, the log information and failure message are sent to the server, and then 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, and the step of modifying the affinity configuration of the target nodes to be managed in the current set of target nodes to be managed is returned to execute until multiple sets of target nodes to be managed are traversed.

[0038] In an optional embodiment of the present invention, the collector collects Pods running in the cluster, specifically including the following steps: The collector collects Pods running in the cluster by watching.

[0039] Specifically, the collector obtains the Pod of the Agent in the cluster through the K8S watch interface, and then obtains the running Pod based on the Pod information.

[0040] Figure 2 A specific flow chart of the Agent management method in the cluster is shown in FIG.

[0041] If the Pod of some Agents is operated directly by calling the K8S interface on the server, the server needs to load the kubeconfig file, and then call the K8S interface to manually adjust the configuration of the cluster Agent (node ​​affinity). The manual adjustment process has poor accuracy and is prone to errors. In addition, the server and the cluster should belong to the same network, but sometimes due to security requirements, the server cannot directly access the network where the cluster is located, and the method of directly loading kubeconfig on the server itself has certain security risks. Therefore, the inventor invented the cluster management component of the present invention, which manages the Agents in the cluster through the cluster management component, controls the operation rate of the cluster Agent by modifying the affinity of DaemonSet (i.e., batch modification), reduces the possible impact on the business, and at the same time, some management operations are completed by the program, which is highly secure and not prone to errors, and has good versatility, because there is no need for the server to directly access the network where the cluster is located, and there is no permission restriction.

[0042] The Agent management method in the cluster of the present invention can complete the installation and uninstallation of the Agent in the cluster environment. The method will introduce additional cluster management components in the cluster, and the cluster management components include: a collector and a controller, wherein the collector is responsible for collecting the Pods running in the cluster, and automatically identifies the Agents running in the cluster environment and the target nodes to which they belong according to the identification field of the Pod and the node where the Pod is located; the controller identifies the target node to be managed according to the target node and the node expected to install the Agent (i.e., the node to be managed), and then adjusts the affinity to achieve consistency between the running state of the Agent and the server. In addition, the cluster management component controls the rate of modifying the node affinity, so as to achieve the gradual installation and uninstallation of the cluster Agent, and reduce the impact of the cluster Agent on other services during the management process.

[0043] Embodiment 2: 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.

[0044] Figure 3 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: The collection and determination unit is used for the collector to collect the Pods running in the cluster, and determine the Agents running in the cluster according to the running Pods and the predefined Agent identifiers in the cluster, and then obtain the target node to which the running Agent belongs; A receiving unit, used for the controller to receive the Agent management task sent by the server, wherein the Agent management task carries information of the items to be managed and the nodes to be managed; The calling unit is used for directly calling 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; The determination and modification unit is used for, if the matter to be managed is installation or uninstallation, the controller determines the target node to be managed according to the node to be managed and the target node, and then realizes 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, 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.

[0045] 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, wherein the cluster management component comprises: a collector and a controller, and the method comprises: the collector collects Pods running in the cluster, and determines the Agents running in the cluster according to the running Pods and a predefined Agent identifier in the cluster, and then obtains the target node to which the running Agent belongs; the controller receives an Agent management task sent by a server, wherein the Agent management task carries information of 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 API of K8S to delete the target Pod corresponding to the node to be managed; if the item to be managed is to install or uninstall, the controller determines the target node to be managed according to the node to be managed and the target node, and then realizes 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, 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 known 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 achieved in batches. The sudden increase in instantaneous traffic is avoided, the impact on other services is reduced, and the technical problems of the prior art affecting other services in the cluster, poor management convenience and flexibility when managing the Agent in the cluster are alleviated.

[0046] Optionally, the collecting and determining unit is further used 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.

[0047] Optionally, the collection and determination unit is also used to: 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 determine 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 Pods does not match the Agent identification in the cluster, then determine that the second running Pod in the running Pods is not the running Agent.

[0048] Optionally, the determining and modifying unit is further used to: calculate the difference between the node to be managed and the target node to obtain the target node to be managed.

[0049] Optionally, the determination and modification unit is also 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 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 the multiple groups of target nodes to be managed are traversed to complete the Agent management task.

[0050] 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.

[0051] Optionally, the collection and determination unit is further used for: the collector collects Pods running in the cluster by watching.

[0052] The device provided in the embodiment of the present invention has the same implementation principle and technical effects as those of the aforementioned method embodiment. For the sake of brief description, for matters not mentioned in the device embodiment, reference may be made to the corresponding contents in the aforementioned method embodiment.

[0053] 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 cluster.

[0054] 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.

[0055] The processor 601 may be an integrated circuit chip with signal processing capabilities. In the implementation process, each step of the above method can be completed by the hardware integrated logic circuit or software instructions in the processor 601. The above 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 methods, steps and logic block diagrams disclosed in the embodiments of the present application can be implemented or executed. The general processor can be a microprocessor or the processor can also be any conventional processor, etc. The steps of the method disclosed in the embodiments of the present application can be directly embodied as a hardware decoding processor for execution, or a combination of hardware and software modules in the decoding processor for execution. The software module may be located in a storage medium mature in the art such as a random access memory, a flash memory, a read-only memory, a programmable read-only memory, or an electrically erasable programmable memory, a register, etc. The storage medium is located in the memory 602, and the processor 601 reads the information in the memory 602 and completes the steps of the above method in combination with its hardware.

[0056] Corresponding to the above-mentioned Agent management method in the cluster, an embodiment of the present application further provides a computer-readable storage medium, wherein the computer-readable storage medium 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.

[0057] 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 device provided in the embodiment of the present application has the same implementation principle and technical effects as the aforementioned method embodiment. For the sake of brief description, the parts not mentioned in the device embodiment can refer to the corresponding contents in the aforementioned method embodiment. Those skilled in the art can clearly understand that for the convenience and simplicity 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.

[0058] In the embodiments provided in the present 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 interfaces, and the indirect coupling or communication connection of the devices or units can be electrical, mechanical or other forms.

[0059] For another example, the flowchart and block diagram in the accompanying drawings show the possible architecture, function and operation of the device, method and computer program product 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 the code, and the module, the program segment or a part of the 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 a different order from the order 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 the flowchart, and the combination of the boxes in the block diagram and / or the flowchart can be implemented with a dedicated hardware-based system that performs a specified function or action, or can be implemented with a combination of dedicated hardware and computer instructions.

[0060] 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 of this embodiment.

[0061] 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.

[0062] If the functions are implemented in the form of 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 the present application, or the part that contributes to the prior art or the part of the technical solution, can be embodied in the form of a software product. The computer software product is stored in a storage medium, including several instructions to enable 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 the present application. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (Read-Only Memory, referred to as ROM), random access memory (Random Access Memory, referred to as RAM), disk or optical disk and other media that can store program codes.

[0063] 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.

[0064] 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 solution of the present application, rather than to limit it. The protection scope of the present application is not limited thereto. Although the present application is described in detail with reference to the aforementioned embodiments, ordinary technicians in the field should understand that any technician familiar with the technical field can still modify the technical solution recorded in the aforementioned embodiments within the technical scope disclosed in the present application, or can easily think of changes, or make equivalent replacements for some of the technical features therein; and these modifications, changes or replacements do not make the essence of the corresponding technical solution deviate from the scope of the technical solution of the embodiment of the present application. They should all be included in the protection scope of the present application. Therefore, the protection scope of the present application shall be based on the protection scope of the claims.

Claims

1. A method for managing agents in a cluster, characterized in that: The method is applied to a cluster management component installed in a cluster, the cluster management component includes: a collector and a controller, and 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 Agent identifiers predefined 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 of 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, 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 the 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, includes: Get the identification field corresponding to the running Pod; Matching 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 Pods does not match the Agent identification in the cluster, it is determined that the second running Pod in the running Pods is not the running Agent.

4. The method according to claim 1, characterized in that: 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 subtracting the node to be managed from the target node.

5. The method according to claim 1, characterized in that 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: 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 the 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 through the running status of the Agent collected by the collector; If successful, the next group of target nodes to be managed is obtained, and the next group of target nodes to be managed is 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 is returned to execute until the multiple groups of target nodes to be managed are traversed, and the Agent management task is completed.

6. The method according to claim 5, characterized in that The method further comprises: If unsuccessful, the log information and failure message are sent to the server, and the next group of target nodes to be managed is obtained, and the next group of target nodes to be managed is 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 is returned 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 the Pods running in the cluster, including: The collector collects the Pods running in the cluster in a watch manner.

8. An Agent management device in a cluster, characterized in that: The cluster management component is applied to a cluster installed in a cluster, the cluster management component includes: a collector and a controller, and the device includes: A collection and determination unit, used for the collector to collect the Pods running in the cluster, and determine the Agents running in the cluster according to the running Pods and the Agent identifiers predefined in the cluster, and then obtain the target node to which the running Agents belong; A receiving unit, used for the controller to receive an Agent management task sent by a server, wherein the Agent management task carries information of items to be managed and nodes to be managed; A calling unit, configured to, if the item to be managed is to restart the Pod, cause the controller to directly call the K8S API to delete the target Pod corresponding to the node to be managed; A determination and modification unit, for, if the item to be managed is installation or uninstallation, the controller determines the target node to be managed according to the node to be managed and the target node, and then realizes 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, 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 the 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

  • Data monitoring method and device for kubernetes edge cluster

    CN114466017A

  • Software package installation method and system, electronic equipment and storage medium

    CN118605900A

  • Active assurance of network slices

    US20240422090A1