Node control method and device in cloud native scene, equipment and storage medium
Through the communication and status statistics of proxy components between master and slave nodes in the k8s system, the autonomous management of slave nodes is realized, solving the problem that the cluster cannot work when the master node is dead, and improving business stability.
Patent Information
- Application Number
- CN202411192280.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-28
- Publication Date
- 2025-01-14
AI Technical Summary
In cloud native scenarios, when the main node in the k8s system is dead, the cluster is in an unworkable state, making it difficult to ensure business stability.
Through the communication between the proxy component between the master node and the slave node, the master node generates a token and sends information to the slave node, causing the slave node to report status information and count the number. When the number is less than or equal to the threshold, the master node is downgraded to the slave node. , normally upgrade from node to master node to take over management functions.
Even if the master node fails, the system can still ensure stable business operation, realize slave nodes to manage clusters automatically, and improve cluster business stability in cloud-native scenarios.
Smart Images

Figure CN119316468A_ABST
Abstract
Description
Technical Field
[0001] The present disclosure relates to the field of computer technology, and in particular to a node control method, device, equipment and storage medium in a cloud native scenario. Background Art
[0002] Cloud Native is a new IT architecture supported by containers (docker) and kubernetes (k8s). Cloud Native technology helps organizations build and run elastically scalable applications in new dynamic environments such as public clouds, private clouds, and hybrid clouds. Representative technologies of cloud native can include containers, service meshes, microservices, immutable infrastructure, and declarative application programming interfaces (APIs). Cloud Native technology can build loosely coupled systems that are fault-tolerant, easy to manage, and easy to observe. Combined with reliable automation methods, cloud Native technology enables engineers to easily make frequent and predictable major changes to the system. Cloud Native container orchestration systems represented by k8s provide unified scheduling and elastic expansion capabilities, as well as standardized components and services to support rapid development and deployment.
[0003] Kubernetes in cloud native technology, referred to as k8s, is an open source container orchestration system. It is an open source system for automatically deploying, scaling and managing containerized applications. It can combine the containers that make up the application into logical units for easy management and service discovery. The goal of k8s is to make the deployment of containerized applications simple and efficient, and it is mainly used for automated deployment, scaling and management of containerized applications.
[0004] The k8s system is mainly composed of two types of nodes: the master node (Master) and the slave node (Node). The Node is the working node of k8s, which is responsible for receiving work instructions from the Master, creating and destroying pod objects accordingly, and adjusting network rules for reasonable routing and traffic forwarding. Each node can be understood as a computer device. The interface service component (apiserver) in the master node is one of the core components of the entire system. It is the gateway and central hub of the distributed cluster, responsible for coordinating all components, managing the status and resources of the system, and providing API interfaces for external applications or users to access and use, tracking the health status of other servers, scheduling loads in an optimal way, and orchestrating communications between other components.
[0005] When the master node to which the apiserver service in k8s belongs hangs up (does not work), the k8s system will be in an unworkable state, which is quite dangerous for the k8s cluster. At this time, the business cannot be served normally, and it is difficult to meet the business stability requirements of the cloud native cluster. Summary of the invention
[0006] In order to solve the above technical problems, the present disclosure provides a node control method, device, equipment and storage medium in a cloud native scenario.
[0007] A first aspect of the present disclosure provides a node control method in a cloud native scenario, the method is applied to a k8s container orchestration system in a cloud native scenario, the k8s container orchestration system includes a master node and at least one slave node, each node is deployed with an agent component, the agent component in the master node is a master agent component, and the agent component in the slave node is a slave agent component, the method includes:
[0008] In response to the master agent component composed of the target agent components in the master node being started, the master agent component generates a token and sends the target component information of the master agent component to the slave agent components in each slave node, so that each slave agent component reports the component information of the slave agent component to the master agent component based on the target component information;
[0009] The master agent component receives the component information reported by each slave agent component at a first preset time interval, and counts the number of slave agent components that report the component information at a second preset time interval;
[0010] When the number is less than or equal to a preset threshold, the master agent component releases the token to downgrade the master node to which the master agent component belongs to a slave node;
[0011] In response to the master agent component releasing the token, each slave agent component determines that the master node to which the master agent component belongs is abnormal, and the first slave agent component in a normal state among the slave agent components is upgraded to the master agent component, so that the slave node to which the first slave agent component belongs is upgraded to the master node, and the first slave agent component, as the master agent component, executes the steps of generating the token and subsequent steps of generating the token.
[0012] A second aspect of the present disclosure provides a node control device in a cloud native scenario, the device is applied to a k8s container orchestration system in a cloud native scenario, the k8s container orchestration system includes a master node and at least one slave node, each node is deployed with an agent component, the agent component in the master node is a master agent component, and the agent component in the slave node is a slave agent component, the device includes:
[0013] A generating module, configured to respond to the master agent component consisting of the target agent components in the master node starting up, the master agent component generating a token, and sending the target component information of the master agent component to the slave agent components in each slave node, so that each slave agent component reports the component information of the slave agent component to the master agent component based on the target component information;
[0014] A first receiving module is used for the master agent component to receive the component information reported by each slave agent component at a first preset time interval, and to count the number of slave agent components that report the component information at a second preset time interval;
[0015] A release module, used for the master agent component to release the token when the number is less than or equal to a preset threshold, so that the master node to which the master agent component belongs is downgraded to a slave node;
[0016] The first upgrade module is used for responding to the master proxy component releasing the token, each slave proxy component determines that the master node to which the master proxy component belongs is abnormal, and the first slave proxy component in a normal state among the slave proxy components is upgraded to the master proxy component, so that the slave node to which the first slave proxy component belongs is upgraded to the master node, and the first slave proxy component performs the steps of generating the token and the steps after the token is generated as the master proxy component
[0017] A third aspect of the present disclosure provides a computer device, comprising:
[0018] A memory and a processor, wherein a computer program is stored in the memory, and when the computer program is executed by the processor, the node control method in the cloud native scenario of the first aspect above can be implemented.
[0019] A fourth aspect of the present disclosure provides a computer-readable storage medium, in which a computer program is stored. When the computer program is executed by a processor, the node control method in the cloud native scenario of the first aspect can be implemented.
[0020] Compared with the prior art, the technical solution provided by the present invention has the following advantages:
[0021] The present disclosure responds to the start of a master agent component composed of target agent components in a master node, the master agent component generates a token, and sends the target component information of the master agent component to the slave agent components in each slave node, so that each slave agent component reports the component information of the slave agent component to the master agent component based on the target component information; the master agent component receives the component information reported by each slave agent component at a first preset time interval, and counts the number of slave agent components that report the component information at a second preset time interval; when the number is less than or equal to a preset threshold, the master agent component releases the token, so that the master node to which the master agent component belongs is downgraded to a slave node; in response to the master agent component releasing the token, each slave agent component determines that the master node to which the master agent component belongs is abnormal, and the first slave agent component in a normal state in the slave agent component is upgraded to the master agent component, so that the slave node to which the first slave agent component belongs is upgraded to the master node, and the first slave agent component, as the master agent component, executes the steps of generating the token and subsequent steps of generating the token. The present invention can enable the slave node to obtain the working status of the master node in time through the communication between the proxy components in the nodes. When the working status of the master node is abnormal, the slave node in normal state takes over the function of managing the k8s cluster from the master node through the control of the proxy component in the node. Even if the k8s cluster service of the master node is lost, all slave nodes can still ensure the stable service of the k8s system to realize the business, thereby achieving the ability of the slave node to autonomously manage the k8s cluster and improving the business stability of the cluster in the cloud native scenario. BRIEF DESCRIPTION OF THE DRAWINGS
[0022] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present disclosure and, together with the description, serve to explain the principles of the present disclosure.
[0023] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, for ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative labor.
[0024] Figure 1 It is a structural diagram of a k8s container orchestration system in a cloud native scenario provided by an embodiment of the present disclosure;
[0025] Figure 2 is a flowchart of a node control method in a cloud native scenario provided by an embodiment of the present disclosure;
[0026] Figure 3 is a flowchart of another node control method in a cloud native scenario provided by an embodiment of the present disclosure;
[0027] Figure 4is a flowchart of another node control method in a cloud native scenario provided by an embodiment of the present disclosure;
[0028] Figure 5 It is a structural diagram of a node control device in a cloud native scenario provided by an embodiment of the present disclosure. DETAILED DESCRIPTION
[0029] In order to more clearly understand the above-mentioned objectives, features and advantages of the present disclosure, the scheme of the present disclosure will be further described below. It should be noted that the embodiments of the present disclosure and the features in the embodiments can be combined with each other without conflict.
[0030] In the following description, many specific details are set forth to facilitate a full understanding of the present disclosure, but the present disclosure may also be implemented in other ways different from those described herein; it is obvious that the embodiments in the specification are only part of the embodiments of the present disclosure, rather than all of the embodiments.
[0031] It should be understood that the various steps described in the method embodiments of the present disclosure may be performed in different orders and / or in parallel. In addition, the method embodiments may include additional steps and / or omit the steps shown. The scope of the present disclosure is not limited in this respect.
[0032] It should be noted that, in this article, relational terms such as "first" and "second" are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the sentence "comprise a ..." do not exclude the existence of other identical elements in the process, method, article or device including the elements.
[0033] It should be noted that the modifications of "one" and "plurality" mentioned in the present disclosure are illustrative rather than restrictive, and those skilled in the art should understand that unless otherwise clearly indicated in the context, it should be understood as "one or more".
[0034] The node control method in the cloud native scenario provided by the embodiment of the present disclosure can be executed by the k8s container orchestration system in the cloud native scenario.
[0035] In order to better understand the inventive concept of the embodiments of the present disclosure, the technical solutions of the embodiments of the present disclosure are described below in conjunction with exemplary embodiments.
[0036] Figure 1 is a schematic diagram of the structure of a k8s container orchestration system in a cloud native scenario provided by an embodiment of the present disclosure, such as Figure 1 As shown, the k8s container orchestration system can include 1 master node master and 2 slave nodes node1 and node2. A k8s component and an agent component (agent component) are deployed in each node. The agent component in the master node is called the master agent component, and the agent component in the slave node is called the slave agent component.
[0037] The k8s components in the master node may include the interface service unit apiserver, the control unit controller-manager, and the scheduling unit scheduler; the k8s components in the slave node may include the control unit kubelet and the core unit kube-proxy.
[0038] The agent component can include a synchronization unit, agent-db, a control unit, agent-sync-apiserver, and a scheduling unit, agent-launch. Agent-db is responsible for synchronizing data with the etcd database of the k8s container orchestration system and recording various information of the container pod of each slave node; agent-sync-apiserver is used to ensure the survival of the apiserver of the master node and to communicate with the agent of the slave node (including two-way actions of receiving and sending information); agent-launch is used to schedule, create, and destroy the pod of the slave node.
[0039] Pod is the smallest basic unit of deployment and management in the k8s container orchestration system.
[0040] Figure 2 is a flowchart of a node control method in a cloud native scenario provided by an embodiment of the present disclosure. The method can be executed by a k8s container orchestration system in a cloud native scenario. A node can be understood as any computer device with processing and computing capabilities, such as Figure 2 As shown, the node control method in the cloud native scenario provided by this embodiment includes the following steps:
[0041] Step 210, in response to the master agent component composed of the target agent components in the master node being started, the master agent component generates a token and sends the target component information of the master agent component to the slave agent components in each slave node, so that each slave agent component reports the component information of the slave agent component to the master agent component based on the target component information.
[0042] In the disclosed embodiment, the target agent components included in the master node constitute the master agent component. In response to the start of the master agent component in the master node, that is, the master agent component starts the independent binary processes of agent-db, agent-sync-apiserver, and agent-launch, the master agent component can generate a token (key-token) and send the target component information of the master agent component to the slave agent components in each slave node, that is, tell all the slave agent components that I am the master agent component. After each slave agent component receives the target component information, it can report the component information of the slave agent component to the master agent component based on the target component information.
[0043] The token can be understood as identification information that indicates the identity of the main agent component.
[0044] Component information can be understood as data describing the status, configuration, etc. of the proxy component.
[0045] Step 220: The master agent component receives the component information reported by each slave agent component at a first preset time interval, and counts the number of slave agent components that report the component information at a second preset time interval.
[0046] In the disclosed embodiment, the master agent component in the master node may receive component information reported by each slave agent component every first preset time period, and count the number of slave agent components reporting component information every second preset time period.
[0047] The first preset duration can be set as needed, for example, 10 seconds, which is not limited here.
[0048] The second preset duration can be set as needed, for example, 30 seconds, which is not limited here.
[0049] Step 230: When the number is less than or equal to a preset threshold, the master agent component releases the token to downgrade the master node to which the master agent component belongs to a slave node.
[0050] In the disclosed embodiment, when the number of slave agent components that report component information to the master agent component is less than or equal to a preset threshold, it indicates that most of the slave agent components are unable to communicate with the master agent component, and there is an abnormality in the master node to which the master agent component belongs. At this time, the master agent component can release the token, whereby the master node to which the master agent component belongs is downgraded to a slave node.
[0051] Step 240, in response to the master agent component releasing the token, each slave agent component determines that the master node to which the master agent component belongs is abnormal, and the first slave agent component in a normal state among the slave agent components is upgraded to the master agent component, so that the slave node to which the first slave agent component belongs is upgraded to the master node, and the first slave agent component, as the master agent component, executes the steps of generating the token and subsequent steps of generating the token.
[0052] In the disclosed embodiment, when the master agent component in the master node releases the token, the slave agent component in each slave node can determine that the master node to which the master agent component belongs is abnormal. At this time, the first slave agent component in the slave agent components that is in a normal state can be upgraded to the master agent component, thereby upgrading the slave node to which the first slave agent component belongs to the master node, and the first slave agent component, as the master agent component, executes the steps of generating the token and subsequent steps of generating the token, that is, the first slave agent component executes the actions of the master agent component.
[0053] In an embodiment of the present disclosure, a master agent component composed of target agent components in a master node is started in response, the master agent component generates a token, and sends target component information of the master agent component to slave agent components in each slave node, so that each slave agent component reports component information of the slave agent component to the master agent component based on the target component information; the master agent component receives component information reported by each slave agent component at intervals of a first preset time period, and counts the number of slave agent components that report component information at intervals of a second preset time period; when the number is less than or equal to a preset threshold, the master agent component releases the token, so that the master node to which the master agent component belongs is downgraded to a slave node; in response to the master agent component releasing the token, each slave agent component determines that the master node to which the master agent component belongs is abnormal, and a first slave agent component in a normal state in the slave agent component is upgraded to a master agent component, so that the slave node to which the first slave agent component belongs is upgraded to a master node, and the first slave agent component, as the master agent component, executes steps of generating a token and subsequent steps of generating a token. The present invention can enable the slave node to obtain the working status of the master node in time through the communication between the proxy components in the nodes. When the working status of the master node is abnormal, the slave node in normal state takes over the function of managing the k8s cluster from the master node through the control of the proxy component in the node. Even if the k8s cluster service of the master node is lost, all slave nodes can still ensure the stable service of the k8s system to realize the business, thereby achieving the ability of the slave node to autonomously manage the k8s cluster and improving the business stability of the cluster in the cloud native scenario.
[0054] Figure 3 is a flowchart of a node control method in a cloud native scenario provided by an embodiment of the present disclosure. The method can be executed by a k8s container orchestration system in a cloud native scenario. A node can be understood as any computer device with processing and computing capabilities, such as Figure 3 As shown, the node control method in the cloud native scenario provided by this embodiment includes the following steps:
[0055] Step 310: For the proxy component in each node, in response to the proxy component being started, the proxy component obtains a score set from the configuration file, the score set including the scores of the proxy components in each node, and the target proxy component corresponding to the maximum score in the score set is the main proxy component.
[0056] In the disclosed embodiment, for the agent component in each node in the k8s container orchestration system, in response to the agent component being started, the agent component can obtain a score set from a configuration file. The score set may include the scores of the agent components in each node, and the target agent component corresponding to the maximum score in the score set is the master agent component in the master node.
[0057] The configuration file may be generated based on the user configuration of the client, and the configuration file may include a score set and a communication address of the proxy component in each node.
[0058] For example, the configuration file may be a config.yaml file, and the communication address may be an Internet Protocol Address (IP address).
[0059] The user can set the score of the proxy component in each node as needed. For example, the score of each proxy component in the score set is negatively correlated with the load of the node to which the proxy component belongs, that is, the greater the load of the node, the smaller the score of the proxy component in the node.
[0060] Step 320, in response to the master agent component composed of the target agent components in the master node being started, the master agent component generates a token and sends the target component information of the master agent component to the slave agent components in each slave node, so that each slave agent component reports the component information of the slave agent component to the master agent component based on the target component information.
[0061] Step 330: The master agent component receives the component information reported by each slave agent component at a first preset time interval, and counts the number of slave agent components that report the component information at a second preset time interval.
[0062] Step 340: When the number is less than or equal to a preset threshold, the master agent component releases the token to downgrade the master node to which the master agent component belongs to a slave node.
[0063] Step 350: In response to the master agent component releasing the token, each slave agent component determines that the master node to which the master agent component belongs is abnormal, and the first slave agent component in a normal state among the slave agent components is upgraded to a master agent component, so that the slave node to which the first slave agent component belongs is upgraded to a master node, and the first slave agent component performs the steps of generating the token and subsequent steps of generating the token as the master agent component, and the first slave agent component is in a normal state and the score of the first slave agent component is second only to the target score of the target agent component in the score set.
[0064] In the disclosed embodiment, the first slave proxy component is in a normal state and the score of the first slave proxy component is second only to the target score of the target proxy component in the score set, that is, the first slave proxy component is in a normal state and the score of the first slave proxy component is lower than the target score of the master proxy component composed of the target proxy components in the master node and is greater than the scores of the remaining slave proxy components other than the first slave proxy component, that is, the first slave proxy component is in a normal state, and the score of the first slave proxy component is the highest among the scores of the remaining slave proxy components other than the first slave proxy component, and is second only to the target score corresponding to the target proxy component in the master node.
[0065] For example, the above Figure 1 In the example, the score can be represented by the identity document (id) of the proxy component. The target score of the master proxy component composed of the target proxy component in the master node master is 100, the score of the slave proxy component in the slave node node1 is 99, and the score of the slave proxy component in the slave node node2 is 98. If the slave nodes node1 and node2 are both in normal state, when the master node master is abnormal, the master proxy component will release the token to downgrade the master node master to which the master proxy component belongs to a slave node. The score of the slave proxy component in the slave node node1 is 99, and the score of the slave proxy component in the slave node node1 is second only to the target score of 100. Then the slave proxy component in the slave node node1 can be upgraded to the master proxy component as the first slave proxy component, so that the slave node node1 is upgraded to the master node.
[0066] Therefore, through the communication between the proxy components in the nodes, the slave nodes can obtain the working status of the master node in time. When the working status of the master node is abnormal, the slave nodes in normal status take over the function of managing the k8s cluster from the master node through the control of the proxy components in the nodes. Even if the k8s cluster service of the master node is lost, all slave nodes can still ensure the stable service of the k8s system, achieving the ability of the slave nodes to autonomously manage the k8s cluster, and improving the business stability of the cluster in the cloud native scenario.
[0067] In some embodiments of the present disclosure, in the above embodiments, in response to the startup of the master agent component, the master agent component can obtain the data in the etcd database of the k8s container orchestration system in the master node based on the synchronization unit agent-db, and obtain the target data, so that the target data in the master agent component and the data in the etcd database complete the first synchronization.
[0068] In response to the completion of the first synchronization between the target data in the master agent component and the data in the etcd database, the master agent component can update the target data to the data in the etcd database based on the synchronization unit agent-db at every preset synchronization period, so that the target data in the master agent component and the data in the etcd database can complete multiple synchronizations.
[0069] The preset synchronization duration can be set as needed, for example, 10 minutes, which is not limited here. After the master agent component completes synchronizing etcd data each time, it can notify the control unit agent-sync-apiserver that the synchronization is complete and wait for the next synchronization of data.
[0070] Among them, the etcd database is a distributed key-value storage database developed based on the Raft protocol. It can be used for service discovery, shared configuration, and consistency assurance. The etcd database stores the entire state of the k8s container orchestration system, including configuration, specifications, and the status of running workloads.
[0071] In response to the completion of a synchronization between the data in the master agent component and the data in the database, the master agent component can send the target data to each slave agent component based on the control unit agent-sync-apiserver, so that the data in each slave agent component is synchronized with the target data in the master agent component, that is, the data in the master agent component and each slave agent component is synchronized with the data in the etcd database of the k8s container orchestration system.
[0072] Figure 4 is a flowchart of a node control method in a cloud native scenario provided by an embodiment of the present disclosure. The method can be executed by a k8s container orchestration system in a cloud native scenario. A node can be understood as any computer device with processing and computing capabilities, such as Figure 4 As shown, the node control method in the cloud native scenario provided by this embodiment includes the following steps:
[0073] Step 410: For the proxy component in each node, in response to the proxy component being started, the proxy component obtains a score set from the configuration file, the score set including the scores of the proxy components in each node, and the target proxy component corresponding to the maximum score in the score set is the main proxy component.
[0074] Step 420, in response to the master agent component composed of the target agent components in the master node being started, the master agent component generates a token and sends the target component information of the master agent component to the slave agent components in each slave node, so that each slave agent component reports the component information of the slave agent component to the master agent component based on the target component information.
[0075] Step 430: The master agent component receives the component information reported by each slave agent component at a first preset time interval, and counts the number of slave agent components that report the component information at a second preset time interval.
[0076] Step 440: When the number is less than or equal to a preset threshold, the master agent component releases the token to downgrade the master node to which the master agent component belongs to a slave node.
[0077] Step 450, in response to the master agent component releasing the token, each slave agent component determines that the master node to which the master agent component belongs is abnormal. If the remaining slave agent components greater than a preset number other than the first slave agent component have not received the component information sent by the first slave agent component, then each remaining slave agent component determines that the first slave agent component is abnormal.
[0078] In the embodiment of the present disclosure, in response to the master agent component releasing the token, each slave agent component can determine that the master node to which the master agent component belongs is abnormal. If the remaining slave agent components greater than a preset number other than the first slave agent component have not received the component information sent by the first slave agent component, each remaining slave agent component can determine that the first slave agent component is abnormal.
[0079] The preset number can be set as needed and is not limited here.
[0080] Step 460: For each remaining slave agent component, in response to determining that the first slave agent component is abnormal, the remaining slave agent component sends component information to a second slave agent component, and the score of the second slave agent component is second only to the score of the first slave agent component in the score set.
[0081] In the disclosed embodiment, for each remaining slave agent component other than the first slave agent component, in response to determining that the first slave agent component is abnormal, the remaining slave agent component may send component information to a second slave agent component. The second slave agent component may be understood as a slave agent component corresponding to the maximum score in the score set that is lower than the score of the first slave agent component, that is, the score of the second slave agent component is second only to the score of the target agent component and the score of the first slave agent component in the score set.
[0082] Step 470: In response to the second slave agent component receiving component information sent by remaining slave agent components greater than a preset number other than the second slave agent component, the second slave agent component is upgraded to a master agent component, so that the slave node to which the second slave agent component belongs is upgraded to a master node, and the second slave agent component, as the master agent component, executes steps to generate a token and subsequent steps to generate the token.
[0083] In the embodiment of the present disclosure, in response to the second slave agent component receiving component information sent by the remaining slave agent components greater than a preset number other than the second slave agent component, it indicates that the second slave agent component can communicate normally with most of the agent components. Therefore, the second slave agent component can be upgraded to a master agent component, so that the slave node to which the second slave agent component belongs is upgraded to a master node, and the second slave agent component, as the master agent component, executes the steps of generating a token and subsequent steps of generating the token.
[0084] Therefore, through the communication between the proxy components in the nodes, the slave nodes can obtain the working status of the master node in time. When the working status of the master node is abnormal, the slave nodes in normal status take over the function of managing the k8s cluster from the master node through the control of the proxy components in the nodes. Even if the k8s cluster service of the master node is lost, all slave nodes can still ensure the stable service of the k8s system, achieving the ability of the slave nodes to autonomously manage the k8s cluster, and improving the business stability of the cluster in the cloud native scenario.
[0085] In some embodiments of the present disclosure, the master agent component may perform S11-S15:
[0086] S11. Receive container control instructions sent by the client.
[0087] In the disclosed embodiment, the main agent component can receive container control instructions sent by the client, that is, container control instructions from the client to the k8s container orchestration system.
[0088] S12. Based on a preset load balancing strategy, determine a target slave node for executing the container control instruction.
[0089] In the disclosed embodiment, the master agent component may determine a target slave node for executing a container control instruction based on a preset load balancing strategy.
[0090] The load balancing strategy can be understood as a strategy that can balance the load of each slave node.
[0091] S13: Send the container control instruction to the proxy component in the target slave node, so that the proxy component in the target slave node performs a control operation corresponding to the container control instruction on the container in the target slave node.
[0092] In the disclosed embodiment, the master agent component may send container control instructions to the agent component in the target slave node, and the agent component in the target slave node may perform control operations corresponding to the container control instructions on the container in the target slave node, such as adding, deleting, and the like.
[0093] S14. Receive the execution result of the container control instruction sent by the proxy component in the target slave node, and store the container control instruction and the execution result.
[0094] S15. Send the container control instruction and the execution result to the proxy components in other slave nodes other than the target slave node.
[0095] In some embodiments of the present disclosure, in response to the master agent component releasing the token, each slave agent component determines that the master node to which the master agent component belongs is abnormal, and the first slave agent component in the slave agent component that is in a normal state is upgraded to the master agent component, and the steps of generating the token and the steps after generating the token are executed. After the slave node to which the first slave agent component belongs is upgraded to the master node, when the target agent component receives component information of slave agent components other than the target agent component that is greater than a preset number, it indicates that the target agent component can communicate with most nodes, and the communication function of the target agent component is restored to a normal state. In response to the data synchronization instruction sent by the client, the target agent component can obtain the target data in the current master agent component, that is, the data in the database of the k8s container orchestration system, and the current master agent component is the agent component in the current master node; in response to the target agent component obtaining the target data, the current master agent component can release the token, and the node to which the current master agent component belongs is downgraded to a slave node. The target agent component can switch to the master agent component to upgrade the node to which the target agent component belongs to the master node. The target agent component executes the steps of generating the token and the steps after generating the token as the master agent component, and the node to which the target agent component belongs can be upgraded to the master node.
[0096] Figure 5 It is a schematic diagram of the structure of a node control device in a cloud native scenario provided by an embodiment of the present disclosure. The device can be understood as the above-mentioned k8s container orchestration system or some functional modules in the above-mentioned k8s container orchestration system. Figure 5 As shown, the node control device 500 in the cloud native scenario includes:
[0097] A generating module 510, configured to generate a token in response to the master agent component consisting of the target agent components in the master node starting up, and send the target component information of the master agent component to the slave agent components in each slave node, so that each slave agent component reports the component information of the slave agent component to the master agent component based on the target component information;
[0098] The first receiving module 520 is configured for the master proxy component to receive component information reported by each slave proxy component at a first preset time interval, and to count the number of slave proxy components that report component information at a second preset time interval;
[0099] A release module 530, configured to release the token by the master agent component when the number is less than or equal to a preset threshold, so that the master node to which the master agent component belongs is downgraded to a slave node;
[0100] The first upgrade module 540 is used to respond to the master agent component releasing the token. Each slave agent component determines that the master node to which the master agent component belongs is abnormal, and the first slave agent component in a normal state among the slave agent components is upgraded to the master agent component, so that the slave node to which the first slave agent component belongs is upgraded to the master node. The first slave agent component, as the master agent component, executes the steps of generating the token and the steps after generating the token.
[0101] Optionally, the node control device in the above cloud native scenario includes:
[0102] A first acquisition module is used for, for the agent component in each node, in response to the agent component being started, the agent component acquiring a score set from a configuration file, the score set including the scores of the agent components in each node, and the target agent component corresponding to the maximum score in the score set being the main agent component;
[0103] The first slave agent component is in a normal state and the score of the first slave agent component is second only to the target score of the target agent component in the score set.
[0104] Optionally, the configuration file is generated based on the user configuration of the client, and the configuration file includes a score set and a communication address of the proxy component in each node, and the score of each proxy component in the score set is negatively correlated with the load of the node to which the proxy component belongs.
[0105] Optionally, the node control device in the above cloud native scenario includes:
[0106] A first determining module, configured to determine that the first slave proxy component is abnormal if the remaining slave proxy components greater than a preset number other than the first slave proxy component have not received the component information sent by the first slave proxy component;
[0107] A first sending module is configured to, for each remaining slave proxy component, in response to determining that the first slave proxy component is abnormal, cause the remaining slave proxy component to send component information to a second slave proxy component, where the second slave proxy component is a slave proxy component corresponding to a maximum score in the score set that is lower than the score of the first slave proxy component;
[0108] The second upgrade module is used for upgrading the second slave agent component to a master agent component in response to the second slave agent component receiving component information sent by remaining slave agent components greater than a preset number other than the second slave agent component, so that the slave node to which the second slave agent component belongs is upgraded to a master node, and the second slave agent component, as the master agent component, executes steps of generating a token and subsequent steps of generating the token.
[0109] Optionally, the node control device in the above cloud native scenario includes:
[0110] A first synchronization module is used for, in response to the main agent component starting up, the main agent component obtains the data in the database of the k8s container orchestration system in the master node based on the synchronization unit to obtain the target data, so that the target data in the main agent component is synchronized with the data in the database for the first time;
[0111] A second synchronization module, configured to respond to the completion of the first synchronization, and at every preset synchronization time, the master agent component updates the target data to the data in the database based on the synchronization unit, so that the target data in the master agent component is synchronized with the data in the database for multiple times;
[0112] The third synchronization module is used for responding to the data in the master agent component completing a synchronization with the data in the database. The master agent component sends the target data to each slave agent component based on the control unit, so that the data in each slave agent component is synchronized with the target data in the master agent component.
[0113] Optionally, the node control device in the above cloud native scenario includes:
[0114] A second receiving module, used for the main agent component to receive the container control instruction sent by the client;
[0115] A second determination module is used to determine a target slave node for executing the container control instruction based on a preset load balancing strategy;
[0116] A second sending module is used to send the container control instruction to the proxy component in the target slave node, so that the proxy component in the target slave node performs a control operation corresponding to the container control instruction on the container in the target slave node;
[0117] A third receiving module is used to receive the execution result of the container control instruction sent by the proxy component in the target slave node, and store the container control instruction and the execution result;
[0118] The third sending module is used to send the container control instruction and the execution result to other proxy components other than the main proxy component.
[0119] Optionally, the node control device in the above cloud native scenario includes:
[0120] A second acquisition module is used for, when the target proxy component receives component information of slave proxy components greater than a preset number other than the target proxy component, in response to a data synchronization instruction sent by the client, the target proxy component acquires target data in the current master proxy component, where the current master proxy component is a proxy component in the current master node;
[0121] A switching module is used to respond to the target proxy component completing the acquisition of target data, the current master proxy component releasing the token, the node to which the current master proxy component belongs being downgraded to a slave node, the target proxy component switching to the master proxy component so that the node to which the target proxy component belongs is upgraded to the master node, and the target proxy component as the master proxy component executes the steps of generating the token and subsequent steps of generating the token.
[0122] The node control device in the cloud-native scenario provided by the embodiments of the present disclosure can implement the method of any of the above embodiments, and its execution method and beneficial effects are similar, which will not be repeated here.
[0123] The embodiments of the present disclosure also provide a computer device, which includes a processor and a memory, wherein a computer program is stored in the memory, and when the computer program is executed by the processor, the method of any of the above embodiments can be implemented, and its execution method and beneficial effects are similar and will not be repeated here.
[0124] An embodiment of the present disclosure provides a computer-readable storage medium, in which a computer program is stored. When the computer program is executed by a processor, the method of any of the above embodiments can be implemented. The execution method and beneficial effects are similar and will not be repeated here.
[0125] The above-mentioned computer readable storage medium can adopt any combination of one or more readable media. The readable medium can be a readable signal medium or a readable storage medium. The readable storage medium can include, for example, but is not limited to, a system, device or device of electricity, magnetism, light, electromagnetic, infrared, or semiconductor, or any combination of the above. More specific examples (non-exhaustive list) of readable storage media include: an electrical connection with one or more wires, a portable disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above.
[0126] The computer program may be written in any combination of one or more programming languages to write program codes for performing the operations of the disclosed embodiments, including object-oriented programming languages such as Java, C++, etc., and conventional procedural programming languages such as "C" or similar programming languages. The program code may be executed entirely on the user's computer device, partially on the user's device, as a separate software package, partially on the user's computer device and partially on a remote computer device, or entirely on a remote computer device or server.
[0127] The above description is only a preferred embodiment of the present disclosure and an explanation of the technical principles used. Those skilled in the art should understand that the scope of disclosure involved in the present disclosure is not limited to the technical solutions formed by a specific combination of the above technical features, but should also cover other technical solutions formed by any combination of the above technical features or their equivalent features without departing from the above disclosed concept. For example, the above features are replaced with the technical features with similar functions disclosed in the present disclosure (but not limited to) by each other to form a technical solution.
[0128] In addition, although each operation is described in a specific order, this should not be understood as requiring these operations to be performed in the specific order shown or in a sequential order. Under certain circumstances, multitasking and parallel processing may be advantageous. Similarly, although some specific implementation details are included in the above discussion, these should not be interpreted as limiting the scope of the present disclosure. Some features described in the context of a separate embodiment can also be implemented in a single embodiment in combination. On the contrary, the various features described in the context of a single embodiment can also be implemented in multiple embodiments individually or in any suitable sub-combination mode.
[0129] The above description is only a specific embodiment of the present disclosure, so that those skilled in the art can understand or implement the present disclosure. Various modifications to these embodiments will be apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of the present disclosure. Therefore, the present disclosure will not be limited to the embodiments described herein, but will conform to the widest scope consistent with the principles and novel features disclosed herein.
Claims
1. A node control method in a cloud native scenario, characterized in that: The method is applied to a k8s container orchestration system in a cloud native scenario, wherein the k8s container orchestration system includes a master node and at least one slave node, wherein an agent component is deployed in each node, wherein the agent component in the master node is a master agent component, and the agent component in the slave node is a slave agent component, wherein the method includes: In response to the master agent component composed of the target agent components in the master node being started, the master agent component generates a token and sends the target component information of the master agent component to the slave agent components in each of the slave nodes, so that each of the slave agent components reports the component information of the slave agent component to the master agent component based on the target component information; The master agent component receives the component information reported by each slave agent component at a first preset time interval, and counts the number of slave agent components that report the component information at a second preset time interval; When the number is less than or equal to a preset threshold, the master agent component releases the token so that the master node to which the master agent component belongs is downgraded to a slave node; In response to the master agent component releasing the token, each of the slave agent components determines that the master node to which the master agent component belongs is abnormal, and the first slave agent component in a normal state among the slave agent components is upgraded to a master agent component, so that the slave node to which the first slave agent component belongs is upgraded to a master node, and the first slave agent component, as the master agent component, executes the steps of generating the token and subsequent steps of generating the token.
2. The method according to claim 1, characterized in that In response to the master agent component composed of the target agent components in the master node starting up, before the master agent component generates a token, the method further includes: For the proxy component in each node, in response to the proxy component being started, the proxy component obtains a score set from a configuration file, the score set including the scores of the proxy components in each node, and the target proxy component corresponding to the maximum score in the score set is the main proxy component; The first slave proxy component is in a normal state and the score of the first slave proxy component is second only to the target score of the target proxy component in the score set.
3. The method according to claim 2, characterized in that The configuration file is generated based on the user configuration of the client, and includes the score set and the communication address of the proxy component in each node. The score of each proxy component in the score set is negatively correlated with the load of the node to which the proxy component belongs.
4. The method according to claim 2, characterized in that: In response to the master agent component releasing the token, after each of the slave agent components determines that the master node to which the master agent component belongs is abnormal, the method further includes: If the remaining slave proxy components greater than a preset number other than the first slave proxy component do not receive the component information sent by the first slave proxy component, each of the remaining slave proxy components determines that the first slave proxy component is abnormal; For each of the remaining slave proxy components, in response to determining that the first slave proxy component is abnormal, the remaining slave proxy component sends component information to a second slave proxy component, where the second slave proxy component is a slave proxy component corresponding to a maximum score in the score set that is lower than the score of the first slave proxy component; In response to the second slave agent component receiving component information sent by remaining slave agent components greater than a preset number other than the second slave agent component, the second slave agent component is upgraded to a master agent component, so that the slave node to which the second slave agent component belongs is upgraded to a master node, and the second slave agent component performs the steps of generating a token and subsequent steps of generating a token as a master agent component.
5. The method according to claim 1, characterized in that The method further comprises: In response to the master agent component being started, the master agent component acquires data in a database of the k8s container orchestration system in the master node based on a synchronization unit to obtain target data, so that the target data in the master agent component is synchronized for the first time with the data in the database; In response to the completion of the first synchronization, the master agent component updates the target data to the data in the database based on the synchronization unit at every preset synchronization time, so that the target data in the master agent component is synchronized with the data in the database for multiple times; In response to the data in the master agent component completing a synchronization with the data in the database, the master agent component sends the target data to each of the slave agent components based on the control unit, so that the data in each of the slave agent components completes the synchronization with the target data in the master agent component.
6. The method according to claim 1, characterized in that The method further comprises: The main agent component receives the container control instruction sent by the client; Based on a preset load balancing strategy, determine a target slave node for executing the container control instruction; Sending the container control instruction to the proxy component in the target slave node, so that the proxy component in the target slave node performs a control operation corresponding to the container control instruction on the container in the target slave node; receiving an execution result of the container control instruction sent by the proxy component in the target slave node, and storing the container control instruction and the execution result; The container control instruction and the execution result are sent to other agent components other than the main agent component.
7. The method according to claim 1, characterized in that In response to the master agent component releasing the token, each of the slave agent components determines that the master node to which the master agent component belongs is abnormal, and a first slave agent component in a normal state among the slave agent components is upgraded to a master agent component, so that the slave node to which the first slave agent component belongs is upgraded to a master node, and after the first slave agent component performs the steps of generating the token and subsequent steps of generating the token as the master agent component, the method further includes: When the target proxy component receives component information of slave proxy components greater than a preset number other than the target proxy component, in response to a data synchronization instruction sent by the client, the target proxy component acquires target data in a current master proxy component, where the current master proxy component is a proxy component in a current master node; In response to the target agent component completing acquisition of the target data, the current master agent component releases the token, the node to which the current master agent component belongs is downgraded to a slave node, the target agent component switches to the master agent component to upgrade the node to which the target agent component belongs to the master node, and the target agent component, as the master agent component, executes the steps of generating the token and subsequent steps of generating the token.
8. A node control device in a cloud native scenario, characterized in that: The device is applied to a k8s container orchestration system in a cloud native scenario, wherein the k8s container orchestration system includes a master node and at least one slave node, wherein an agent component is deployed in each node, wherein the agent component in the master node is a master agent component, and the agent component in the slave node is a slave agent component, wherein the device includes: A generating module, configured to respond to the master agent component composed of the target agent components in the master node starting up, the master agent component generating a token, and sending the target component information of the master agent component to the slave agent components in each of the slave nodes, so that each of the slave agent components reports the component information of the slave agent component to the master agent component based on the target component information; A first receiving module, configured for the master agent component to receive the component information reported by each slave agent component at a first preset time interval, and to count the number of slave agent components that report the component information at a second preset time interval; A release module, configured to release the token by the master agent component when the number is less than or equal to a preset threshold, so that the master node to which the master agent component belongs is downgraded to a slave node; A first upgrade module is used for responding to the master agent component releasing the token, each of the slave agent components determines that the master node to which the master agent component belongs is abnormal, and the first slave agent component in a normal state among the slave agent components is upgraded to the master agent component, so that the slave node to which the first slave agent component belongs is upgraded to the master node, and the first slave agent component performs the token generation and the steps after the token generation as the master agent component.
9. A computer device, characterized in that: include: A memory and a processor, wherein a computer program is stored in the memory, and when the computer program is executed by the processor, a node control method in a cloud native scenario as described in any one of claims 1 to 7 is implemented.
10. A computer-readable storage medium, characterized in that: The storage medium stores a computer program, and when the computer program is executed by the processor, the node control method in the cloud native scenario according to any one of claims 1 to 7 is implemented.
Citation Information
Cited By
Method, device and equipment for detecting node state in k8s cluster and medium
CN120675991A
Resource scheduling method and device
CN121542058A