Method and device for debugging application in local communication Kubernetes cluster, computer readable storage medium and computer program product
By modifying the registry center of the Kubernetes cluster and setting up a gateway in the container, and dynamically configuring the routing configuration, the problem of inability to access the microservices in the container during local debugging is solved, and local debugging capabilities without additional software installation and authorization files are achieved, improving development efficiency.
Patent Information
- Application Number
- CN202510088622.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-01-20
- Publication Date
- 2025-05-13
- Estimated Expiration
- 2045-01-20
AI Technical Summary
When doing local debugging, developers cannot access microservices inside containers directly from outside the container, and existing solutions are complex and difficult to promote.
By modifying the registry of the Kubernetes cluster, applications outside the container and within the container can access the registry, and set up a gateway in the container to provide the gateway access interface, and dynamically configure routing configuration to realize debugging of applications outside the container.
Without installing additional software or exposing additional authorization files, developers can debug applications that rely on microservices in containers locally, improving development efficiency and simplifying processes.
Smart Images

Figure CN119996148A_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the field of application debugging and testing, and in particular relates to a method, device, computer-readable storage medium and computer program product for debugging an application in a local Unicom Kubernetes (K8s) cluster. Background Art
[0002] With the development of microservice technology and container technology, there are more and more operating environments that combine microservice and container technology. Putting a single microservice into a container to run, this operating mechanism not only isolates the system environment, but also saves a lot of system resources. In the prior art, Kubernetes (K8s) is an open source, used to manage containerized applications on multiple hosts in the cloud platform, and provides a typical operating environment that combines microservice and container technology; at the same time, in the prior art, in order to adapt to this deployment method, a large number of development tools have been generated to support this operating mechanism, including automatic build and release tools, automated testing tools, and log monitoring tools. After the user submits the code, the platform that provides the development tool automatically builds the application and publishes it to the container environment. After that, the automated testing tool can be used to test the operation and maintenance functions. At the same time, the log monitoring tool can be used to view the application logs in the entire cluster, and the link tool can be used to analyze the call chain of the request.
[0003] However, in actual operation, some scenarios of the application development of the above operation mechanism may need to be developed in a local connection test environment for debugging. In this case, some problems will arise. Because under normal circumstances, applications in a container environment will expose an entrance through the container's network. There may be many ways to expose, such as using nodeport, hostnetwork, loadbalance, ingress, etc. These exposed services can be accessed from outside the container. However, access to services inside the container will not be performed through the interface exposed outside the container. Access to services inside the container is more often achieved by directly accessing the IP port of a service or a set of services in the container, such as the IP port of a pod. In the case of using a microservice architecture, each application that provides microservices is registered with the registration center, that is, registered and added to a set of services, such as a pod. When an application accesses other applications, it obtains the IP port of the pod from the registration center, and then directly accesses the corresponding IP port in the container to access the corresponding service of other applications. However, in the case of local debugging, that is, debugging in a local connection test environment, the locally started application is outside the container. After obtaining the pod information in the container from the registration center, it cannot directly access the IP port corresponding to the pod. At this point, a problem arises. When a microservice application that needs to be debugged locally can call the service running in the container that it depends on for debugging, the existing technology provides some solutions. One is to install a virtual private network VPN server inside the container cluster as a pod, and expose the server through the cluster port. The local client connects through the virtual private network VPN, so that there will be a network connected to the container locally, and the IP of the pod in the container can be directly accessed. However, this solution is difficult to promote because additional software must be installed on the server and the local, and additional networks must be managed, corresponding to a development environment with strict management; the second is to use the proxy function of the Kubernetes (K8s) command line tool kubectl, such as Alibaba Cloud's kt-connect, but this solution requires each developer to know the configuration file corresponding to each application in k8s, that is, the kubeconfig file, and also requires additional authorization files to be exposed to users. This solution is more complicated and difficult to operate, and is also difficult to promote. Summary of the invention
[0004] In order to solve the above problems, a method, device, computer-readable storage medium and computer program product for debugging applications in a local Unicom Kubernetes (K8s) cluster are proposed, aiming to provide a solution without installing additional software or exposing additional authorization files to each user. Through the gateway of the microservice application, the local application can call the microservice in the container for debugging.
[0005] On the one hand, a method for debugging an application in a local Unicom Kubernetes (K8s) cluster is provided, including:
[0006] Modify the registry of the Kubernetes (K8s) cluster so that applications outside and inside the container can access the registry.
[0007] A gateway is set in the container of the Kubernetes (K8s) cluster, and an access interface of the gateway is provided for application calls and access outside the container; a routing configuration in the gateway is configured to provide an access path for the application in the container;
[0008] When performing local debugging of the application outside the container, obtaining the routing configuration provided by the gateway through the access interface of the gateway;
[0009] The access path of the application in the container is obtained from the routing configuration, and then the application in the container is called to implement debugging of the application outside the container.
[0010] Further, the modification of the registration center of the Kubernetes (K8s) cluster so that applications outside the container and inside the container can access the registration center includes: configuring the registration center outside the container so that applications outside the container and inside the container can access the registration center; or,
[0011] The registration center is configured inside the container, and an access interface of the registration center is provided for registration access of the application.
[0012] Further, providing the access interface of the gateway includes: the access interface provides a network IP address of the container and an access port of an application inside the container.
[0013] Further, providing the access interface of the gateway includes: obtaining a routing configuration configured in the gateway through the access interface, wherein the routing configuration includes an access path of the application in the container that needs to be accessed for dynamically configured debugging.
[0014] Furthermore, the dynamic configuration of the routing configuration is achieved by providing a configuration tool.
[0015] Furthermore, when performing local debugging of the application outside the container, obtaining the routing configuration provided by the gateway through the access interface of the gateway includes: modifying the load balancing policy of the client; creating a new class and rewriting the function of the new class to call the interface function provided by the access interface of the gateway to obtain the routing configuration provided by the gateway.
[0016] Furthermore, the interface function provides a URL parameter for obtaining the network IP address of the container and the access port information of the internal application of the container in a URL format.
[0017] On the other hand, a device for debugging an application in a local Unicom Kubernetes (K8s) cluster is provided, comprising:
[0018] A modification module is used to modify the registry center of the Kubernetes (K8s) cluster so that applications outside and inside the container can access the registry center;
[0019] A gateway module is used to set a gateway in the container of the Kubernetes (K8s) cluster and provide an access interface of the gateway for application calls and access outside the container; a routing configuration in the gateway is used to configure and provide an access path for applications in the container;
[0020] A debugging module, used to obtain the routing configuration provided by the gateway through the access interface of the gateway when performing local debugging of the application outside the container;
[0021] It is also used to obtain the access path of the application in the container from the routing configuration, and then call the application in the container to implement debugging of the application outside the container.
[0022] On the other hand, a local Unicom Kubernetes (K8s) cluster application debugging system is provided, the system includes a processor and a memory, the processor executes computer instructions stored in the memory to implement the above method.
[0023] On the other hand, a computer-readable storage medium is provided, wherein the computer-readable storage medium stores computer instructions, and the computer instructions are used to enable a computer system to execute the above method.
[0024] The solution provided by the present disclosure solves the deficiencies of the prior art and has the following beneficial effects:
[0025] Through the technical solution provided above, without installing additional software or exposing the k8s container authorization file to developers, the developer's local application can be connected to other dependent applications in the container in the test environment, so that the application can be debugged locally during application development. This effectively improves development efficiency and is convenient for promotion.
[0026] Other features and advantages of the present invention will be described in the following description, and partly become apparent from the description, or understood by practicing the present invention. The purpose and other advantages of the present invention can be realized and obtained by the structures pointed out in the description, claims and drawings. BRIEF DESCRIPTION OF THE DRAWINGS
[0027] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings described below are some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0028] Figure 1 A flow chart of a method for debugging an application in a local Unicom Kubernetes (K8s) cluster according to an embodiment of the present invention is shown;
[0029] Figure 2 A structural diagram of a device for debugging an application in a local Unicom Kubernetes (K8s) cluster according to an embodiment of the present invention is shown;
[0030] Figure 3 A structural diagram of a script language escape system based on a large language model according to an embodiment of the present invention is shown;
[0031] Figure 4 A computer-readable storage medium structure diagram according to an embodiment of the present invention is shown;
[0032] Figure 5 A microservice client load balancing process flow chart of an embodiment of the present invention is shown;
[0033] Figure 6 A module structure diagram of a microservice device according to an embodiment of the present disclosure is shown. DETAILED DESCRIPTION
[0034] In order to make the purpose, technical solution and advantages of the embodiments of the present invention clearer, the technical solution in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0035] Faced with the key issues in local development and debugging of applications in the operating environment of Kubernetes (K8s) that combines microservices and container technologies, that is, based on the proper characteristics of microservices and containers, when developing and debugging, it is often not possible to simply run only one application. The operation of an application often depends on one or more application services inside the container. However, when debugging locally, if you want to debug an application, you need to run all the applications it depends on. In reality, there are certain difficulties. First, running an application requires a lot of resources, which may not be supported by the local development environment. Second, you do not have direct access to the applications it depends on, and you cannot run all the applications it depends on for corresponding debugging. The present disclosure provides the following technical solutions.
[0036] On the one hand, if Figure 1 As shown, a method for debugging an application in a local Unicom Kubernetes (K8s) cluster is provided, including:
[0037] First, modify the registry of the Kubernetes (K8s) cluster so that applications outside and inside the container can access the registry.
[0038] In one embodiment, since the overall architecture of the Kubernetes (K8s) cluster is a microservice architecture, both local applications and applications in cluster containers need to access the registration center to obtain corresponding configurations, register application information with the registration center, and register their own instances with the applications.
[0039] In one embodiment, the registration center is configured outside the container so that a local application can directly access the registration center to implement the configuration.
[0040] In one embodiment, the registration center is configured inside the container and exposed through corresponding means, such as providing an access interface or an access template. The interface or template to be finally implemented is to enable both the application in the container and the local application (i.e., the application outside the container) to access the registration center, so that the developed local application can interact with the application in the test environment container for information.
[0041] Second, a gateway is set in the container of the Kubernetes (K8s) cluster, and an access interface of the gateway is provided for application calls and access outside the container; the routing configuration in the gateway configures the access path provided for the application in the container;
[0042] In one embodiment, the gateway is disposed in the container, and an access interface of the gateway is exposed externally, so as to access the application service in the container through the gateway from outside the container.
[0043] In one embodiment, the gateway is deployed in the container because the gateway is needed to access the application services in the container. At the same time, the gateway acts as an access intermediary for the application services, and the applications outside the container also need to access the gateway, so the gateway needs to be exposed. There are many ways to expose the gateway, as long as it can be accessed outside the container.
[0044] In one embodiment, the final form in which the gateway is exposed is to provide an access function through the gateway's access interface, and the parameters of the access function are the network IP address of the container and the access port of the application inside the container.
[0045] Third, when performing local debugging of the application outside the container, the routing configuration provided by the gateway is obtained through the access interface of the gateway;
[0046] In one embodiment, the gateway is configured with a routing configuration, and the routing configuration includes routing information. The routing configuration at least configures information of application services that need to be exposed externally. For services that are only used for invocation within the container, they may not be added to the routing configuration of the gateway for external exposure. If a local application needs to call a specific application in the debugging test environment container, the access path including the access port of the specific application is dynamically configured in the routing configuration.
[0047] In one embodiment, for debugging of local applications, the routing configuration configured in the gateway can be obtained through the access interface of the gateway, and the routing configuration includes an access path of the application in the container that needs to be accessed by the dynamically configured debugging.
[0048] In one embodiment, the dynamic configuration of the routing configuration is achieved by providing a configuration tool.
[0049] Fourth, the access path of the application in the container is obtained from the routing configuration, and then the application in the container is called to implement debugging of the application outside the container.
[0050] In one embodiment, the load balancing policy of the client is modified. The external information required for the modification includes the routing configuration information of the gateway exposed by the gateway including the network IP address and the access port of the application. The information is obtained through the access interface of the gateway.
[0051] In one embodiment, a new class is created and a function of the new class is rewritten to call an interface function provided by the access interface of the gateway to obtain the routing configuration provided by the gateway. The interface function provides a URL parameter to obtain the network IP address of the container in URL format and the access port information of the internal application of the container.
[0052] Specific examples, such as Figure 5 As shown, for the springcloud microservice application, modify the client load balancing, create a new class CustomBlockingLoudBalanceClient, inherit the BlockingLoudbalanceclient class in springcloud, and add the @primary annotation to the class, introduce NacosConfigManger into the class to obtain the gateway routing configuration in nacos, rewrite the choose method and reconstructURI method in the class;
[0053] Modify the choose(serviceId,request) method.
[0054] gatewayIP = "xx.xx.xx.xx" / / The IP and port exposed by the gateway,
[0055] routeString = nacosConfigManger.getConfigService.getConfig("gateway-routers","gateway",5000) / / Get the routing configuration file corresponding to the gateway.
[0056] jsonArray = JASONArray.parseArray (routeString) / / Parse the configuration file into jsonJsonobject = jsonArray.stream.filter (("lb: / / " + serviceId).equals (getString ("url")).get (); / / Get the routing configuration from the routing configuration information of the gateway. In the routing list, find the routing configuration corresponding to the application service according to the corresponding service name demo-service in "uri": "lb: / / demo-service".
[0057] Parse the route configuration of the application service, obtain the item whose name is path in predicates, and then extract the value in argspatter in the item.
[0058] jsonObjectPath=jsonObject.getJSONArray("predicates").stream.filter("Path".equals(getString("name")));
[0059] pattern=jsonObjectPath.getJSONObject("args").getString("pattern");
[0060] patternNew = pattern.subString(0, pattern.lastIndexOf(" / v") / / Remove the path information that identifies the interface.
[0061] The calling parameters of the interface function of the access interface exposed by the gateway, i.e., the URL address composed of ip+port+patter, are used as the instance information of the load balancing service. When the load balancing client calls, it will directly use the URL address plus the interface path behind it as the calling request. After the calling request is sent to the gateway, it is forwarded to the corresponding application by the gateway, thereby realizing the calling of the service in the container by the local application. In this way, the debugging and running of the local application is realized.
[0062] On the one hand, if Figure 2 As shown, the embodiment of the present disclosure provides a device for debugging an application in a local Unicom Kubernetes (K8s) cluster, including:
[0063] A modification module is used to modify the registry center of the Kubernetes (K8s) cluster so that applications outside and inside the container can access the registry center;
[0064] A gateway module is used to set a gateway in the container of the Kubernetes (K8s) cluster and provide an access interface of the gateway for application calls and access outside the container; a routing configuration in the gateway is used to configure and provide an access path for applications in the container;
[0065] A debugging module, used to obtain the routing configuration provided by the gateway through the access interface of the gateway when performing local debugging of the application outside the container;
[0066] It is also used to obtain the access path of the application in the container from the routing configuration, and then call the application in the container to implement debugging of the application outside the container.
[0067] In one embodiment, Figure 6 As shown, the device structure specifically includes:
[0068] The local client performs corresponding debugging and testing operations through client load balancing;
[0069] A registration center, used for cluster container registration of each application, and arranged outside the container;
[0070] Gateway, which is set inside the Kubernetes (K8s) cluster and is used to provide a gateway interface for external exposure. Applications in the container can be accessed through the gateway from outside the container.
[0071] Test service applications (test-service) and demonstration service applications (demo-service) are applications that provide specific services inside the Kubernetes (K8s) cluster container, such as the container internal application that needs to be called for debugging the application outside the container.
[0072] On the one hand, if Figure 3 As shown, an embodiment of the present disclosure provides a system for debugging an application in a local Unicom Kubernetes (K8s) cluster, the system comprising a processor and a memory, the processor executing computer instructions stored in the memory to implement the above-mentioned method for debugging an application in a local Unicom Kubernetes (K8s) cluster.
[0073] On the one hand, if Figure 4 As shown, an embodiment of the present disclosure provides a computer-readable storage medium 40 on which non-transitory computer-readable instructions 41 are stored. When the non-transitory computer-readable instructions 41 are executed by a processor, a method for debugging an application in a local Unicom Kubernetes (K8s) cluster according to the aforementioned embodiments of the present disclosure is executed.
[0074] The following advantages are achieved through the above disclosed embodiments:
[0075] Without installing additional software or exposing the k8s container authorization file to developers, developers' local applications can be connected to other applications they depend on in the container in the test environment, so that developers can debug the application locally.
[0076] In summary, the disclosed technical solution faces the key issues in the local development and debugging of applications in the operating environment of Kubernetes (K8s), which is a combination of microservices and container technologies. That is, based on the due characteristics of microservices and containers, when developing and debugging, it is often not possible to simply run only one application. The operation of an application often depends on one or more application services inside the container. However, when debugging locally, if you want to debug an application, you need to run all the applications it depends on. In reality, there are certain difficulties. First, running the application requires a large amount of resources, and the local development environment may not support it. Second, it does not have direct access rights to the applications it depends on, and it is impossible to run all the applications it depends on for corresponding debugging. The solution provided can enable the developer's local application to connect to other applications that are dependent on the container in the test environment without installing additional software or exposing the k8s container authorization file to the developer, so that the application can be debugged locally during application development, effectively improving the development efficiency, and the convenience it has is conducive to promotion.
[0077] Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent substitutions for some of the technical features therein; and these modifications or substitutions do not make the essence of the corresponding technical solutions deviate from the spirit and scope of the technical solutions of the embodiments of the present invention.
Claims
1. A method for debugging an application in a local Unicom Kubernetes (K8s) cluster, characterized by: Modify the registry of the Kubernetes (K8s) cluster so that applications outside and inside the container can access the registry. A gateway is set in the container of the Kubernetes (K8s) cluster, and an access interface of the gateway is provided for application calls and access outside the container; The routing configuration in the gateway provides an access path for the application in the container; When performing local debugging of the application outside the container, obtaining the routing configuration provided by the gateway through the access interface of the gateway; The access path of the application in the container is obtained from the routing configuration, and then the application in the container is called to implement debugging of the application outside the container.
2. According to the method of claim 1, further, modifying the registration center of the Kubernetes (K8s) cluster so that applications outside and inside the container can access the registration center includes: The registration center is configured outside the container so that applications outside the container and inside the container can access the registration center; or, The registration center is configured inside the container, and an access interface of the registration center is provided for registration access of the application.
3. The method according to claim 1, further comprising providing an access interface of the gateway comprising: The access interface provides the network IP address of the container and the access port of the application inside the container.
4. The method according to claim 1, further comprising providing an access interface of the gateway comprising: The routing configuration configured in the gateway is obtained through the access interface, wherein the routing configuration includes an access path of the application in the container that needs to be accessed by the dynamically configured debugging.
5. The method according to claim 4, further comprising providing a configuration tool to implement dynamic configuration of the routing configuration.
6. According to the method of claim 1, further, when performing local debugging of the application outside the container, obtaining the routing configuration provided by the gateway through the access interface of the gateway comprises: Modify the client's load balancing strategy; A new class is created and the function of the new class is rewritten to call the interface function provided by the access interface of the gateway to obtain the routing configuration provided by the gateway.
7. The method according to claim 6, wherein the interface function provides a URL parameter to obtain the network IP address of the container and the access port information of the internal application of the container in a URL format.
8. A device for debugging an application in a local Unicom Kubernetes (K8s) cluster, characterized by: A modification module is used to modify the registry center of the Kubernetes (K8s) cluster so that applications outside and inside the container can access the registry center; A gateway module is used to set a gateway in the container of the Kubernetes (K8s) cluster and provide an access interface of the gateway for application calls and access outside the container; The routing configuration in the gateway provides an access path for the application in the container; A debugging module, used to obtain the routing configuration provided by the gateway through the access interface of the gateway when performing local debugging of the application outside the container; It is also used to obtain the access path of the application in the container from the routing configuration, and then call the application in the container to implement debugging of the application outside the container.
9. A system for debugging applications in a local Unicom Kubernetes (K8s) cluster, the system comprising a processor and a memory, the processor executing computer instructions stored in the memory to implement any of the methods of claims 1-7.
10. A computer-readable storage medium storing computer instructions for causing a computer system to execute the method of any one of claims 1 to 7.
Citation Information
Patent Citations
Micro-service debugging method and device, electronic equipment and readable storage medium
CN115599669A
Application program automatic deployment method and system based on cloud native
CN116755794A
Local service debugging method and system based on micro-service architecture and containerization
CN116800761A
Device for locally debugging Kubernetes container
CN117648158A
Remote debugging method and device based on Kubernetes environment, product and storage medium
CN118331864A