A Multi-Cluster Microservice Access Method and System Based on Kubernetes
By initializing the correspondence between the microservice forwarding module and the subcluster in a multi-cluster environment, and using the Kubeconfig configuration file for request mapping and forwarding, the unified and efficient communication problems of microservice access is solved, and lightweight microservice access and unified entry management is realized.
Patent Information
- Application Number
- CN202310023742.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-01-09
- Publication Date
- 2025-08-05
- Estimated Expiration
- 2043-01-09
AI Technical Summary
In a multi-cluster environment, it is difficult for the prior art to provide an economical and universal microservice access method, especially in the case of achieving unified and efficient communication of microservices between multiple clusters without relying on an external load balancer.
By initializing the correspondence between the microservice forwarding module and the microservices of each subcluster, identifying user requests and encapsulating them into standard requests, and using Kubeconfig configuration files for mapping and forwarding, realizing a unified entrance to microservice access.
It realizes lightweight microservice access without additional traffic management components, blocks subcluster differences, unifies access portals, and improves the convenience of management and use.
Smart Images

Figure CN116016233B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of microservice access technology, and in particular to a Kubernetes-based multi-cluster microservice access method and system. Background Art
[0002] Kubernetes is an open-source system for automating the deployment, scaling, and management of containerized applications. It allows users to deploy applications across multiple hosts and automatically manages their state. In a microservices architecture, an application is split into many independent services, each deployed independently, typically using container technology. Kubernetes helps manage these containerized services, including deployment, scaling, monitoring, and maintenance.
[0003] In a multi-cluster environment, users can run microservices on multiple independent Kubernetes clusters. This helps users better isolate services and manage resources, and makes it easier to scale to new environments. However, in a multi-cluster environment, users also need to consider how to enable services to communicate across multiple clusters. In practice, there are many ways to access individual microservices. For example, a central load balancer can be used to route requests to the microservices in the appropriate subcluster, but this method requires reliance on an external load balancer and increases costs. Alternatively, each microservice can be exposed externally in each cluster, but this approach results in fragmented and inconsistent traffic entry points.
[0004] Therefore, how to provide an economical and more versatile microservice access method has become a technical problem that needs to be solved urgently. Summary of the Invention
[0005] In view of this, in order to overcome the shortcomings of the existing technology, the present invention aims to provide a multi-cluster microservice access method based on Kubernetes.
[0006] In one aspect, the present invention provides a multi-cluster microservice access method based on Kubernetes, comprising:
[0007] Step S1: Initialize the correspondence between the microservice forwarding module and each sub-cluster microservice;
[0008] Step S2: The microservice forwarding module identifies the corresponding microservice based on the microservice access request sent by the user;
[0009] Step S3: The microservice forwarding module encapsulates the user's microservice access request into a standard microservice request that meets the access entry standard of the identified microservice;
[0010] Step S4: After receiving the standard microservice request, the microservice in the subcluster returns response data corresponding to the standard microservice request to the user.
[0011] Furthermore, step S1 of the multi-cluster microservice access method based on Kubernetes of the present invention includes:
[0012] Load the Kubeconfig configuration files of each subcluster through the microservice forwarding module;
[0013] Expose the IP and port of the microservice forwarding module to the outside world, and configure the mapping rules between the microservice forwarding module and the microservices of each sub-cluster;
[0014] The microservice access portal of each sub-cluster is exposed through the microservice forwarding module.
[0015] Furthermore, step S2 of the multi-cluster microservice access method based on Kubernetes of the present invention includes:
[0016] Step S21: The user sends a microservice access request to the microservice forwarding module according to the IP and port exposed by the microservice forwarding module, where the microservice access request includes a recognizable request header;
[0017] Step S22: The microservice forwarding module receives the microservice access request and finds the corresponding subcluster according to the identifiable request header in the microservice access request;
[0018] Step S23: The microservice forwarding module reads the corresponding Kubeconfig configuration file from the loaded Kubeconfig configuration files of each sub-cluster;
[0019] Step S24: The microservice forwarding module reads the request path in the microservice access request sent by the user, and identifies the corresponding microservice according to the read request path and mapping rules.
[0020] On the other hand, the present invention provides a multi-cluster microservice access system based on Kubernetes, comprising:
[0021] The control cluster is used to deploy the microservice forwarding module, which forwards the user's microservice access request to the microservice of the corresponding subcluster;
[0022] The subcluster is used to deploy microservices and return response data corresponding to the standard microservice request to the user after receiving the standard microservice request.
[0023] Furthermore, the microservice forwarding module in the multi-cluster microservice access system based on Kubernetes of the present invention is used to load the Kubeconfig configuration file of each sub-cluster and expose the microservice access entrance of each sub-cluster.
[0024] Furthermore, the microservice forwarding module in the multi-cluster microservice access system based on Kubernetes of the present invention is used to expose the IP and port to the user, receive the microservice access request sent by the user, find the corresponding subcluster according to the identifiable request header in the microservice access request; read the corresponding Kubeconfig configuration file from the loaded Kubeconfig configuration file of each subcluster; read the request path in the microservice access request sent by the user, and identify the corresponding microservice according to the read request path and mapping rules.
[0025] Furthermore, the microservice forwarding module in the Kubernetes-based multi-cluster microservice access system of the present invention is used to encapsulate the user's microservice access request into a standard microservice request that meets the access entry standard of the identified microservice.
[0026] Secondly, the present invention provides a computer-readable storage medium having a computer program stored thereon. When the computer program is executed, the steps of the Kubernetes-based multi-cluster microservice access method of the present invention are performed.
[0027] Finally, the present invention also provides a computer device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the program, the steps of the Kubernetes-based multi-cluster microservice access method of the present invention are performed.
[0028] The present invention provides a multi-cluster microservice access method and system based on Kubernetes, which has the following beneficial effects:
[0029] 1. Make microservice access more lightweight and implement traffic management for sub-cluster microservices without the need for additional traffic management components.
[0030] 2. The differences between each sub-cluster are shielded, and the microservices of all sub-clusters are accessed through the management and control cluster, making the access entrance unified and easy to manage and use. BRIEF DESCRIPTION OF THE DRAWINGS
[0031] In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the following briefly introduces the drawings required for use in 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 paying any creative work.
[0032] Figure 1 This is a flowchart of a multi-cluster microservice access method based on Kubernetes according to the first exemplary embodiment of the present invention.
[0033] Figure 2 This is a flowchart of a multi-cluster microservice access method based on Kubernetes according to the second exemplary embodiment of the present invention.
[0034] Figure 3 This is a schematic diagram of the architecture of a multi-cluster microservice access system based on Kubernetes according to the third exemplary embodiment of the present invention. DETAILED DESCRIPTION
[0035] The embodiments of the present invention are described in detail below with reference to the accompanying drawings.
[0036] It should be noted that, in the absence of conflict, the following embodiments and features in the embodiments may be combined with each other; and, based on the embodiments in this disclosure, all other embodiments obtained by persons of ordinary skill in the art without creative work are within the scope of protection of this disclosure.
[0037] It should be noted that various aspects of the embodiments within the scope of the appended claims are described below. It should be apparent that the aspects described herein can be embodied in a wide variety of forms, and any specific structure and / or function described herein is merely illustrative. Based on this disclosure, it should be understood by those skilled in the art that an aspect described herein can be implemented independently of any other aspect, and two or more of these aspects can be combined in various ways. For example, any number of aspects described herein can be used to implement an apparatus and / or practice a method. In addition, other structures and / or functionalities other than one or more of the aspects described herein can be used to implement this apparatus and / or practice this method.
[0038] Figure 1 FIG. 1 is a flowchart of a multi-cluster microservice access method based on Kubernetes according to an exemplary first embodiment of the present invention. Figure 1 As shown, the method of this embodiment includes:
[0039] Step S1: Initialize the correspondence between the microservice forwarding module and each sub-cluster microservice;
[0040] Step S2: The microservice forwarding module identifies the corresponding microservice based on the microservice access request sent by the user;
[0041] Step S3: The microservice forwarding module encapsulates the user's microservice access request into a standard microservice request that meets the access entry standard of the identified microservice;
[0042] Step S4: After receiving the standard microservice request, the microservice in the subcluster returns response data corresponding to the standard microservice request to the user.
[0043] Step S1 of the method of this embodiment includes: loading the Kubeconfig configuration file of each subcluster through the microservice forwarding module; exposing the IP and port of the microservice forwarding module to the outside, configuring the mapping rules between the microservice forwarding module and the microservices of each subcluster; and exposing the microservice access entrance of each subcluster through the microservice forwarding module.
[0044] Figure 2 This is a flowchart of a multi-cluster microservice access method based on Kubernetes according to an exemplary second embodiment of the present invention. Figure 1 The preferred embodiment of the method shown is as follows Figure 2 As shown, step S2 of the method of this embodiment includes:
[0045] Step S21: The user sends a microservice access request to the microservice forwarding module according to the IP and port exposed by the microservice forwarding module, where the microservice access request includes a recognizable request header;
[0046] Step S22: The microservice forwarding module receives the microservice access request and finds the corresponding subcluster according to the identifiable request header in the microservice access request;
[0047] Step S23: The microservice forwarding module reads the corresponding Kubeconfig configuration file from the loaded Kubeconfig configuration files of each sub-cluster;
[0048] Step S24: The microservice forwarding module reads the request path in the microservice access request sent by the user, and identifies the corresponding microservice according to the read request path and mapping rules.
[0049] Figure 3 FIG. 1 is a schematic diagram of an architecture of a multi-cluster microservice access system based on Kubernetes according to an exemplary third embodiment of the present invention. Figure 3 As shown, the system of this embodiment includes:
[0050] The control cluster is used to deploy the microservice forwarding module, which forwards the user's microservice access request to the microservice of the corresponding subcluster;
[0051] The subcluster is used to deploy microservices and return response data corresponding to the standard microservice request to the user after receiving the standard microservice request.
[0052] In the multi-cluster microservice access system based on Kubernetes in this embodiment, the microservice forwarding module is used to load the Kubeconfig configuration file of each subcluster and expose the microservice access entrance of each subcluster; expose the IP and port to the user, receive the microservice access request sent by the user, and find the corresponding subcluster based on the identifiable request header in the microservice access request; read the corresponding Kubeconfig configuration file from the loaded Kubeconfig configuration file of each subcluster; read the request path in the microservice access request sent by the user, identify the corresponding microservice based on the read request path and mapping rules; and encapsulate the user's microservice access request into a standard microservice request that meets the access entrance standard of the identified microservice.
[0053] Secondly, the present invention provides a computer-readable storage medium having a computer program stored thereon. When the computer program is executed, the steps of the Kubernetes-based multi-cluster microservice access method of the present invention are performed.
[0054] Finally, the present invention also provides a computer device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the program, the steps of the Kubernetes-based multi-cluster microservice access method of the present invention are performed.
[0055] The above description is merely a specific embodiment of the present invention, but the scope of protection of the present invention is not limited thereto. Any changes or substitutions that can be easily conceived by a person skilled in the art within the technical scope disclosed in the present invention should be included in the scope of protection of the present invention. Therefore, the scope of protection of the present invention should be based on the scope of protection of the claims.
Claims
1. A multi-cluster microservice access method based on kubernetes, characterized in that: The method comprises: Step S1: Initialize the correspondence between the microservice forwarding module and the microservices of each sub-cluster; control the cluster to deploy the microservice forwarding module; Step S2: The microservice forwarding module identifies the corresponding microservice based on the microservice access request sent by the user; Step S3: The microservice forwarding module encapsulates the user's microservice access request into a standard microservice request that meets the access entry standard of the identified microservice; Step S4: After receiving the standard microservice request, the microservice in the subcluster returns the response data corresponding to the standard microservice request to the user; Step S1 includes: Load the Kubeconfig configuration files of each subcluster through the microservice forwarding module; Expose the IP and port of the microservice forwarding module to the outside world, and configure the mapping rules between the microservice forwarding module and the microservices of each sub-cluster; Expose the microservice access portal of each sub-cluster through the microservice forwarding module; Step S2 includes: Step S21: The user sends a microservice access request to the microservice forwarding module according to the IP and port exposed by the microservice forwarding module, where the microservice access request includes a recognizable request header; Step S22: The microservice forwarding module receives the microservice access request and finds the corresponding subcluster according to the identifiable request header in the microservice access request; Step S23: The microservice forwarding module reads the corresponding Kubeconfig configuration file from the loaded Kubeconfig configuration files of each sub-cluster; Step S24: The microservice forwarding module reads the request path in the microservice access request sent by the user, and identifies the corresponding microservice according to the read request path and mapping rules.
2. A multi-cluster microservice access system based on Kubernetes, characterized by: The system comprises: The control cluster is used to deploy the microservice forwarding module, which forwards the user's microservice access request to the microservice of the corresponding subcluster; The subcluster is used to deploy microservices and return response data corresponding to standard microservice requests to users after receiving them. The microservice forwarding module is used to load the Kubeconfig configuration files of each subcluster and expose the microservice access entrance of each subcluster; The microservice forwarding module is used to expose the IP and port to the user, receive the microservice access request sent by the user, find the corresponding subcluster according to the identifiable request header in the microservice access request; read the corresponding Kubeconfig configuration file from the loaded Kubeconfig configuration file of each subcluster; read the request path in the microservice access request sent by the user, and identify the corresponding microservice according to the read request path and mapping rules; The microservice forwarding module is used to encapsulate the user's microservice access request into a standard microservice request that meets the access entry standard of the identified microservice.
3. A computer-readable storage medium, characterized in that The computer-readable storage medium stores a computer program, and when the computer program is executed, the method according to claim 1 is performed.
4. A computer device, characterized in that: The computer device includes a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the program, the steps of the method according to claim 1 are implemented.
Citation Information
Patent Citations
Multi-cluster traffic forwarding method and device and electronic equipment
CN115086321A