A service discovery method, device, equipment and storage medium
The service discovery method addresses the inefficiency of K8s with elastic load balancing by automating listener lifecycle processes, enhancing deployment efficiency and usability through real-time data detection and reconciliation.
Patent Information
- Application Number
- CN202111138041.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-09-27
- Publication Date
- 2025-07-15
- Estimated Expiration
- 2041-09-27
AI Technical Summary
Kubernetes (K8s) cannot integrate efficiently with elastic load balancing, cannot implement listener automation processes, and application deployment is inefficient.
Detect the changes in listener data in ETCD in real time, call K8s to find Endpoint, register the pod IP in the listener with elastic load balancing, and regularly compare the listener data of ETCD and elastic load balancing to form a closed loop to realize the automatic creation, modification and deletion of listeners.
It realizes efficient integration of K8s and elastic load balancing, improves application deployment efficiency, and is easy to use and promotes.
Smart Images

Figure CN113867955B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of Kubernetes container technology, and in particular, to a service discovery method, device, equipment and storage medium. Background Art
[0002] At present, Kubernetes (K8s), as the main container orchestration tool in the industry, has become the main direction of the development of the PASS (Platform-as-a-Service) platform. Elastic load balancing is a traffic distribution control service that distributes access traffic to multiple backend service instances according to forwarding policies. It can expand the external service capabilities of the application system through traffic distribution, improve the fault tolerance of the application program, and has become the mainstream proxy solution due to its flexible scalability and high performance. Although K8s has a built-in load balancing service, K8s cannot be efficiently integrated with elastic load balancing, cannot implement the automated process of the listener, and the application deployment efficiency is low.
[0003] Therefore, how to achieve efficient and automated full-process operation of the listener based on K8s and elastic load is a technical problem that needs to be solved urgently by those skilled in the art. Summary of the Invention
[0004] In view of this, the purpose of the present invention is to provide a service discovery method, device, equipment and storage medium, which can realize the efficient integration of K8s and elastic load balancing, and effectively solve the automated processes of creating, modifying and deleting the elastic load balancing listener based on K8s. The specific solutions are as follows:
[0005] A service discovery method includes:
[0006] Real-time detecting changes in the listener data stored in ETCD;
[0007] After detecting the operation of creating a new listener, calling K8s to find the corresponding Endpoint, registering the pod IP into the listener of the elastic load balancing, and writing the pod IP into ETCD at the same time;
[0008] After detecting the operation of modifying the listener, updating the registered listener configuration from the elastic load in real time;
[0009] After detecting the operation of deleting the listener, deleting the registered listener from the elastic load in real time;
[0010] Regularly comparing the listener data in ETCD with the listener data of the elastic load balancing, eliminating differences, and forming a closed loop.
[0011] Preferably, in the above service discovery method provided by the embodiments of the present invention, the step of calling K8s to find the corresponding Endpoint includes:
[0012] Calling the ApiServer to query the corresponding Endpoint.
[0013] Preferably, in the above service discovery method provided by the embodiments of the present invention, before updating the registered listener configuration from the elastic load in real time after detecting the modify listener operation, it further includes:
[0014] When the user deposits the modified data into ETCD and overwrites the original data, detecting the modify listener operation.
[0015] Preferably, in the above service discovery method provided by the embodiments of the present invention, while updating the registered listener configuration from the elastic load in real time, it further includes:
[0016] After detecting a change in the Endpoint, finding the latest pod IP and automatically registering the latest pod IP into the listener of the elastic load balancer.
[0017] Preferably, in the above service discovery method provided by the embodiments of the present invention, while automatically registering the latest pod IP into the listener of the elastic load balancer, it further includes:
[0018] Updating the backend service address of the corresponding listener in ETCD.
[0019] Preferably, in the above service discovery method provided by the embodiments of the present invention, before deleting the registered listener from the elastic load in real time after detecting the delete listener operation, it further includes:
[0020] When the user deletes the listener data from ETCD, detecting the delete listener operation.
[0021] Preferably, in the above service discovery method provided by the embodiments of the present invention, the elimination of differences includes:
[0022] If there are differences in the comparison result, modifying the listener data of the elastic load balancer to make the modified listener data of the elastic load balancer consistent with the listener data in ETCD.
[0023] Embodiments of the present invention further provide a service discovery device, including:
[0024] A data detection module, configured to detect changes in the listener data stored in ETCD in real time;
[0025] A new operation module is used to call K8s to find the corresponding Endpoint after detecting a new listener operation, register the pod IP into the listener of the elastic load balancer, and write the pod IP into ETCD at the same time;
[0026] A modification operation module is used to update the registered listener configuration from the elastic load in real time after detecting a listener modification operation;
[0027] A deletion operation module is used to delete the registered listener from the elastic load in real time after detecting a listener deletion operation;
[0028] A regular comparison module is used to regularly compare the listener data in ETCD with the listener data of the elastic load balancer, eliminate the differences, and form a closed loop.
[0029] An embodiment of the present invention also provides an electronic device, including a processor and a memory. Among them, when the processor executes the computer program stored in the memory, the above service discovery method provided by the embodiment of the present invention is implemented.
[0030] An embodiment of the present invention also provides a computer-readable storage medium for storing a computer program. Among them, when the computer program is executed by a processor, the above service discovery method provided by the embodiment of the present invention is implemented.
[0031] As can be seen from the above technical solutions, a service discovery method provided by the present invention includes: detecting changes in the listener data stored in ETCD in real time; after detecting a new listener operation, calling K8s to find the corresponding Endpoint, registering the pod IP into the listener of the elastic load balancer, and writing the pod IP into ETCD at the same time; after detecting a listener modification operation, updating the registered listener configuration from the elastic load in real time; after detecting a listener deletion operation, deleting the registered listener from the elastic load in real time; regularly comparing the listener data in ETCD with the listener data of the elastic load balancer, eliminating the differences, and forming a closed loop.
[0032] The above service discovery method provided by the present invention realizes the efficient integration of K8s and the elastic load balancer based on the service discovery mechanism, effectively solves the automation process of creating, modifying, and deleting the elastic load balancer listener based on K8s. This process fully relies on the service discovery mechanism to achieve automation, improves the application deployment efficiency, and has better usability and popularity based on the service discovery design method.
[0033] In addition, the present invention also provides corresponding devices, equipment, and computer-readable storage media for the service discovery method, further making the above method more practical. The devices, equipment, and computer-readable storage media have corresponding advantages. BRIEF DESCRIPTION OF THE DRAWINGS
[0034] In order to more clearly illustrate the technical solutions in the embodiments of the present invention or related technologies, the following will briefly introduce the drawings required for use in the description of the embodiments or related technologies. Obviously, the drawings in the following description are only the embodiments of the present invention. For those of ordinary skill in the art, without creative efforts, other drawings can also be obtained based on the provided drawings.
[0035] Figure 1 It is a flowchart of the service discovery method provided by the embodiment of the present invention;
[0036] Figure 2 It is a flowchart of step S102 provided by the embodiment of the present invention;
[0037] Figure 3 It is a flowchart of step S103 provided by the embodiment of the present invention;
[0038] Figure 4 It is a flowchart of step S104 provided by the embodiment of the present invention;
[0039] Figure 5 It is a schematic structural diagram of the service discovery device provided by the embodiment of the present invention. DETAILED DESCRIPTION OF THE EMBODIMENTS
[0040] The following will clearly and completely describe the technical solutions in the embodiments of the present invention with reference to the drawings in the embodiments of the present invention. Obviously, the described embodiments are only a part of the embodiments of the present invention, rather than all the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those of ordinary skill in the art without creative efforts belong to the scope of protection of the present invention.
[0041] The present invention provides a service discovery method, as Figure 1 shown, including the following steps:
[0042] S101. Real-time detect the change of the listener data stored in ETCD;
[0043] It should be noted that ETCD is independent of K8s and is used to store the relevant data of the listener and display the status of the listener. Specifically, when creating a listener, the listener data can be first stored in ETCD, and the status of the listener in ETCD is set to ready, and the service discovery watches the change of the listener data.
[0044] S102. After detecting the operation of creating a new listener, call K8s to find the corresponding Endpoint, register the pod IP into the listener of the elastic load balancer, and at the same time write the pod IP into ETCD;
[0045] Specifically, as Figure 2 shown, after the service discovery detects the operation of creating a new listener, it will call K8s to find the corresponding EndPoint, register its pod IP into the elastic load balancer listener, and at the same time write the pod IP into ETCD to update the listener status to normal; if there is no pod IP in the found EndPoint, the listener status in ETCD will be set to abnormal.
[0046] S103. After detecting the operation of modifying the listener, update the registered listener configuration in the elastic load in real time;
[0047] Specifically, as Figure 3 shown, after the service discovery detects the operation of modifying the listener, it will update the registered listener configuration in the elastic load in real time.
[0048] In specific implementation, when performing step S103 to update the registered listener configuration in the elastic load in real time, it may further include: when the service discovery monitors that the Endpoint has changed, find the latest pod IP, and re-register the latest pod IP into the listener of the elastic load balancer automatically, and at the same time write the latest pod IP into ETCD to update the listener status to normal; if the latest pod IP cannot be found, the listener status in ETCD will be set to abnormal.
[0049] S104. After detecting the operation of deleting the listener, delete the registered listener in the elastic load in real time;
[0050] Specifically, as Figure 4 shown, after the service discovery detects the operation of deleting the listener, it will delete the registered listener in the elastic load in real time.
[0051] S105. Regularly compare the listener data in ETCD with the listener data of the elastic load balancer to eliminate differences and form a closed loop;
[0052] Specifically, the service discovery mechanism will regularly compare the listener data in ETCD with the listener data of the elastic load balancer to eliminate differences and form a closed loop.
[0053] The above service discovery method provided by the embodiments of the present invention is an efficient service discovery method for K8s and the elastic load balancer. Based on the service discovery mechanism, the efficient integration of K8s and the elastic load balancer is realized, and the automation process of creating, modifying and deleting the elastic load balancer listener based on K8s is effectively solved. This process fully depends on the service discovery mechanism to achieve automation, improves the application deployment efficiency, and based on the service discovery design method, it is more user-friendly and popularizable.
[0054] In specific implementation, in the above service discovery method provided by the embodiments of the present invention, step S102 of invoking K8s to find the corresponding Endpoint may include: invoking the ApiServer to query the corresponding Endpoint. That is to say, when the user executes the new operation listener operation, the relevant listener data will be stored in ETCD. When the service discovery watches the data change in ETCD, it will invoke the ApiServer to query the corresponding endpoint, register the pod IP into the elastic load listener, and at the same time write the pod IP back to ETCD, and set the listener status to normal.
[0055] In specific implementation, in the above service discovery method provided by the embodiments of the present invention, after detecting the modify listener operation in step S103 and before updating the registered listener configuration from the elastic load in real time, it may further include: detecting the modify listener operation when the user stores the modified data in ETCD to overwrite the original data. Specifically, when the user executes the operation of modifying the listener, the modified data will be first stored in ETCD to overwrite the original data. When the service discovery detects that a modification operation has been performed, it will update the registered listener configuration from the elastic load in real time; if the pod IP changes due to pod restart or the like, the service discovery will watch the change of this endpoint, re-register the latest pod IP into the elastic load balancer listener, and at the same time update the backend service address of the corresponding listener in ETCD, that is, modify the backend service group, so as to achieve smooth and seamless switching.
[0056] In specific implementation, in the above service discovery method provided by the embodiments of the present invention, after detecting the delete listener operation in step S104 and before deleting the registered listener from the elastic load in real time, it may further include: detecting the delete listener operation when the user deletes the listener data from ETCD. Specifically, when the user executes the operation of deleting the listener, the listener data in ETCD will be first deleted. When the service discovery monitors the data deletion, it will delete the registered listener from the elastic load in real time.
[0057] In specific implementation, in the above service discovery method provided by the embodiments of the present invention, step S105 of eliminating differences may include: when there are differences in the comparison result, modifying the listener data of the elastic load balancer to make the modified listener data of the elastic load balancer consistent with the listener data in ETCD. That is to say, when executing step S105, the service discovery will regularly compare the listener data in ETCD with the elastic load balancer listener, and make comparison and modification based on the data in ETCD as the main, eliminate the differences, maintain consistency, and form a closed-loop operation.
[0058] Based on the same inventive concept, an embodiment of the present invention further provides a service discovery device. Since the principle of this device for solving problems is similar to that of the foregoing service discovery method, the implementation of this device can refer to the implementation of the service discovery method, and the repeated parts will not be described again.
[0059] In specific implementation, the service discovery device provided by the embodiment of the present invention, as Figure 5 shown, specifically includes:
[0060] A data detection module 11, configured to detect the change of the listener data stored in ETCD in real time;
[0061] A new operation module 12, configured to, after detecting a new listener operation, call K8s to find the corresponding Endpoint, register the pod IP into the listener of the elastic load balancer, and write the pod IP into ETCD at the same time;
[0062] A modification operation module 13, configured to, after detecting a modification listener operation, update the registered listener configuration from the elastic load in real time;
[0063] A deletion operation module 14, configured to, after detecting a deletion listener operation, delete the registered listener from the elastic load in real time;
[0064] A periodic comparison module 15, configured to periodically compare the listener data in ETCD with the listener data of the elastic load balancer to eliminate differences and form a closed loop.
[0065] In the above service discovery device provided by the embodiment of the present invention, through the interaction of the above five modules, the high-efficiency integration of K8s and the elastic load balancer can be realized, effectively solving the automation process of creating, modifying, and deleting the elastic load balancer listener based on K8s. This process is completely automated relying on the service discovery mechanism, improving the application deployment efficiency, and the design method based on service discovery is more user-friendly and popularizable.
[0066] In specific implementation, in the above service discovery device provided by the embodiment of the present invention, the modification operation module 13 is specifically configured to, when the user stores the modification data in ETCD to overwrite the original data, detect the modification listener operation; after detecting the modification listener operation, update the registered listener configuration from the elastic load in real time; when it is detected that the Endpoint has changed, find the latest pod IP, and automatically register the latest pod IP into the listener of the elastic load balancer, and at the same time, update the backend service address of the corresponding listener in ETCD.
[0067] In specific implementation, in the above service discovery device provided by the embodiments of the present invention, the deletion operation module 14 is specifically configured to detect the listener deletion operation when the user deletes the listener data from ETCD; after detecting the listener deletion operation, delete the registered listener from the elastic load in real time.
[0068] In specific implementation, in the above service discovery device provided by the embodiments of the present invention, the regular comparison module 15 is used to regularly perform a comparison poll on the listener data in ETCD and the listener data of the elastic load balancer. If there are differences in the comparison results, modify the listener data of the elastic load balancer so that the modified listener data of the elastic load balancer is consistent with the listener data in ETCD, forming a closed loop.
[0069] For the more specific working processes of the above various modules, reference can be made to the corresponding content disclosed in the foregoing embodiments, and details will not be elaborated here.
[0070] Correspondingly, an embodiment of the present invention also discloses an electronic device, including a processor and a memory; wherein, when the processor executes the computer program stored in the memory, the service discovery method disclosed in the foregoing embodiments is implemented.
[0071] For the more specific process of the above method, reference can be made to the corresponding content disclosed in the foregoing embodiments, and details will not be elaborated here.
[0072] Furthermore, the present invention also discloses a computer-readable storage medium for storing a computer program; when the computer program is executed by a processor, the service discovery method disclosed above is implemented.
[0073] For the more specific process of the above method, reference can be made to the corresponding content disclosed in the foregoing embodiments, and details will not be elaborated here.
[0074] The various embodiments in this specification are described in a progressive manner. Each embodiment focuses on the differences from other embodiments. The same or similar parts among the various embodiments can be referred to each other. For the devices, equipment, and storage media disclosed in the embodiments, since they correspond to the methods disclosed in the embodiments, the descriptions are relatively simple, and the relevant parts can be referred to the description of the method part.
[0075] Those skilled in the art may further realize that the units and algorithm steps of each example described in combination with the embodiments disclosed herein can be implemented by electronic hardware, computer software, or a combination of both. To clearly illustrate the interchangeability of hardware and software, the composition and steps of each example have been generally described according to functions in the above description. Whether these functions are executed in a hardware or software manner depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementation should not be considered to exceed the scope of this application.
[0076] The steps of the methods or algorithms described in combination with the embodiments disclosed herein can be directly implemented by hardware, software modules executed by a processor, or a combination of both. The software modules can be placed in a random access memory (RAM), internal memory, read-only memory (ROM), electrically programmable ROM, electrically erasable programmable ROM, registers, hard disk, removable disk, CD-ROM, or any other form of storage medium known in the technical field.
[0077] In summary, a service discovery method provided by an embodiment of the present invention includes: real-time detecting changes in the listener data stored in ETCD; after detecting a new listener operation, calling K8s to find the corresponding Endpoint, registering the pod IP into the listener of the elastic load balancer, and at the same time writing the pod IP into ETCD; after detecting a modify listener operation, updating the registered listener configuration in the elastic load in real time; after detecting a delete listener operation, deleting the registered listener from the elastic load in real time; periodically comparing the listener data in ETCD with the listener data of the elastic load balancer to eliminate differences and form a closed loop. The above service discovery method realizes the efficient integration of K8s and the elastic load balancer based on the service discovery mechanism, effectively solves the automation process of creating, modifying, and deleting the elastic load balancer listener based on K8s. This process fully relies on the service discovery mechanism to achieve automation, improves the application deployment efficiency, and has better usability and popularity based on the service discovery design method. In addition, the present invention also provides corresponding devices, equipment, and computer-readable storage media for the service discovery method, further making the above method more practical, and the devices, equipment, and computer-readable storage media have corresponding advantages.
[0078] Finally, it should be noted that, in this article, relational terms such as first and second, etc. 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 presence of other identical elements in the process, method, article or device including the elements.
[0079] The service discovery method, device, equipment and storage medium provided by the present invention are introduced in detail above. Specific examples are used in this article to illustrate the principles and implementation methods of the present invention. The description of the above embodiments is only used to help understand the method of the present invention and its core idea; at the same time, for general technical personnel in this field, according to the idea of the present invention, there will be changes in the specific implementation method and application scope. In summary, the content of this specification should not be understood as a limitation on the present invention.
Claims
1. A service discovery method, characterized in that, Including: Real-time detection of changes in the listener data stored in ETCD; ETCD is independent of K8s and is used to store relevant data of the listener and display the listener status; After detecting the operation of creating a new listener, call K8s to find the corresponding Endpoint, register the pod IP into the listener of the elastic load balancer, and at the same time write the pod IP into ETCD to update the listener status; When the user stores modified data in ETCD and overwrites the original data, detect the operation of modifying the listener; after detecting the operation of modifying the listener, update the registered listener configuration from the elastic load in real time; When the user deletes the listener data from ETCD, detect the operation of deleting the listener; after detecting the operation of deleting the listener, delete the registered listener from the elastic load in real time; Regularly compare the listener data in ETCD with the listener data of the elastic load balancer. If there are differences in the comparison results, modify the listener data of the elastic load balancer to make the modified listener data of the elastic load balancer consistent with the listener data in ETCD, forming a closed loop.
2. The service discovery method according to claim 1, wherein The calling of K8s to find the corresponding Endpoint includes: Call ApiServer to query the corresponding Endpoint.
3. The service discovery method according to claim 2, wherein When updating the registered listener configuration from the elastic load in real time, it also includes: After detecting a change in the Endpoint, find the latest pod IP and automatically register the latest pod IP into the listener of the elastic load balancer.
4. The service discovery method according to claim 3, wherein When automatically registering the latest pod IP into the listener of the elastic load balancer, it also includes: Update the backend service address of the corresponding listener in ETCD.
5. A service discovery device, characterized in that, Including: Data detection module, used to real-time detect changes in the listener data stored in ETCD; ETCD is independent of K8s and is used to store relevant data of the listener and display the listener status; New operation module, used to call K8s to find the corresponding Endpoint after detecting the operation of creating a new listener, register the podIP into the listener of the elastic load balancer, and at the same time write the pod IP into ETCD to update the listener status; Modify operation module, used to detect the operation of modifying the listener when the user stores modified data in ETCD and overwrites the original data; after detecting the operation of modifying the listener, update the registered listener configuration from the elastic load in real time; Delete operation module, used to detect the operation of deleting the listener when the user deletes the listener data from ETCD; after detecting the operation of deleting the listener, delete the registered listener from the elastic load in real time; Regular comparison module, used to regularly compare the listener data in ETCD with the listener data of the elastic load balancer. If there are differences in the comparison results, modify the listener data of the elastic load balancer to make the modified listener data of the elastic load balancer consistent with the listener data in ETCD, forming a closed loop.
6. An electronic device, characterized in that, It includes a processor and a memory. Among them, when the processor executes the computer program stored in the memory, it implements the service discovery method according to any one of claims 1 to 4.
7. A computer-readable storage medium, characterized in that, It is used to store a computer program. Among them, when the computer program is executed by a processor, it implements the service discovery method according to any one of claims 1 to 4.
Citation Information
Patent Citations
Containerized application request copying method and system based on Kubernetes, medium and equipment
CN112860375A