Method for dynamically managing kubernetes virtual node provider in real time
By introducing kafka and elasticsearch in cloud native scenarios, real-time synchronization of k8s provider pod status and dynamic expansion of virtual nodes are achieved, which solves the virtual node management load pressure and single point problems in the existing technology, and improves system performance and controllability. .
Patent Information
- Application Number
- CN202410864136.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-30
- Publication Date
- 2024-09-20
- Estimated Expiration
- 2044-06-30
AI Technical Summary
The existing technology lacks a way to synchronize status changes from the k8s provider side to the k8s apiserver in cloud native scenarios, resulting in developers needing to poll regularly, resulting in excessive load pressure on the provider, and virtual nodes manage thousands of pods, becoming a single Point services lack a dynamic expansion mechanism, resulting in load pressure and security performance issues.
By introducing kafka message middleware and elasticsearch, real-time synchronization of provider pod status changes to k8s pods is achieved, virtual nodes are dynamically expanded, and custom schedulers and vk-operators are used to manage pod scheduling to ensure that each virtual node only manages part of its pods. Avoid single point problems.
It achieves real-time status synchronization, reduces the performance pressure on the provider, dynamically expands virtual nodes, avoids single point services, and improves the controllability and performance of the system.
Smart Images

Figure CN118677904A
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of kubernetes cloud platform, and in particular to a method for real-time dynamic management of kubernetes virtual node provider. Background Art
[0002] In the cloud-native scenario, there is an application scenario in which kubelet is extended through a virtual node (virtual kubelet, hereinafter referred to as vk). In the serverless k8s cluster, there is no concept of kubelet and node, so it is necessary to use vk to disguise as kubelet to register internally with the k8s apiserver and externally connect to the providers provided by various cloud vendors (providers maintain a set of pod lifecycle interfaces, which can be understood as providing different implementation methods for managing k8s pods).
[0003] The general solution for this business scenario is that although the existing vk source code provides an implementation for synchronizing status changes from the k8sapiserver side to the provider, it does not provide a way to synchronize status changes on the provider side to the k8s apiserver. At this time, the existing method requires developers to regularly poll the provider-related interfaces in vk to obtain the latest pod status. When the number of pods is huge, it will cause excessive load pressure on the provider. In addition, only one vk is registered in the entire serverless cluster. Vk may need to manage thousands of pods. It is a single-point service and lacks a dynamic expansion mechanism, which will have greater load pressure and security performance issues. Summary of the invention
[0004] The purpose of this section is to summarize some aspects of embodiments of the present invention and briefly introduce some preferred embodiments. Some simplifications or omissions may be made in this section and the specification abstract and the invention title of this application to avoid blurring the purpose of this section, the specification abstract and the invention title, and such simplifications or omissions cannot be used to limit the scope of the present invention.
[0005] In view of the above existing problems, the present invention is proposed.
[0006] Therefore, the purpose of the present invention is to provide a method for real-time dynamic management of kubernetes virtual node providers, in order to solve the problem of "a general solution in this business scenario. Although the existing vk source code provides an implementation for synchronizing status changes from the k8sapiserver side to the provider, it does not provide a way to synchronize the status changes on the provider side to the k8s apiserver. At this time, the existing method requires developers to regularly poll the provider-related interfaces in vk to obtain the latest pod status. When the number of pods is huge, the provider load pressure will be too high. Moreover, only one vk is registered for the entire serverless cluster. Vk may need to manage thousands of pods. It is a single-point service and lacks a dynamic expansion mechanism. There will be greater load pressure and security performance issues."
[0007] In order to solve the above technical problems, the present invention provides the following technical solutions:
[0008] A method for real-time dynamic management of a kubernetes virtual node provider comprises the following steps:
[0009] SI, the component console opens the serverless k8s cluster and uses a custom scheduler. If it meets expectations, a vk node is started and registered in the serverless k8s cluster, and the provider service is started;
[0010] S2. Manually trigger the status change of the provider pod and observe the data production of Kafka. When vk consumes the change message, it can find the corresponding pod in k8s according to this unique identifier and synchronize the provider pod change to the k8s pod through protocol conversion.
[0011] S3. Create n pods in the serverless k8s cluster, observe the writing of corresponding data in elasticsearch, and continue to create pods until the threshold configured in configmap is reached. During this process, vk regularly queries es to determine whether the number of pods managed by itself has reached the threshold. After the threshold is reached, vk creates cr in the kubernetes cluster to trigger vk node expansion;
[0012] S4. Repeat S3 several times to observe the expansion operation.
[0013] S5. After the expansion, continue to create pods in the serverless k8s cluster, verify that the pods are scheduled to the newly expanded vk node, observe that the pods managed by the node are running, and the pod information is transmitted to other vk nodes. The number of pods managed by each follower has reached the threshold, and then create a cr to the k8s cluster. After the vk-operator tunes to watch the creation of the cr, it creates a new vk node;
[0014] S6. After the implementation is completed, unsubscribe from the serverless k8s cluster, kill the provider service, and clear the resources on the kubernetes cluster.
[0015] As a preferred solution of the method for real-time dynamic management of Kubernetes virtual node provider described in the present invention, it is agreed that there are n vks in the same consumer group to ensure that messages are not consumed repeatedly after expansion.
[0016] As a preferred solution of the method for real-time dynamic management of kubernetes virtual node provider described in the present invention, wherein: all the vk nodes can consume, all the vk nodes can access the k8s cluster, the consumer group limits the message to be consumed only once, the provider pod and the k8s pod are associated with a unique identifier, and any vk can update the status of the k8s pod.
[0017] As a preferred solution of the method for real-time dynamic management of kubernetes virtual node provider described in the present invention, vk-operator is deployed in the k8s cluster, and the role of vk-operator is to process the creation of vk nodes.
[0018] As a preferred solution of the method for real-time dynamic management of kubernetes virtual node provider described in the present invention, wherein: the k8s cluster is a management cluster, not the user's own business cluster.
[0019] As a preferred solution of the method for real-time dynamic management of Kubernetes virtual node provider described in the present invention, the number of vk nodes is kept odd, and an election mechanism is introduced. There is only one vk at the time of initialization, and the vk automatically becomes the leader. When there are multiple vk nodes, a leader is elected through a paxos or raft-like protocol, and the rest are followers.
[0020] As a preferred solution of the method for real-time dynamic management of Kubernetes virtual node providers described in the present invention, the provider pod created and maintained by a single vk node is stored in elasticsearch.
[0021] As a preferred solution of the method for real-time dynamic management of Kubernetes virtual node provider described in the present invention, the total number of vk nodes should be kept odd after creation, which is controlled by the spec in the crd. Each time the leader is created, it has the number information of the current vk nodes.
[0022] As a preferred solution of the method for real-time dynamic management of kubernetes virtual node provider described in the present invention, the pod node scheduling is achieved by extending kube-scheduler through a custom scheduler.
[0023] As a preferred solution of the method for real-time dynamic management of kubernetes virtual node provider described in the present invention, the threshold of the number of pods is configured in the management cluster in the form of configmap, and the custom scheduler implements the priority scheduling strategy based on the threshold of "the number of pods managed by each vk node", and preferentially schedules the created k8s pod to the vk whose number of pods does not reach the threshold.
[0024] Beneficial effects of the present invention:
[0025] 1. Manually trigger the status change of the provider pod and observe the data production of kafka. When vk consumes the change message, it can find the corresponding pod in k8s according to this unique identifier. Through protocol conversion, the provider pod change is synchronized to the k8s pod, and the status is synchronized from the provider pod to the k8s pod in real time, avoiding frequent polling and causing performance problems in the provider. The data synchronization is fully decoupled through the message queue, the architecture is more reasonable, and it will not cause provider performance overload, making the risk controllable.
[0026] 2. By creating n pods in the serverless k8s cluster, observing the writing of the corresponding data in elasticsearch, and continuously creating pods until the threshold configured in configmap is reached, a mechanism for dynamically expanding vk nodes is implemented. Each vk node only manages the pods that belong to it, avoiding the single point problem of vk. Introducing elasticsearch as storage provides efficient insertion queries, and through a custom scheduler, the number of pods managed by each vk is in a dynamically balanced state. BRIEF DESCRIPTION OF THE DRAWINGS
[0027] In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the following briefly introduces the drawings required for describing the embodiments. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative labor. Among them:
[0028] Figure 1 This is a system architecture diagram of a method for real-time dynamic management of Kubernetes virtual node providers in the present invention. DETAILED DESCRIPTION
[0029] In order to make the above-mentioned objects, features and advantages of the present invention more obvious and easy to understand, the specific implementation methods of the present invention are described in detail below in conjunction with the accompanying drawings.
[0030] In the following description, many specific details are set forth to facilitate a full understanding of the present invention, but the present invention may also be implemented in other ways different from those described herein, and those skilled in the art may make similar generalizations without violating the connotation of the present invention. Therefore, the present invention is not limited to the specific embodiments disclosed below.
[0031] Secondly, the term "one embodiment" or "embodiment" as used herein refers to a specific feature, structure, or characteristic that may be included in at least one implementation of the present invention. The term "in one embodiment" that appears in different places in this specification does not necessarily refer to the same embodiment, nor does it refer to a separate or selective embodiment that is mutually exclusive with other embodiments.
[0032] Secondly, the present invention is described in detail with reference to the schematic diagram. When describing the embodiments of the present invention in detail, for the sake of convenience, the cross-sectional diagrams showing the device structure will not be partially enlarged according to the general scale, and the schematic diagrams are only examples, which should not limit the scope of protection of the present invention. In addition, in actual production, the three-dimensional dimensions of length, width and depth should be included.
[0033] Reference Figure 1The present invention provides a method for real-time dynamic management of kubernetes virtual node provider, comprising the following steps:
[0034] SI, the component console opens the serverless k8s cluster and uses a custom scheduler. If it meets expectations, a vk node is started and registered in the serverless k8s cluster. The provider service is started, the provider status is synchronized to vk, and message middleware such as kafka is introduced. For the pods scheduled to vk, a label is uniformly added to indicate the vk to which the pod belongs.
[0035] S2. Manually trigger the status change of the provider pod and observe the data production of Kafka. When vk consumes the change message, it can find the corresponding pod in k8s according to this unique identifier and synchronize the provider pod change to the k8s pod through protocol conversion.
[0036] S3. Create n pods in the serverless k8s cluster, observe the writing of corresponding data in elasticsearch, continue to create pods, and synchronize data to es when the provider pod is produced until the threshold configured in configmap is reached. During this process, vk regularly queries es to determine whether the number of pods managed by itself has reached the threshold. After the threshold is reached, vk creates cr in the kubernetes cluster to trigger vk node expansion;
[0037] S4. Repeat S3 several times to observe the expansion operation.
[0038] S5. After the expansion, continue to create pods in the serverless k8s cluster, verify that the pods are scheduled to the newly expanded vk node, observe that the pods managed by the node are running, and the pod information is transmitted to other vk nodes. The number of pods managed by each follower has reached the threshold, and then create cr to the k8s cluster. After vk-operator tunes to watch the creation of cr, it creates a new vk node. The new node will automatically join the vk node group as a follower. Each vk node maintains the provider pods it manages through es, and the interaction process between vk and provider will only query and change the provider pods it manages.
[0039] S6. After the implementation is completed, unsubscribe from the serverless k8s cluster, kill the provider service, and clear the resources on the kubernetes cluster.
[0040] Among them, it is agreed that there are n vks in the same consumer group to ensure that the messages are not consumed repeatedly after expansion, so that each change of the provider will only be consumed by one of the vks.
[0041] Furthermore, all of the vk nodes can consume, all of the vk nodes can access the k8s cluster, the consumer group limits the message to be consumed only once, the provider pod is associated with the k8s pod with a unique identifier, and any vk can update the status of the k8s pod, so that the provider pod is not restricted to be consumed only by the vk it manages, and all vk nodes can consume.
[0042] Furthermore, vk-operator is deployed in the k8s cluster, and the role of vk-operator is to handle the creation of vk nodes.
[0043] Furthermore, the k8s cluster is a management cluster, not the user's own business cluster.
[0044] Furthermore, the number of the vk nodes is kept odd, and an election mechanism is introduced. There is only one vk at the time of initialization, and the vk automatically becomes the leader. When there are multiple vk nodes, a leader is elected through a paxos or raft-like protocol, and the rest are followers.
[0045] Furthermore, the provider pod created and maintained by the single vk node is stored in elasticsearch.
[0046] Furthermore, the total number of vk nodes should be kept odd after creation, which is controlled by spec in crd. Each time a leader is created, it has the number of current vk nodes, and new nodes will automatically join the vk node group as followers. Each vk node maintains its own provider pod through es, and the interaction process between vk and provider will only query and change the provider pod it manages.
[0047] Furthermore, the pod node scheduling is achieved by extending kube-scheduler through a custom scheduler.
[0048] Furthermore, the threshold of the number of pods is configured in the management cluster in the form of configmap. The custom scheduler implements the priority scheduling strategy based on this "number of pods managed by each vk node" threshold, and preferentially schedules the created k8s pods to the vk whose number of pods does not reach the threshold.
[0049] It should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention rather than to limit it. Although the present invention has been described in detail with reference to the preferred embodiments, those skilled in the art should understand that the technical solutions of the present invention may be modified or replaced by equivalents without departing from the spirit and scope of the technical solutions of the present invention, which should all be included in the scope of the claims of the present invention.
Claims
1. A method for real-time dynamic management of kubernetes virtual node providers, characterized in that: The steps include: SI, the component console opens the serverless k8s cluster and uses a custom scheduler. If it meets expectations, a vk node is started and registered in the serverless k8s cluster, and the provider service is started; S2. Manually trigger the status change of the provider pod and observe the data production of Kafka. When vk consumes the change message, it can find the corresponding pod in k8s according to this unique identifier and synchronize the provider pod change to the k8s pod through protocol conversion. S3. Create n pods in the serverless k8s cluster, observe the writing of corresponding data in elasticsearch, and continue to create pods until the threshold configured in configmap is reached. During this process, vk regularly queries es to determine whether the number of pods managed by itself has reached the threshold. After the threshold is reached, vk creates cr in the kubernetes cluster to trigger vk node expansion; S4. Repeat S3 several times to observe the expansion operation. S5. After the expansion, continue to create pods in the serverless k8s cluster, verify that the pods are scheduled to the newly expanded vk node, observe that the pods managed by the node are running, and the pod information is transmitted to other vk nodes. The number of pods managed by each follower has reached the threshold, and then create a cr to the k8s cluster. After the vk-operator tunes to watch the creation of the cr, it creates a new vk node; S6. After the implementation is completed, unsubscribe from the serverless k8s cluster, kill the provider service, and clear the resources on the kubernetes cluster.
2. A method for real-time dynamic management of kubernetes virtual node providers according to claim 1, characterized in that: It is agreed that there are n vks in the same consumer group to ensure that messages are not consumed repeatedly after expansion.
3. A method for real-time dynamic management of kubernetes virtual node providers according to claim 1, characterized in that: All of the vk nodes can consume, all of the vk nodes can access the k8s cluster, the consumergroup limits the message to be consumed only once, the provider pod is associated with the k8s pod with a unique identifier, and any vk can update the status of the k8s pod.
4. A method for real-time dynamic management of kubernetes virtual node providers according to claim 1, characterized in that: The vk-operator is deployed in the k8s cluster. The role of vk-operator is to handle the creation of vk nodes.
5. A method for real-time dynamic management of kubernetes virtual node providers according to claim 1, characterized in that: The k8s cluster is a management cluster, not the user's own business cluster.
6. A method for real-time dynamic management of kubernetes virtual node providers according to claim 1, characterized in that: The number of vk nodes is kept odd, and an election mechanism is introduced. There is only one vk at the time of initialization, and the vk automatically becomes the leader. When there are multiple vk nodes, a leader is elected through a paxos or raft-like protocol, and the rest are followers.
7. A method for real-time dynamic management of kubernetes virtual node providers according to claim 6, characterized in that: The provider pod created and maintained by a single vk node is stored in elasticsearch.
8. A method for real-time dynamic management of kubernetes virtual node providers according to claim 1, characterized in that: The total number of vk nodes must remain an odd number after creation. This is controlled by the spec in the crd. Each time a vk node is created, the leader has information about the number of current vk nodes.
9. A method for real-time dynamic management of kubernetes virtual node providers according to claim 1, characterized in that: The pod node scheduling is achieved by extending kube-scheduler through a custom scheduler.
10. A method for real-time dynamic management of kubernetes virtual node providers according to claim 1, characterized in that: The threshold of the number of pods is configured in the management cluster in the form of configmap. The custom scheduler implements the priority scheduling strategy based on this "number of pods managed by each vk node" threshold, and preferentially schedules the created k8s pods to the vk whose number of pods does not reach the threshold.
Citation Information
Patent Citations
Improved method and system for container state synchronization on Kubernetes virtual node
CN117850971A
Serverless Kubernetes-oriented multi-tenant isolation method
CN117880099A
Serverless Kubernetes-oriented multi-tenant multi-cluster management and application deployment method
CN118192992A
Application data protection method and system
US20240028488A1
