Cluster automatic service discovery method and device, electronic equipment and readable storage medium
By defining custom resource CRDs and using the Kubernetes controller mechanism, we can monitor and manage changes to custom resources in Kubernetes, generate instance operation lists, solve the compatibility issues between enterprise internal service discovery mechanisms and Kubernetes services, and ensure normal access to Redis services and consistency of instance states.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- DUXIAOMAN TECH (BEIJING) CO LTD
- Filing Date
- 2023-06-01
- Publication Date
- 2026-06-26
AI Technical Summary
In a Kubernetes environment, the enterprise's internal service discovery mechanism is incompatible with the open-source K8s service approach, which means that when the container instance that is the access point changes in a fault or upgrade scenario, the business cannot access the Redis service normally.
By defining custom resource CRDs and using the Kubernetes controller mechanism, we can listen for changes to custom resources, obtain object information, generate an instance operation list, and send operation requests to the independent operation and maintenance platform to match the mounted instance with the application instance, thereby achieving consistent management of instance status.
This ensures that businesses can access Redis Pod instances normally when custom resources change, resolving the inconsistency between application instances and actual custom resources caused by automatic pod changes, and improving system operating efficiency.
Smart Images

Figure CN116866412B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of computer technology, and in particular to a method, apparatus, electronic device, and readable storage medium for automatic cluster service discovery. Background Technology
[0002] Kubernetes (K8s) is an open-source container orchestration engine from Google that supports automated deployment, massive scalability, and containerized application management. When deploying an application in a production environment, it is typically necessary to deploy multiple instances of the application to load balance application requests.
[0003] In Kubernetes, we can create multiple containers, each running an application instance. Then, through built-in load balancing strategies, we can manage, discover, and access this group of application instances without requiring complex manual configuration and processing by operations personnel.
[0004] Currently, major cloud vendors offer Kubernetes as a container orchestration solution for clustered Redis deployment. However, open-source solutions are incompatible with enterprise service discovery mechanisms, and using open-source Kubernetes services incurs high business transformation costs. Without modification, directly accessing the router can lead to service disruptions in scenarios involving router Pod migration during failures or upgrades. Because the container instance at the access point changes, but the list of access point instances doesn't update automatically, the business cannot access the Redis service normally. Summary of the Invention
[0005] In view of this, embodiments of the present invention provide a cluster automatic service discovery method, apparatus, electronic device, and readable storage medium to solve the problem of being unable to access Redis services normally when using an enterprise's internal service discovery mechanism.
[0006] According to one aspect of the present invention, a cluster automatic service discovery method is provided, comprising:
[0007] When a change is detected in a custom resource, the object information of the custom resource is obtained;
[0008] Compare the application instances in the object information with the instances mounted in the independent operation and maintenance platform to generate an instance operation list;
[0009] Send an instance operation request to the independent operation and maintenance platform, wherein the instance operation request is used to enable the independent operation and maintenance platform to perform corresponding operations on the instances mounted on the independent operation and maintenance platform according to the instance operation list.
[0010] This invention also provides a cluster automatic service discovery method, which further includes, before detecting changes to custom resources:
[0011] Listen for changes to pods;
[0012] When the change event is related to a custom resource, obtain information about the custom resource;
[0013] The information of the custom resource is changed according to the change event.
[0014] According to another aspect of the present invention, a cluster automatic service discovery apparatus is provided, comprising:
[0015] The first acquisition module is used to acquire the object information of the custom resource when a change is detected.
[0016] The comparison module is used to compare the instances in the object information with the instances mounted in the independent operation and maintenance platform, and generate an instance operation list;
[0017] The operation request module is used to send an instance operation request to the independent operation and maintenance platform, wherein the instance operation request is used to enable the independent operation and maintenance platform to perform corresponding operations on the instances mounted on the independent operation and maintenance platform according to the instance operation list.
[0018] According to another aspect of the present invention, an electronic device is provided, comprising:
[0019] Processor; and
[0020] Stored program memory,
[0021] The program includes instructions that, when executed by the processor, cause the processor to perform any of the aforementioned methods.
[0022] A computer-readable storage medium is also provided, wherein computer instructions are stored, the computer instructions being used to cause a computer to perform any of the aforementioned methods.
[0023] One or more technical solutions provided in the embodiments of this application can achieve the following technical effects:
[0024] 1. By defining CRDs for custom resources and using the Kubernetes controller mechanism, the matching between the mounted instance and the application instance of the custom resource is achieved, so that when the custom resource CR is actively changed, the business can still access the Redis Pod instance normally;
[0025] 2. By using a monitoring mechanism, we can obtain real-time information on Pod changes and modify custom resources accordingly, thus resolving the issue of inconsistency between the app's mounted instance and the actual custom resources caused by automatic pod changes. Attached Figure Description
[0026] Further details, features, and advantages of the invention are disclosed in the following description of exemplary embodiments in conjunction with the accompanying drawings, in which:
[0027] Figure 1 A flowchart illustrating an automatic service discovery method for clusters according to an exemplary embodiment of the present invention is shown. Figure 1 ;
[0028] Figure 2 A flowchart illustrating step S110 of a cluster automatic service discovery method according to an exemplary embodiment of the present invention is shown.
[0029] Figure 3 A schematic structural block diagram of a custom controller for a cluster automatic service discovery method according to an exemplary embodiment of the present invention is shown.
[0030] Figure 4 A flowchart illustrating an automatic service discovery method for clusters according to an exemplary embodiment of the present invention is shown. Figure 2 ;
[0031] Figure 5 A schematic flowchart of a cluster automatic service discovery method according to an exemplary embodiment of the present invention is shown.
[0032] Figure 6 A flowchart illustrating step S102 of a cluster automatic service discovery method according to an exemplary embodiment of the present invention is shown.
[0033] Figure 7 A flowchart illustrating step S103 of a cluster automatic service discovery method according to an exemplary embodiment of the present invention is shown.
[0034] Figure 8 A schematic diagram of the structure of a cluster automatic service discovery device according to an exemplary embodiment of the present invention is shown. Figure 1 ;
[0035] Figure 9 A schematic diagram of the structure of a cluster automatic service discovery device according to an exemplary embodiment of the present invention is shown. Figure 2 ;
[0036] Figure 10 A structural block diagram of an exemplary electronic device that can be used to implement embodiments of the present invention is shown. Detailed Implementation
[0037] Embodiments of the present invention will now be described in more detail with reference to the accompanying drawings. While some embodiments of the invention are shown in the drawings, it should be understood that the invention can be implemented in various forms and should not be construed as limited to the embodiments set forth herein. Rather, these embodiments are provided to provide a more thorough and complete understanding of the invention. It should be understood that the accompanying drawings and embodiments are for illustrative purposes only and are not intended to limit the scope of protection of the invention.
[0038] It should be understood that the various steps described in the method embodiments of the present invention may be performed in different orders and / or in parallel. Furthermore, the method embodiments may include additional steps and / or omit the steps shown. The scope of the present invention is not limited in this respect.
[0039] The term "comprising" and its variations as used herein are open-ended, meaning "including but not limited to". The term "based on" means "at least partially based on". The term "one embodiment" means "at least one embodiment"; the term "another embodiment" means "at least one additional embodiment"; the term "some embodiments" means "at least some embodiments". Definitions of other terms will be given in the following description. It should be noted that the concepts of "first", "second", etc., mentioned in this invention are used only to distinguish different devices, modules, or units, and are not intended to limit the order of functions performed by these devices, modules, or units or their interdependencies.
[0040] It should be noted that the terms "a" and "a plurality of" used in this invention are illustrative rather than restrictive. Those skilled in the art should understand that, unless otherwise expressly indicated in the context, they should be understood as "one or more".
[0041] The names of the messages or information exchanged between the multiple devices in the embodiments of the present invention are for illustrative purposes only and are not intended to limit the scope of these messages or information.
[0042] Firstly, a cluster-based automatic service discovery method, such as... Figure 1 As shown, it includes:
[0043] S110: When a change is detected in a custom resource, obtain the object information of the custom resource;
[0044] S120: Compare the application instances in the object information with the instances mounted in the independent operation and maintenance platform, and generate an instance operation list;
[0045] S130: Send an instance operation request to the independent operation and maintenance platform, wherein the instance operation request is used to enable the independent operation and maintenance platform to perform corresponding operations on the instances mounted on the independent operation and maintenance platform according to the instance operation list.
[0046] In this embodiment, the custom resource (CR) is used to describe information about the Redis cluster, storing essential cluster information such as topology status, number of instances, and instance IPs. The object information of the custom resource refers to the custom resource objects of RedisApp that are listened to from the K8s API Server each time, including information about the instances (appInstances, i.e., application instances) within the custom resource. The independent operation and maintenance platform refers to an operation and maintenance platform used to implement the enterprise's internal service discovery mechanism, replacing the functionality of K8s Services. In this embodiment, the independent operation and maintenance platform is exemplified by the Noah platform; Noah is a visualization platform that includes a collection of operation and maintenance systems such as service management, machine management, resource location, monitoring and alarms, automatic deployment, and task scheduling.
[0047] When the object information of the custom resource changes, the application instances (appInstances) of the object information become inconsistent with the instances mounted on the independent operation and maintenance platform. In this case, it is necessary to modify the instances mounted on the independent operation and maintenance platform according to the object information of the custom resource to match the current state of the mounted instances with the desired state. Based on this, this embodiment generates an instance operation list for performing instance change operations on the independent operation and maintenance platform and sends an instance operation request to the independent operation and maintenance platform. The independent operation and maintenance platform performs the corresponding operations according to the instance operation list to ensure that the instances mounted on the independent operation and maintenance platform are consistent with the application instances (appInstances) in the custom resource CR.
[0048] The instance operation list is generated by comparing the application instances (appInstances) in the object information with the instances mounted in the independent operation and maintenance platform.
[0049] In some embodiments, the instance operation list includes at least one of a delete list, a mount list, and an update list;
[0050] The corresponding operations include deleting instances from the deletion list, mounting instances from the mount list, and updating instances from the update list.
[0051] In this embodiment, corresponding operations are performed based on changes in application instances within the monitored object information. Specifically, a deletion list containing all instances to be deleted can be generated based on the instances in the monitored object information and their deletion events; a mount list containing all instances to be mounted can be generated based on the instances in the monitored object information and their mount events; and an update list containing all instances to be updated can be generated based on the instances in the monitored object information and their update events.
[0052] Operations on the instance may include one or more of the following: deletion, mounting, and update operations. Update operations may also include blocking and unblocking operations. Therefore, the instance operation list may include a deletion list, a mounting list, and an update list, or it may only include one or two of these. Upon receiving an instance operation request, the independent operation and maintenance platform performs the corresponding operations on the instances in the deletion list, mounting list, and update list.
[0053] In some embodiments, the step of comparing the application instances in the object information with the instances mounted in the independent operation and maintenance platform to generate an instance operation list includes:
[0054] If the object information contains at least one instance that is not mounted in the independent operation and maintenance platform, a mounting list is generated based on the instance to be mounted.
[0055] If there is at least one instance in the instance mounted in the independent operation and maintenance platform that corresponds to but is different from the object information and needs to be updated, then an update list is generated based on the instance to be updated.
[0056] If at least one instance that is not present in the object information exists among the instances mounted in the independent operation and maintenance platform, a deletion list is generated based on the third instance.
[0057] In this embodiment, the instance operation list is generated based on the comparison between the application instance and the instances mounted in the independent operation and maintenance platform. Specifically, in the application instance of the object information, if there are instances that are not mounted in the independent operation and maintenance platform, a mounting list is generated for the independent operation and maintenance platform; if there are instances that are not updated in the independent operation and maintenance platform, an update list is generated for the independent operation and maintenance platform; if there are instances that do not exist in the application instance but are mounted in the independent operation and maintenance platform, a deletion list is generated for the independent operation and maintenance platform.
[0058] In some embodiments, when the cluster is a migration cluster, the instance operation list does not generate the deletion list, or the deletion operation is ineffective.
[0059] In this embodiment, the Custom Resource Definition (CRD) may also include a Redis cluster type (redisClusterType), which may include types such as OrdinaryCluster, TransitionCluster, and UnmanagedCluster. If the Redis cluster is an OrdinaryCluster, the instances on the independent operation and maintenance platform must strictly align with the mounted and masked states of the instances in the Custom Resource Definition (CR). If it is a TransitionCluster, no instance deletion operations will be performed; only mounting and updating (such as masking and unmasking) operations will be performed on the instances. This is because this mode is used for migrating old clusters to new architectures, and during this process, there may be some cases where the actual number of instances mounted on the independent operation and maintenance platform (such as noah) is greater than the number of instances in the Custom Resource Definition (CR). If it is an UnmanagedCluster, no application instance processing operations will be performed on changes to the Custom Resource Definition (CR).
[0060] In particular, when the Redis cluster is a Transition Cluster, no instance deletion operation will be performed. This solution can be implemented in several different ways, such as not generating a deletion list when the instance operation list is in place, or making the deletion operation ineffective.
[0061] In some embodiments, obtaining the object information of the custom resource, such as Figure 2 As shown, it includes:
[0062] S111: Obtain the latest version of the object information of the custom resource and continuously obtain the increment of the object information;
[0063] S112: Establish local storage based on the object information and create an index corresponding to the object information;
[0064] S113: Update the object information in the local storage according to the incremental update;
[0065] S114: Create a first tag for the increment and send the first tag to the work queue;
[0066] S115: Obtain the first tag from the work queue;
[0067] S116: Obtain the object information of the custom resource from the local storage based on the first tag and the index.
[0068] In this embodiment, as Figure 3As shown, using Kubernetes' operator mechanism, a custom controller can be defined, including structures such as an informer, a work queue, and reconcile (the control process by which the controller moves the current state of associated resources toward the desired state). The reflector in the informer can monitor the custom resource objects of RedisApp using the ListWatch method. It lists all instances of the custom resource from the Kubernetes API Server, obtains the latest resource version (ResourceVersion), and then uses the Watch method to listen for all changes after the resource version (ResourceVersion). Once an instance of the object is created, deleted, or updated, the reflector receives a notification of the change event and uses reflection to instantiate the monitored result into a specific object. The combination of the change event and its corresponding instance is called the delta, which is then stored in the delta-first-in, first-out (FIFO) queue. The delta-first-in, first-out queue forms a first-in, first-out (FIFO) queue for the objects with incremental changes monitored by the reflector.
[0069] The Informer continuously reads increments from the DeltaFIFO (incremental priority queue). Each time an object appears, the Informer determines the event type of the increment and then creates or updates the local storage (LocalStore, which can be a cache). For example, if the event type is "Added" (adding an object), the Informer saves the object in the increment to local storage and creates an index for it; if it's a deletion operation, it deletes the object from local storage.
[0070] In addition, LocalStore utilizes indexes to provide fast lookup capabilities. When users need to query (Get / List) Kubernetes objects, they can directly request LocalStore, thereby reducing the pressure on the Kubernetes API Server.
[0071] For the workqueue, after DeltaFIFO completes the synchronization of LocalStore, it will pop the event to the controller. The controller will call the pre-registered callback functions (such as OnAdd, OnUpdate, OnDelete) for processing. These callback functions only perform some simple filtering work. Finally, the object key-value pairs (i.e., the first tags) created according to the increment will be put into the workqueue for business logic processing in reconcile.
[0072] During the reconcile control process, based on the key value of the first tag obtained from the work queue, the fast lookup capability provided by the index can be used to retrieve detailed information about the object from local storage. If the corresponding object cannot be retrieved, it indicates that the custom resource has been deleted, the Redis cluster is no longer in use, and the current process ends. If the corresponding object can be retrieved, the operation described in the previous embodiments—comparing the instances in the object information with the instances mounted on the independent operation and maintenance platform to generate an instance operation list—can continue.
[0073] In one type of embodiment, such as Figure 4 As shown, before detecting changes to the custom resource, the process also includes:
[0074] S101: Listen for pod change events;
[0075] S102: When the change event is related to a custom resource, obtain information about the custom resource;
[0076] S103: Modify the information of the custom resource according to the change event.
[0077] The content described in S110 to S130 of the aforementioned embodiments can be a scenario where the custom resource CR of RedisApp is actively modified. In this embodiment, a StatefulSet is used to manage multiple router replicas. If a pod in the StatefulSet experiences an anomaly or upgrade, the application instances (appInstances) of the custom resource CR in RedisApp cannot be changed, thus preventing reconcile. This leads to inconsistencies between the instances mounted on the independent operation and maintenance platform (which could be noah) and those provided in the actual StatefulSet, resulting in services accessing abnormal instances. This embodiment addresses this issue by subscribing to pod changes and updating the application instances of the custom resource in the node in real time.
[0078] In this context, a Pod is the smallest unit of operation and deployment in Kubernetes (K8s). Services managed using K8s containers, such as MySQL and Redis, require the creation of Pods to provide services. A StatefulSet is primarily used to manage stateful application Pods on K8s. Its main function in this invention is to maintain the number of Pods. For example, if a StatefulSet is configured to run three Pods, and one Pod fails, the StatefulSet will automatically start a new Pod to ensure a total of three Pods are running.
[0079] like Figure 5 As shown, when the PodWatcher component detects a change in a pod, it first determines whether the pod change event is related to a custom resource. If so, it retrieves the custom resource information associated with the change event. The pod change event may include at least one of the following: pod create event, pod update event, and pod delete event.
[0080] In some embodiments, such as Figure 6 As shown, step S102: When the change event is related to a custom resource, obtain information about the custom resource, including:
[0081] When a change event is detected in a pod, determine whether the pod contains a second tag related to Redis and the aforementioned custom resource:
[0082] If included, information about the associated custom resource is obtained based on the second tag;
[0083] If it is not included, no processing will be performed.
[0084] In this embodiment, before making changes to custom resources, it is first determined whether the monitored pod change event is related to Redis and custom resources. If it is not related, no processing is required. If it is related, subsequent judgment and changes are then performed.
[0085] like Figure 5 As shown, the second label can be a label containing redis-crd, such as redis-app-operator-crd. When a pod contains a second label, the name of the custom resource (CR Name) can be obtained through the second label, and then the custom resource CR associated with that name can be obtained.
[0086] The solution in this embodiment can effectively improve the system's operating efficiency.
[0087] In some embodiments, such as Figure 5 , Figure 7 As shown, step S103: modifying the information of the custom resource according to the change event includes:
[0088] When processing the pod creation event, switch to processing the pod update event;
[0089] When processing the pod update event, determine whether there is an instance in the custom resource corresponding to the pod update event:
[0090] If it exists, determine whether the pod is in a state where it can provide services. Otherwise, set the instance in the custom resource to a blocked state. If it is, do not process it.
[0091] If it does not exist, determine whether the pod is in a state where it can provide services. If it is, store the instance in the custom resource in a masked state; otherwise, do not process it.
[0092] When processing the pod deletion event, determine whether there is an instance corresponding to the pod deletion event in the custom resource. If it exists, delete the instance from the custom resource; otherwise, do not process it.
[0093] Among them, such as Figure 5 As shown, after determining that the issue is related to Redis and custom resource CR, this embodiment further processes the custom resource CR based on the different pod change events. Pod change events include creation events (podcreate), update events (pod update), and deletion events (pod delete). Since the pod's status is changed to running when a pod is created, an update event is generated at this time. Therefore, it can be processed in the same way as a pod update event.
[0094] When handling pod update events, two checks are performed: first, to check if the corresponding instance exists in the Resource Catalog (CR), and second, to check if the pod's status is "ready" (i.e., ready to provide services). If the corresponding instance does not exist and the pod is not "ready," no action is taken. If the corresponding instance does not exist and the pod is "ready," the instance is saved to the custom resource CR in a blocked state. If the corresponding instance exists and the pod is not "ready," it indicates an instance error; the instance is then blocked and saved to the custom resource CR. If the corresponding instance exists and the pod is "ready," no action is taken.
[0095] When handling pod deletion events, if the corresponding instance does not exist in the custom resource, no action is taken; otherwise, the instance is deleted from the custom resource.
[0096] like Figure 5 As shown, after updating the custom resource with the above operations, the tuning logic of Redisapp can be triggered to execute steps S110 to S130 in the aforementioned method, so that the instance in the independent operation and maintenance platform is consistent with the application instance in the custom resource CR.
[0097] This invention achieves matching between the mounted instance and the application instance of the custom resource by defining a custom resource's CRD and using Kubernetes' controller mechanism. This ensures that when the custom resource's CRD is actively changed, the application can still access the Redis Pod instance normally. Furthermore, through a monitoring mechanism, it obtains Pod change information in real time and modifies the custom resource accordingly, resolving the inconsistency between the app's mounted instance and the actual custom resource caused by automatic pod changes.
[0098] Secondly, a cluster automatic service discovery device 1, such as... Figure 8 As shown, it includes:
[0099] The first acquisition module 11 is used to acquire the object information of the custom resource when a change in the custom resource is detected.
[0100] Comparison module 12 is used to compare the instances in the object information with the instances mounted in the independent operation and maintenance platform, and generate an instance operation list;
[0101] The operation request module 13 is used to send an instance operation request to the independent operation and maintenance platform, wherein the instance operation request is used to enable the independent operation and maintenance platform to perform corresponding operations on the instances mounted on the independent operation and maintenance platform according to the instance operation list.
[0102] This embodiment corresponds to the content of S110 to S130 described in the previous embodiments. The custom resource (CR) is used to describe information about the Redis cluster, storing essential cluster information such as topology status, number of instances, and instance IPs. The custom resource object information refers to the custom resource objects of RedisApp that are listened to from the K8sAPIServer each time, including information about the instances (appInstances, i.e., application instances) within the custom resource. The independent operation and maintenance platform refers to an operation and maintenance platform used to implement the enterprise's internal service discovery mechanism, replacing the functionality of K8s Service. In this embodiment, the independent operation and maintenance platform uses the Noah platform as an example.
[0103] When the object information of the custom resource changes, the application instances (appInstances) of the object information become inconsistent with the instances mounted on the independent operation and maintenance platform. In this case, it is necessary to modify the instances mounted on the independent operation and maintenance platform according to the object information of the custom resource to match the current state of the mounted instances with the desired state. Based on this, this embodiment generates an instance operation list for performing instance change operations on the independent operation and maintenance platform and sends an instance operation request to the independent operation and maintenance platform. The independent operation and maintenance platform performs the corresponding operations according to the instance operation list to ensure that the instances mounted on the independent operation and maintenance platform are consistent with the application instances (appInstances) in the custom resource CR.
[0104] The instance operation list is generated by comparing the application instances (appInstances) in the object information with the instances mounted in the independent operation and maintenance platform.
[0105] In some embodiments, the cluster automatic service discovery device 1, such as Figure 9 As shown, it also includes:
[0106] Listening module 101 is used to listen for pod change events;
[0107] The second acquisition module 102 is used to acquire information about the custom resource when the change event is related to the custom resource;
[0108] The change module 103 is used to change the information of the custom resource according to the change event.
[0109] The aforementioned embodiment's cluster automatic service discovery device can be used in scenarios where custom resource CRs of RedisApp are actively modified. However, in this embodiment, a StatefulSet is used to manage multiple router replicas. If a pod in the StatefulSet experiences an anomaly or upgrade, the application instances (appInstances) of the custom resource CRs in RedisApp cannot be changed, thus preventing reconcile. This leads to inconsistencies between the instances mounted on the independent operations platform (which could be NoAH) and those provided in the actual StatefulSet, resulting in services accessing abnormal instances. This embodiment addresses this issue by subscribing to pod changes and updating the application instances of custom resources on nodes in real time.
[0110] In this context, a Pod is the smallest unit of operation and deployment in Kubernetes (K8s). Services managed using K8s containers, such as MySQL and Redis, require the creation of Pods to provide services. A StatefulSet is primarily used to manage stateful application Pods on K8s. Its main function in this invention is to maintain the number of Pods. For example, if a StatefulSet is configured to run three Pods, and one Pod fails, the StatefulSet will automatically start a new Pod to ensure a total of three Pods are running.
[0111] When the monitoring module (i.e., the PodWatcher component) detects a change to a pod, if the pod's change event is related to a custom resource, the second acquisition module retrieves the custom resource information associated with that change event. The change module then modifies the custom resource according to the change event. The pod's change event may include at least one of the following: pod creation event, pod update event, and pod deletion event.
[0112] like Figure 9 As shown, after the change module 103 changes the information of the custom resource, the first acquisition module 11, the comparison module 12 and the operation request module 13 in the aforementioned device can be triggered in sequence to make the instance in the independent operation and maintenance platform consistent with the application instance in the custom resource CR.
[0113] Thirdly, exemplary embodiments of the present invention also provide an electronic device, including: at least one processor; and a memory communicatively connected to the at least one processor. The memory stores a computer program executable by the at least one processor, the computer program being executed by the at least one processor to cause the electronic device to perform a method according to an embodiment of the present invention.
[0114] An exemplary embodiment of the present invention also provides a non-transitory computer-readable storage medium storing a computer program, wherein the computer program, when executed by a computer's processor, is used to cause the computer to perform a method according to an embodiment of the present invention.
[0115] An exemplary embodiment of the present invention also provides a computer program product, including a computer program, wherein, when executed by a computer's processor, the computer program is used to cause the computer to perform a method according to an embodiment of the present invention.
[0116] refer to Figure 10The present invention will now be described in the form of a structural block diagram of an electronic device 200 that can serve as a server or client of the present invention, which is an example of a hardware device that can be applied to various aspects of the present invention. The term "electronic device" is intended to represent various forms of digital electronic computer devices, such as laptop computers, desktop computers, workstations, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The electronic device can also represent various forms of mobile devices, such as personal digital processors, cellular phones, smartphones, wearable devices, and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely illustrative and are not intended to limit the implementation of the invention described and / or claimed herein.
[0117] like Figure 10 As shown, the electronic device 200 includes a computing unit 201, which can perform various appropriate actions and processes according to a computer program stored in a read-only memory (ROM) 202 or a computer program loaded from a storage unit 208 into a random access memory (RAM) 203. The RAM 203 may also store various programs and data required for the operation of the device 200. The computing unit 201, ROM 202, and RAM 203 are interconnected via a bus 204. An input / output (I / O) interface 205 is also connected to the bus 204.
[0118] Multiple components in electronic device 200 are connected to I / O interface 205, including: input unit 206, output unit 207, storage unit 208, and communication unit 209. Input unit 206 can be any type of device capable of inputting information to electronic device 200. Input unit 206 can receive input digital or character information and generate key signal inputs related to user settings and / or function control of electronic device. Output unit 207 can be any type of device capable of presenting information and may include, but is not limited to, a display, speaker, video / audio output terminal, vibrator, and / or printer. Storage unit 208 may include, but is not limited to, disks and optical discs. Communication unit 209 allows electronic device 200 to exchange information / data with other devices through computer networks such as the Internet and / or various telecommunications networks, and may include, but is not limited to, modems, network cards, infrared communication devices, wireless communication transceivers, and / or chipsets, such as Bluetooth™ devices, WiFi devices, WiMax devices, cellular communication devices, and / or the like.
[0119] The computing unit 201 can be a variety of general-purpose and / or special-purpose processing components with processing and computing capabilities. Some examples of the computing unit 201 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various special-purpose artificial intelligence (AI) computing chips, various computing units running machine learning model algorithms, a digital signal processor (DSP), and any suitable processor, controller, microcontroller, etc. The computing unit 201 performs the various methods and processes described above. For example, in some embodiments, the methods may be implemented as computer software programs tangibly contained in a machine-readable medium, such as storage unit 208. In some embodiments, part or all of the computer program may be loaded and / or installed on the electronic device 200 via ROM 202 and / or communication unit 209. In some embodiments, the computing unit 201 may be configured to execute methods by any other suitable means (e.g., by means of firmware).
[0120] The program code used to implement the methods of the present invention can be written in any combination of one or more programming languages. This program code can be provided to a processor or controller of a general-purpose computer, special-purpose computer, or other programmable data processing device, such that when executed by the processor or controller, the program code causes the functions / operations specified in the flowcharts and / or block diagrams to be implemented. The program code can be executed entirely on the machine, partially on the machine, as a standalone software package partially on the machine and partially on a remote machine, or entirely on a remote machine or server.
[0121] In the context of this invention, a machine-readable medium can be a tangible medium that may contain or store a program for use by or in conjunction with an instruction execution system, apparatus, or device. A machine-readable medium can be a machine-readable signal medium or a machine-readable storage medium. Machine-readable media can include, but are not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, apparatus, or devices, or any suitable combination of the foregoing. More specific examples of machine-readable storage media include electrical connections based on one or more wires, portable computer disks, hard disks, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fibers, portable compact disk read-only memory (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination of the foregoing.
[0122] As used herein, the terms "machine-readable medium" and "computer-readable medium" refer to any computer program product, device, and / or apparatus (e.g., disk, optical disk, memory, programmable logic device (PLD)) for providing machine instructions and / or data to a programmable processor, including machine-readable media that receive machine instructions as machine-readable signals. The term "machine-readable signal" refers to any signal for providing machine instructions and / or data to a programmable processor.
[0123] To provide interaction with a user, the systems and techniques described herein can be implemented on a computer having: a display device for displaying information to the user (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor); and a keyboard and pointing device (e.g., a mouse or trackball) through which the user provides input to the computer. Other types of devices can also be used to provide interaction with the user; for example, feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user can be received in any form (including sound input, voice input, or tactile input).
[0124] The systems and technologies described herein can be implemented in computing systems that include backend components (e.g., as a data server), or computing systems that include middleware components (e.g., an application server), or computing systems that include frontend components (e.g., a user computer with a graphical user interface or web browser through which a user can interact with embodiments of the systems and technologies described herein), or any combination of such backend, middleware, or frontend components. The components of the system can be interconnected via digital data communication of any form or medium (e.g., a communication network). Examples of communication networks include local area networks (LANs), wide area networks (WANs), and the Internet.
[0125] Computer systems can include clients and servers. Clients and servers are generally located far apart and typically interact through communication networks. Client-server relationships are created by computer programs running on the respective computers and having a client-server relationship with each other.
Claims
1. A cluster automatic service discovery method, characterized in that, include: Listen for changes to pods; When the change event is related to a custom resource, obtain information about the custom resource; The information of the custom resource is changed according to the change event; When a change is detected in the custom resource, the object information of the custom resource is obtained; By comparing the application instances in the object information with the instances mounted in the independent operation and maintenance platform, an instance operation list is generated; wherein, the instance operation list includes at least one of the following: a deletion list, a mounting list, and an update list; An instance operation request is sent to the independent operation and maintenance platform, wherein the instance operation request is used to enable the independent operation and maintenance platform to perform corresponding operations on the instances mounted on the independent operation and maintenance platform according to the instance operation list, so that the instances mounted on the independent operation and maintenance platform are consistent with the application instances in the custom resources; wherein the corresponding operation includes a deletion operation on instances in the deletion list, a mounting operation on instances in the mounting list, and an update operation on instances in the update list, wherein the update operation further includes a masking and unmasking operation.
2. The cluster automatic service discovery method according to claim 1, characterized in that: The process of comparing the application instances in the object information with the instances mounted in the independent operation and maintenance platform generates an instance operation list, including: If the object information contains at least one instance that is not mounted in the independent operation and maintenance platform, a mounting list is generated based on the instance to be mounted. If there is at least one instance in the instance mounted in the independent operation and maintenance platform that corresponds to but is different from the object information and needs to be updated, then an update list is generated based on the instance to be updated. If at least one instance that is not present in the object information exists among the instances mounted in the independent operation and maintenance platform, a deletion list is generated based on the third instance.
3. The cluster automatic service discovery method according to claim 1, characterized in that: When the cluster is a migration cluster, the instance operation list does not generate the deletion list, or The deletion operation is ineffective.
4. The cluster automatic service discovery method according to claim 1, characterized in that, The step of obtaining the object information of the custom resource includes: Obtain the latest version of the object information of the custom resource and continuously obtain the increment of the object information; Local storage is established based on the object information, and an index corresponding to the object information is created; Update the object information in the local storage according to the incremental update; Create a first tag for the increment and send the first tag to the work queue; Retrieve the first tag from the work queue; The object information of the custom resource is obtained from the local storage based on the first tag and the index.
5. The cluster automatic service discovery method according to claim 1, characterized in that, When the change event is related to a custom resource, obtaining information about the custom resource includes: When a change event is detected in a pod, determine whether the pod contains a second tag related to Redis and the aforementioned custom resource: If included, information about the associated custom resource is obtained based on the second tag; If it is not included, no processing will be performed.
6. The cluster automatic service discovery method according to claim 1, characterized in that: The change event includes at least one of the following: pod creation event, pod update event, and pod deletion event.
7. The cluster automatic service discovery method according to claim 6, characterized in that, The step of modifying the information of the custom resource according to the change event includes: When processing the pod creation event, switch to processing the pod update event; When processing the pod update event, determine whether there is an instance in the custom resource corresponding to the pod update event: If it exists, determine whether the pod is in a state where it can provide services. Otherwise, set the instance in the custom resource to a blocked state. If it is, do not process it. If it does not exist, determine whether the pod is in a state where it can provide services. If it is, store the instance in the custom resource in a masked state; otherwise, do not process it. When processing the pod deletion event, determine whether there is an instance corresponding to the pod deletion event in the custom resource. If it exists, delete the instance from the custom resource; otherwise, do not process it.
8. A cluster automatic service discovery device, characterized in that, include: The listening module is used to listen for change events in the pod. The second acquisition module is used to acquire information about the custom resource when the change event is related to the custom resource; The modification module is used to modify the information of the custom resource according to the modification event; The first acquisition module is used to acquire the object information of the custom resource when a change is detected. The comparison module is used to compare the instances in the object information with the instances mounted in the independent operation and maintenance platform, and generate an instance operation list; wherein, the instance operation list includes at least one of a deletion list, a mounting list, and an update list; The operation request module is used to send an instance operation request to the independent operation and maintenance platform. The instance operation request is used to enable the independent operation and maintenance platform to perform corresponding operations on the instances mounted on the independent operation and maintenance platform according to the instance operation list, so that the instances mounted on the independent operation and maintenance platform are consistent with the application instances in the custom resources. The corresponding operations include deletion operations on instances in the deletion list, mounting operations on instances in the mounting list, and update operations on instances in the update list. The update operations also include blocking and unblocking operations.
9. An electronic device, comprising: processor; as well as Stored program memory, The program includes instructions that, when executed by the processor, cause the processor to perform the method according to any one of claims 1-7.
10. A readable storage medium, wherein, The computer contains computer instructions for causing the computer to perform the method according to any one of claims 1-7.