A method, device, computer readable storage medium and computer program product for debugging an application in a local connected Kubernetes cluster
By modifying the Kubernetes cluster registration center and setting the gateway interface, the problem of local debugging of internal container services was solved, and direct debugging of external container applications was achieved, which improved development efficiency and convenience.
Patent Information
- Application Number
- CN202510088622.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-01-20
- Publication Date
- 2025-10-17
- Estimated Expiration
- 2045-01-20
AI Technical Summary
In a Kubernetes cluster, existing technologies make it difficult to effectively debug microservice applications inside containers in a local environment, especially because applications outside the container cannot directly access services inside the container, and existing solutions are complex or require additional software installation and exposure of authorization files.
By modifying the registry center of the Kubernetes cluster, both external and internal applications of the container can access the registry center, and setting up a gateway in the cluster to provide a gateway interface to debug applications outside the container, dynamically configure routing paths, and use the gateway interface to obtain access paths for applications inside the container.
This enables applications outside the container to directly debug services inside the container without installing additional software or exposing authorization files, improving development efficiency and convenience.
Smart Images

Figure CN119996148B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application belongs to the field of application debugging test, and particularly relates to a method and device for debugging an application in a local Kubernetes (K8s) cluster, a computer readable storage medium and a computer program product. BACKGROUND
[0002] With the development of micro-service technology and container technology, more and more running environments combine micro-service technology and container technology, and a single micro-service is put into a container to run, which not only isolates the system environment, but also saves a lot of system resources. In the prior art, Kubernetes (K8s) is a typical open source technology for managing containerized applications on multiple hosts in a cloud platform, and provides a running environment combining micro-service technology and container technology. Meanwhile, in the prior art, in order to adapt to this deployment mode, a large number of development tools are generated to support this running mechanism, including automatic build and release tools, automatic test tools and log monitoring tools, etc. After the user submits the code, the platform providing the development tools automatically builds the application and releases it to the container environment, and then the automatic test tools can be used to test the operation and maintenance function, and the log monitoring tools can be used to view the application logs in the entire cluster, and the link tools can be used to analyze the request call chain.
[0003] But in the actual operation, the application of the above running mechanism may need to be developed in some scenarios of local connection test environment debugging, in which case some problems will arise. Because normally, the application in the container environment will expose an entrance through the container network, and the exposure method may be various, such as using nodeport, hostnetwork, loadbalance, ingress, etc. The exposed service can be accessed from outside the container. However, for the internal service access of the container, it will not be accessed through the interface exposed outside the container. The access of the internal service of the container is more through directly accessing the ip port of the service or a set of services of the container, such as the ip port of the pod. In the case of using micro-service architecture, each application providing micro-service registers with the registration center, that is, joins 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 the other application. However, in the case of local debugging, that is, in the case of local connection test environment debugging, the locally started application cannot directly access the ip port of the pod because it is outside the container. At this time, a problem arises. When the micro-service application to be locally debugged can call the service running in the container to debug, the existing technology provides some solutions. One is to install a virtual private network (VPN) server as a pod in the container cluster, and expose the service through the port of the cluster. The local client connects through the virtual private network (VPN) client, so that the local has access to the network in the container, and can directly access the ip of the pod in the container. However, this solution requires the service and the local to install additional software and manage additional networks, which requires strict management of the development environment and is difficult to promote. The second solution is to use the proxy function of the command line tool kubectl of Kubernetes (K8s), such as kt-connect of Alibaba Cloud. However, this solution requires each developer to know the configuration file corresponding to each application in k8s, that is, the kubeconfig file, and also requires to expose additional authorization files to the user. This solution is complex and difficult to operate, and is also difficult to promote. SUMMARY
[0004] To solve the above problems, a method, device, computer readable storage medium and computer program product for locally connecting applications in a Kubernetes (K8s) cluster for debugging are proposed, aiming to provide a solution without installing additional software and exposing additional authorization files to each user. By using the gateway of the micro-service application, the local application can call the micro-service in the container, thereby realizing debugging.
[0005] In one aspect, a method for locally connecting applications in a Kubernetes (K8s) cluster for debugging is provided, comprising:
[0006] Modifying the registry center of the Kubernetes (K8s) cluster so that the applications outside and inside the container can access the registry center;
[0007] Setting a gateway in the container of the Kubernetes (K8s) cluster and providing an access interface of the gateway for application outside the container to call and access; the routing configuration in the gateway is configured to provide an access path of the application inside the container;
[0008] When locally debugging the application outside the container, the routing configuration provided by the gateway is obtained through the access interface of the gateway;
[0009] The access path of the application inside the container is obtained from the routing configuration, and then the application inside the container is called to realize the debugging of the application outside the container.
[0010] Further, the modification of the registry center of the Kubernetes (K8s) cluster so that the applications outside and inside the container can access the registry center comprises: configuring the registry center outside the container to enable the applications outside and inside the container to access the registry center; or,
[0011] The registry center is configured inside the container, and an access interface of the registry center is provided for the registration and access of the application.
[0012] Further, the provision of the access interface of the gateway comprises: the access interface provides the network IP address of the container and the access port of the application inside the container.
[0013] Further, the provision of the access interface of the gateway comprises: the routing configuration configured in the gateway is obtained through the access interface, and the routing configuration comprises the access path of the application inside the container required for debugging.
[0014] Further, the dynamic configuration of the routing configuration is realized by providing a configuration tool.
[0015] Further, the gateway provides a routing configuration for the container inside application, and the local debugging of the application outside the container is performed by obtaining the routing configuration through the access interface of the gateway.
[0016] Further, 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.
[0017] In another aspect, an apparatus for locally debugging an application in a Kubernetes (K8s) cluster is provided, comprising:
[0018] A modification module is configured to modify a registry center of a Kubernetes (K8s) cluster, so that the applications inside and outside the container can access the registry center.
[0019] A gateway module is configured to set a gateway in a container of the Kubernetes (K8s) cluster and provide an access interface of the gateway for the application outside the container to call and access.
[0020] A debugging module is configured to obtain a routing configuration of the gateway through the access interface of the gateway when performing local debugging of the application outside the container.
[0021] Further, the application inside the container is called by obtaining the access path of the application inside the container from the routing configuration, thereby achieving the debugging of the application outside the container.
[0022] In another aspect, a system for locally debugging an application in a Kubernetes (K8s) cluster is provided, comprising a processor and a memory, wherein the processor executes computer instructions stored in the memory to implement the above method.
[0023] In another aspect, a computer readable storage medium is provided, which stores computer instructions for causing a computer system to execute the above method.
[0024] The scheme provided by the present disclosure solves the deficiencies of the prior art and has the following beneficial effects:
[0025] By the technical solution provided above, the local application of the developer can be connected to other applications in the container in the test environment without installing additional software and exposing the k8s container authorization file to the developer, so that the application can be debugged locally during development, thereby effectively improving the development efficiency and facilitating promotion.
[0026] Other features and advantages of the present application will be set forth in the following description, and in part will become apparent to those skilled in the art upon examination of the following or can be learned by practice of the application. The objects and other advantages of the application can be realized and attained by the structure particularly pointed out in the written description and claims hereof as well as the appended drawings. BRIEF DESCRIPTION OF DRAWINGS
[0027] In order to more clearly illustrate the technical solutions in the embodiments of the present application or the prior art, the following will briefly introduce the drawings needed to be used in the embodiments or prior art description. Obviously, the drawings in the following description are some embodiments of the present application, and for those skilled in the art, other drawings can also be obtained without creative labor based on these drawings.
[0028] Figure 1 A method flow chart for locally connecting applications in a Kubernetes (K8s) cluster for debugging is shown according to an embodiment of the present application;
[0029] Figure 2 A device structure diagram for locally connecting applications in a Kubernetes (K8s) cluster for debugging is shown according to an embodiment of the present application;
[0030] Figure 3 A script language escaping system structure diagram based on a large language model is shown according to an embodiment of the present application;
[0031] Figure 4 A computer readable storage medium structure diagram is shown according to an embodiment of the present application;
[0032] Figure 5 A microservice client load balancing processing flow chart is shown according to an embodiment of the present application;
[0033] Figure 6 A microservice device module structure diagram is shown according to an embodiment of the present application. DETAILED DESCRIPTION
[0034] To make the objectives, technical solutions, and advantages of the embodiments of the present invention more clear, the technical solutions in the embodiments of the present invention will be clearly and completely described below in conjunction with the accompanying drawings in the embodiments of the present invention. Obviously, the described embodiments are only 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 making creative efforts shall fall within the scope of protection of the present invention.
[0035] Faced with the key issues in local development and debugging of applications in an operating environment that combines microservices and container technologies such as Kubernetes (K8s), that is, based on the inherent 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 rights to the applications it depends on, and 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 applications 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 local applications 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 ultimately implemented is to enable both applications within the container and local applications (i.e., applications outside the container) to access the registration center. In this way, the developed local applications can interact with the applications within the test environment container.
[0041] Second, a gateway is set in a container of the Kubernetes (K8s) cluster, and an access interface of the gateway is provided for an application outside the container to call and access; a routing configuration in the gateway is configured to provide an access path of an application inside the container;
[0042] In an embodiment, the gateway is set in the container, and the access interface of the gateway is exposed outside for an application outside the container to access the application service inside the container through the gateway.
[0043] In an embodiment, the gateway is set in the container because the gateway is needed to realize the access of the application service inside the container. Meanwhile, the gateway is needed to be exposed because the application outside the container also needs to access the gateway. There are various ways to expose the gateway, as long as the access to the gateway outside the container can be guaranteed.
[0044] In an embodiment, the final form of the exposed gateway is to provide an access function through the access interface of the gateway, and the parameter of the access function is the network IP address of the container and the access port of the application inside the container.
[0045] Third, when the local debugging of the application outside the container is performed, the routing configuration provided by the gateway is obtained through the access interface of the gateway.
[0046] In an embodiment, the gateway is configured with a routing configuration, and the routing configuration includes routing information. The routing configuration at least includes the information of the application service that needs to be exposed outside. For the service that is only used for the call inside the container, the service can not be added to the routing configuration of the gateway for exposure outside. If the local application needs to call a specific application inside the debugging test environment container, the access path of the specific application including the access port is dynamically configured in the routing configuration.
[0047] In an embodiment, for the debugging of the local application, the routing configuration configured in the gateway can be obtained through the access interface of the gateway, and the routing configuration includes the dynamically configured access path of the application inside the container that needs to be accessed for debugging.
[0048] In an embodiment, the dynamic configuration of the routing configuration is realized by providing a configuration tool.
[0049] Fourth, the access path of the application inside the container is obtained from the routing configuration, and then the application inside the container is called to realize the debugging of the application outside the container.
[0050] In one embodiment, the load balancing strategy of the client is modified, and the external information needed in the modification includes the gateway routing configuration information exposed by the gateway, including the network IP address and the access port of the application, and the information is obtained through the access interface of the gateway.
[0051] In one embodiment, 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. 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 are shown in the following table: Figure 5 For a springcloud microservice application, the client load balancing is modified, a new class CustomBlockingLoudBalanceClient is created, which inherits the BlockingLoudbalanceclient class in springcloud, and the class is annotated with @primary. In the class, NacosConfigManger is introduced to obtain the gateway routing configuration in nacos, the choose method and the reconstructURI method in the class are rewritten.
[0053] The choose(serviceId, request) method is modified as follows:
[0054] gatewayIP = "xx.xx.xx.xx" / / gateway exposed ip and port,
[0055] routeString = nacosConfigManger.getConfigService.getConfig("gateway-routers", "gateway", 5000) / / get the gateway corresponding routing configuration file.
[0056] jsonArray = JASONArray.parseArray(routeString) / / parse the configuration file into json Jsonobject = jsonArray.stream.filter(("lb: / / " + serviceId).equals(getString("url"))).get() / / get the routing configuration from the gateway routing configuration information, corresponding to the routing configuration, in the routing list, according to the corresponding service name demo-service in "uri":"lb: / / demo-service", find the routing configuration of the application service.
[0057] The routing configuration of the application service is parsed, the item with name being path in predicates is obtained, and then the value in args pattern in the item is taken out.
[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 of the identified interface.
[0061] The calling parameter of the interface function of the exposed access interface of the gateway, that is, the URL address composed of ip+port+pattern, is used as the instance information of the service load balancing. When the load balancing client calls, the URL address is directly used as the calling request, and the calling request is forwarded to the corresponding application by the gateway, so that the local application calls the container for service. Thus, the debugging and running of the local application are realized.
[0062] In one aspect, as shown in Figure 2 The embodiment of the disclosure provides a device for debugging an application in a local Kubernetes (K8s) cluster, which comprises:
[0063] A modification module is configured to modify a registration center of a Kubernetes (K8s) cluster, so that the applications outside and inside the container can access the registration center.
[0064] A gateway module is configured to set a gateway in a container of the Kubernetes (K8s) cluster and provide an access interface of the gateway for application calling and accessing outside the container. A routing configuration in the gateway is configured to provide an access path of the application inside the container.
[0065] A debugging module is configured to obtain a routing configuration provided by the gateway through the access interface of the gateway when performing local debugging of the application outside the container.
[0066] Further, an access path of the application in the container is obtained from the routing configuration, and the application in the container is invoked to realize the debugging of the application outside the container.
[0067] In one embodiment, as shown in Figure 6 the device structure specifically includes:
[0068] The local client performs corresponding debugging test operations through client load balancing.
[0069] The registration center is used for registering the cluster containers of various applications and is arranged outside the container.
[0070] The gateway is arranged inside the Kubernetes (K8s) cluster and is used for providing a gateway interface to realize external exposure, so that the application in the container can be accessed from outside the container through the gateway.
[0071] The test service application (test-service) and the demo service application (demo-service) are applications that provide specific services inside the Kubernetes (K8s) cluster container, for example, the container-internal application that needs to be invoked by the application debugging outside the container.
[0072] In one aspect, as shown in Figure 3 the disclosure provides a system for locally connecting to the application in the Kubernetes (K8s) cluster for debugging, which includes a processor and a memory, and the processor executes the computer instructions stored in the memory to realize the above-mentioned method for locally connecting to the application in the Kubernetes (K8s) cluster for debugging.
[0073] In one aspect, as shown in Figure 4 the disclosure provides a computer-readable storage medium 40, which stores non-transitory computer-readable instructions 41. When the non-transitory computer-readable instructions 41 are run by a processor, the method for locally connecting to the application in the Kubernetes (K8s) cluster for debugging of the above-mentioned embodiments of the disclosure is executed.
[0074] The above-mentioned disclosed embodiments have the following advantages:
[0075] Without installing additional software and without exposing the k8s container authorization file to the developer, the local application of the developer can be connected to the other application in the container in the test environment, so that the developer can debug the application locally.
[0076] In summary, the technical scheme of the present disclosure faces the key problem in local development and debugging of applications in the running environment of Kubernetes (K8s) which combines microservices and container technology, that is, based on the characteristics of microservices and containers, when developing and debugging, it is often not possible to simply run one application. The running of an application often depends on one or more application services inside the container. However, when debugging locally, if an application needs to be debugged, all the applications it depends on need to be run up, which is difficult in reality. First, running the application requires a large amount of resources, and the development local environment may not support it. Second, it does not have direct access to the applications it depends on, and it cannot run all the dependent applications to perform corresponding debugging. The provided solution can enable the local application of the developer to connect to the dependent other applications inside the container in the test environment without installing additional software and exposing the k8s container authorization file to the developer, thereby enabling the application to be debugged locally during development, effectively improving the development efficiency, and the convenience is conducive to promotion.
[0077] Although the present application has been described in detail with reference to the foregoing embodiments, it should be understood by those skilled in the art that the technical scheme recorded in the foregoing embodiments can still be modified, or some technical features can be replaced by equivalents; and these modifications or replacements do not make the essence of the corresponding technical scheme deviate from the spirit and scope of the technical scheme of the embodiments of the present application.
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. Setting a gateway in the container of the Kubernetes (K8s) cluster and providing an access interface of the gateway for application calls and access outside the container; The routing configuration in the gateway provides access paths for applications in the container; When performing local debugging of an application outside the container, obtaining the routing configuration provided by the gateway through the gateway's access interface; The access path of the application in the container is obtained from the routing configuration, and the application in the container is then called to implement debugging of the application outside the container.
2. The method according to claim 1, further comprising modifying the registry center of the Kubernetes (K8s) cluster so that applications outside and inside the container can access the registry center, comprising: The registration center is configured outside the container so that applications outside 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 for the gateway; 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 for the gateway; The routing configuration configured in the gateway is obtained through the access interface, where the routing configuration includes an access path of the application in the container that needs to be accessed for debugging in a dynamically configured manner. 5 . The method according to claim 4 , further comprising providing a configuration tool to implement dynamic configuration of the routing configuration.
6. The method according to claim 1, further comprising: obtaining the routing configuration provided by the gateway through the access interface of the gateway during local debugging of the application outside the container, comprising: 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 applications in a local Unicom Kubernetes (K8s) cluster, characterized by: A modification module is used to modify the registry of the Kubernetes (K8s) cluster so that applications outside and inside the container can access the registry. A gateway module is used to set up a gateway in the container of the Kubernetes (K8s) cluster and provide an access interface of the gateway for application calls outside the container; The routing configuration in the gateway provides access paths for applications in the container; a debugging module, configured to obtain the routing configuration provided by the gateway through the gateway's access interface 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 according to any one of claims 1 to 7.
Citation Information
Patent Citations
Local service debugging method and system based on micro-service architecture and containerization
CN116800761A
Remote debugging method and device based on Kubernetes environment, product and storage medium
CN118331864A