Container service access method, system, storage medium and electronic device

CN114500537BActive Publication Date: 2024-11-01TONGDUN NETWORK TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202210301393.4
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-03-24
Publication Date
2024-11-01
Estimated Expiration
2042-03-24

AI Technical Summary

Technical Problem

[0004]本发明的主要目的在于提供一种容器服务的访问方法及系统,以解决现有kubernetes集群容器服务对外暴露技术操作复杂繁琐、维护成本较高的问题

Benefits of technology

[0037]在本发明实施例提供的容器服务的访问方法中,只需要将nginx容器自身的服务对kubernetes集群外部进行暴露,用户通过第一url地址访问nginx容器,进而通过nginx容器转发访问请求到第二url地址,实现访问容器上服务的目的,访问过程操作简单,业务变化时只需要修改业务对应的容器和服务,不需要维护ingress资源,降低了维护成本,解决了现有kubernetes集群容器服务对外暴露技术操作复杂繁琐、维护成本较高的问题。

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114500537B_ABST
    Figure CN114500537B_ABST
Patent Text Reader

Abstract

The present invention discloses a method, system, storage medium and electronic device for accessing container services, wherein the method comprises: creating an nginx container, and exposing the nginx container to the outside of a kubernetes cluster through the IP address and port of a physical machine; configuring the nginx container, and receiving a first URL address requested by a user through the configured nginx container; parsing and reorganizing the first URL address to obtain a second URL address; forwarding the user request to the second URL address through the nginx container, so as to forward the external traffic of the kubernetes cluster to the inside of the cluster. The present invention only needs to expose the service of the nginx container itself to the outside of the kubernetes cluster, and the user accesses the nginx container through the first URL address, and then forwards the access request to the second URL address through the nginx container, so as to achieve the purpose of accessing the service on the container, and the access process is simple to operate. When the business changes, only the container and service corresponding to the business need to be modified, and there is no need to maintain the ingress resources, thereby reducing the maintenance cost.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of container technology, and in particular to a container service access method, system, storage medium and electronic device. Background Art

[0002] When users access services provided by Kubernetes cluster containers, they may be unable to access the services because the container address is unreachable outside the Kubernetes cluster or even the service address is unreachable. Therefore, it is often necessary to expose the Kubernetes cluster container service to the outside world so that it can be accessed from outside the cluster.

[0003] However, the technologies commonly used by Kubernetes to expose container services are too heavy to use, complicated and cumbersome to operate, and have high maintenance costs. Taking the nginx ingress controller technology as an example, the ingress backend depends on the service, and different domain names are routed to different backend services. If you add a service when adding an app, you also need to modify the original ingress or add a new ingress to process it before you can access the container service, which is cumbersome. In addition, you also need to maintain the ingress resources while maintaining the service, which has a high maintenance cost. Summary of the invention

[0004] The main purpose of the present invention is to provide a container service access method and system to solve the problem that the existing Kubernetes cluster container service external exposure technology operation is complicated and cumbersome and the maintenance cost is high.

[0005] In order to achieve the above object, a first aspect of the present invention provides a method for accessing a container service, comprising:

[0006] Create an nginx container and expose it to the outside of the kubernetes cluster through the IP address and port of the physical machine;

[0007] The nginx container is configured, and a first URL address requested by a user to be accessed is received through the configured nginx container, wherein the first URL address includes the IP address and port of the physical machine;

[0008] Parse and reorganize the first URL address to obtain a second URL address;

[0009] The user request is forwarded to the second URL address through the nginx container to forward the external traffic of the kubernetes cluster to the inside of the cluster.

[0010] Optionally, exposing the nginx container to the outside of the kubernetes cluster through the IP address and port of the physical machine includes:

[0011] Use the nginx container as the entrance of external traffic of the kubernetes cluster, and use nodeport to expose the nginx container to the outside of the kubernetes cluster through the IP address and port of the physical machine;

[0012] Receive a user's access request to the nginx container through the nodeport.

[0013] Optionally, configuring the nginx container includes:

[0014] The location instruction is configured to match the first URL address requested by the user;

[0015] Configure the resolver to the cluster DNS server address so that when the user requests to access the domain name of the service, the domain name resolution is performed to obtain the IP address of the service;

[0016] The proxy forwarding is configured to obtain the IP address and port number of the reverse proxy to forward the user request to the second URL address obtained by recombining the IP address and port number of the reverse proxy.

[0017] Optionally, parsing and reorganizing the first URL address to obtain a second URL address includes:

[0018] Parse the IP address variable and the port number variable in the first URL address to obtain the IP address and port number of the reverse proxy;

[0019] The IP address and port number of the reverse proxy are concatenated to obtain a second URL address.

[0020] Optionally, forwarding the user request to the second URL address through the nginx container includes:

[0021] Determine the address type of the second URL address;

[0022] If the address type of the second URL address is the IP address of the service, the user request is forwarded to the service, and all containers under the service perform load balancing on the user request to achieve access to the container service;

[0023] If the address type of the second URL address is the IP address of the container, the user request is forwarded to the container to access the container service.

[0024] Furthermore, if the address type of the second URL address is a domain name of a service, then:

[0025] Use the resolver to resolve the domain name and resolve the service's IP address based on the service's domain name;

[0026] The user request is forwarded to the service, and all containers under the service perform load balancing on the user request to achieve access to the container service.

[0027] Optionally, the method further comprises:

[0028] The container corresponding to the second URL address obtains a request result according to the user request;

[0029] The request result is returned to the user.

[0030] A second aspect of the present invention provides a container service access system, including:

[0031] An external exposure unit, used to create an nginx container and expose the nginx container to the outside of the kubernetes cluster through the IP address and port of the physical machine;

[0032] A configuration unit, configured to configure the nginx container, and receive a first URL address requested by a user through the configured nginx container, wherein the first URL address includes an IP address and a port of the physical machine;

[0033] A recombining unit, used for parsing and recombining the first URL address to obtain a second URL address;

[0034] The forwarding unit is used to forward the user request to the second URL address through the nginx container to forward the external traffic of the kubernetes cluster to the inside of the cluster.

[0035] A third aspect of the present invention provides a computer-readable storage medium, wherein the computer-readable storage medium stores computer instructions, and the computer instructions are used to enable a computer to execute the container service access method provided by any one of the first aspects.

[0036] A fourth aspect of the present invention provides an electronic device, comprising: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores a computer program executable by the at least one processor, and the computer program is executed by the at least one processor so that the at least one processor executes the container service access method provided in any one of the first aspects.

[0037] In the container service access method provided in the embodiment of the present invention, it is only necessary to expose the service of the nginx container itself to the outside of the kubernetes cluster. The user accesses the nginx container through the first URL address, and then forwards the access request to the second URL address through the nginx container to achieve the purpose of accessing the service on the container. The access process is simple to operate. When the business changes, it is only necessary to modify the container and service corresponding to the business. There is no need to maintain ingress resources, which reduces the maintenance cost and solves the problem that the existing kubernetes cluster container service external exposure technology is complex and cumbersome and has high maintenance cost. BRIEF DESCRIPTION OF THE DRAWINGS

[0038] In order to more clearly illustrate the specific implementation methods of the present invention or the technical solutions in the prior art, the drawings required for use in the specific implementation methods or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some implementation methods of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.

[0039] Figure 1 A schematic diagram of a method for accessing a container service provided by an embodiment of the present invention;

[0040] Figure 2 A schematic diagram of the nodeport mode in the existing container service external exposure technology;

[0041] Figure 3 A schematic diagram of an IP address for a user to access a service provided by an embodiment of the present invention;

[0042] Figure 4 This is a schematic diagram of the loadbalancer mode in the existing container service external exposure technology;

[0043] Figure 5 A schematic diagram of the ingress mode in the existing container service external exposure technology;

[0044] Figure 6 A schematic diagram of a method for accessing a container service provided by an embodiment of the present invention;

[0045] Figure 7 A block diagram of an access system for container services provided by an embodiment of the present invention;

[0046] Figure 8 A block diagram of an electronic device provided in an embodiment of the present invention. DETAILED DESCRIPTION

[0047] In order to enable those skilled in the art to better understand the scheme of the present invention, the technical scheme 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 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 creative work should fall within the scope of protection of the present invention.

[0048] It should be noted that the terms "first", "second", etc. in the specification and claims of the present invention and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchanged where appropriate, so as to describe the embodiments of the present invention described herein. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device that includes a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.

[0049] It should be noted that, in the absence of conflict, the embodiments of the present invention and the features in the embodiments can be combined with each other. The present invention will be described in detail below with reference to the accompanying drawings and in combination with the embodiments.

[0050] When users access services provided by Kubernetes cluster containers, they may be unable to access the services because the container address is unreachable outside the Kubernetes cluster or even the service address is unreachable. Therefore, it is often necessary to expose the Kubernetes cluster container service to the outside world so that it can be accessed from outside the cluster.

[0051] In order to solve the above problems, an embodiment of the present invention provides a container service access method applicable to a kubernetes cluster, such as Figure 1 As shown, the method includes the following steps S101 to S104:

[0052] Step S101: Create an nginx container, and expose the nginx container to the outside of the kubernetes cluster through the IP address and port of the physical machine;

[0053] Among them, the kubernetes cluster is an open source platform for managing containers, referred to as k8s; pod is the smallest unit of k8s scheduling, which can be simply understood as a container. If you want to create or delete containers on different physical servers, you need to operate pod;

[0054] Expose the nginx container through the IP address and port of the physical machine, so that the traffic outside the cluster can be forwarded to the inside of the cluster through the nginx container; for example, the IP address of the physical machine can be 192.168.0.2 or 192.168.0.3, and the port can be 38080 or 38081.

[0055] Specifically, the step S101 of exposing the nginx container to the outside of the kubernetes cluster through the IP address and port of the physical machine includes:

[0056] Use the nginx container as the entrance of the external traffic of the kubernetes cluster, and use nodeport to expose the nginx container to the outside of the kubernetes cluster through the IP address and port of the physical machine; nodeport is node access, which means opening a static port on the IP of each node and exposing the service to the outside through the static port. Expose the nginx container to the outside through 192.168.0.2:38080, 192.168.0.2:38081, 192.168.0.3:38080 or 192.168.0.3:38081.

[0057] Receive the user's access request to the nginx container through the nodeport. The user request is regarded as the external traffic of the kubernetes cluster, from the port of the node to the nginx container, and then forwarded to the cluster through the nginx container.

[0058] Node (node ​​or physical machine): server, the carrier that runs the container. K8s will create a container on the physical machine; nodeport: access the container by accessing the port on the physical machine.

[0059] The common ways to expose container services in Kubernetes clusters include: nodeport mode, loadbalancer mode, and ingress mode. Figure 2 As shown: the solid line is the traffic outside the cluster, and the dotted line is the traffic inside the cluster;

[0060] Assume that there are two physical machines with addresses 192.168.0.2 and 192.168.0.3, on which two containers of applications app1 and app2 are running. The nodes (physical machines) in the cluster are connected to the containers. When a service of type nodeport with port 38080 is created for app1, port 38080 will be listened on all nodes in the entire cluster. Similarly, when a service of type nodeport with port 38081 is created for app2, port 38081 of each node will be occupied. Therefore, when the task of exposing the container service to the outside world is completed, the user can access the physical machine address 192.168.0.2:38080 or 192.68.0.3:38080 and reach the container through the network policy on the physical machine.

[0061] However, since the number of ports that each system can listen to is limited, the corresponding nodeport type services are also limited. The existing nodeport mode will occupy many machine ports, which is prone to port conflicts. In the nodeport mode, each application will occupy a host port, and each service needs to be forwarded through a port on the cluster host. Each additional service forwarding will occupy an additional host port. When there are many applications, many host ports will be occupied, and there is an upper limit on the ports.

[0062] Compared with the existing nodeport mode, the embodiment of the present invention does not need to configure a nodeport for each service, only one entry is needed, and only the port exposed by the nginx container is needed, which will not occupy a large number of host ports and will not cause port conflicts;

[0063] Furthermore, when modifying or adding services in the embodiment of the present invention, only the service and pod need to be changed accordingly, which has no impact on the nodeport port, does not require additional port numbers, and does not require occupying too many ports on the cluster host.

[0064] Step S102: configuring the nginx container, and receiving a first URL address requested by a user through the configured nginx container, wherein the first URL address includes the IP address and port of the physical machine;

[0065] Specifically, configuring the nginx container in step S102 includes:

[0066] The location instruction is configured to match the first URL address requested by the user;

[0067] Configure the resolver to the cluster DNS server address so that when the user requests to access the domain name of the service, the domain name resolution is performed to obtain the IP address of the service;

[0068] The proxy forwarding is configured to obtain the IP address and port number of the reverse proxy to forward the user request to the second URL address obtained by recombining the IP address and port number of the reverse proxy.

[0069] The embodiment of the present invention needs to create an nginx container with a correct configuration file. The configuration file needs to parse the variables in the url to complete the splicing and forwarding to the real backend. The nginx container serves as a springboard for the external cluster to access the internal cluster and forwards the external cluster traffic to the internal cluster.

[0070] For example, you can configure the nginx container as follows:

[0071] location / send{

[0072] resolver 10.246.0.2;

[0073] proxy_pass http: / / $arg_host:$arg_port / ;

[0074] }

[0075] Among them, location / send means that the location instruction matches the access request with the prefix send, and forwards it after matching send in the URL;

[0076] resolver 10.246.0.2, which indicates the resolver, used for domain name resolution, where 10.246.0.2 is the cluster dnsserver (dns server) address;

[0077] proxy_pass http: / / $arg_host:$arg_port / indicates proxy forwarding, which is used to forward to the specific address of the backend. It configures the IP address and port number of the reverse proxy. The URL address needs to be added with http: / / or https: / / ; $arg_host indicates the variable for obtaining the host in the URL, and $arg_port indicates the variable for obtaining the port in the URL.

[0078] Step S103: parsing and reorganizing the first URL address to obtain a second URL address; dynamically parsing variables in the first URL address, splicing and reorganizing into the second URL address;

[0079] Specifically, the step S103 includes:

[0080] Parse the IP address variable and the port number variable in the first URL address to obtain the IP address and port number of the reverse proxy;

[0081] The reverse proxy IP address and port number are concatenated to obtain a second URL address. The user request can be further forwarded to the second URL address within the cluster by parsing and concatenating the first URL address requested by the user to obtain the real second URL address of the backend.

[0082] Step S104: forward the user request to the second URL address through the nginx container to forward the external traffic of the kubernetes cluster to the inside of the cluster.

[0083] Specifically, forwarding the user request to the second URL address through the nginx container in step S104 includes:

[0084] Determine the address type of the second URL address;

[0085] If the address type of the second URL address is the IP address of the service, the user request is forwarded to the service, and all containers under the service perform load balancing on the user request to achieve access to the container service;

[0086] If the address type of the second URL address is the IP address of the container, the user request is forwarded to the container to access the container service.

[0087] In an embodiment of the present invention, the nginx service is exposed to the outside of the cluster. Nginx is used as a traffic entrance to obtain variable parameters of the URL. The nginx container is used to dynamically parse the variable parameters in the request, and the variable parameters are spliced ​​and reassembled into a new URL. The external traffic is forwarded to the spliced ​​new URL address to achieve the purpose of accessing the service on the container.

[0088] Among them, service: a group of container applications with the same functions provide a unified entry address and distribute the request load to each container application on the backend.

[0089] The schematic diagram of the IP address of the user accessing the service provided by the embodiment of the present invention is as follows Figure 3As shown in the figure, there are two services with IP addresses of 172.21.10.40:80 and 172.21.10.41:80. When a user accesses 172.21.10.40:80, it is equivalent to accessing the services provided by the 10.10.10.10:8080 container and the 10.10.10.20:8080 container, which is equivalent to the load balancing of the two containers 10.10.10.10:8080 and 10.10.10.20:8080. When a user accesses 172.21.10.41:80, it is equivalent to accessing the service provided by the 10.10.10.30:8080 container.

[0090] For example, the first URL address can be http: / / 192.168.0.2:30080 / send?host=172.21.10.40\&port=80. When a user accesses the first URL address, nginx parses and reorganizes the parameters of the host and port (IP address and port number) according to the established configuration and rules to form a new URL second URL address http: / / 172.21.10.40:80. Then the nginx container initiates a request to the second URL address (the address of the service) http: / / 172.21.10.40:80 and returns the final result of the request to the user; service is the load balancing of the following group of containers. When a user accesses service (172.21.10.40:80), it is equivalent to accessing two containers (10.10.10.10:8080 and 10.10.10.20:8080).

[0091] The user can also directly access the container through the present invention. In this case, the first URL address can be http: / / 192.168.0.3:30080 / send?host=10.10.10.10\&port=8080 When the user accesses the first URL address, the nginx container resolves it to a new URL, the second URL address is http: / / 10.10.10.10:8080, and completes the forwarding;

[0092] Users can also access the first url address http: / / 192.168.0.3:30080 / send?host= 10.10.10.20\&port=8080 , the nginx container resolves the new URL to the second URL address http: / / 10.10.10.20:8080 (the container's address) and completes the forwarding.

[0093] The user needs to determine the service address or container address based on the preset configuration or rules. If the user accesses the service address, k8s will do the load balancing; if the user accesses two container addresses, the user application will do the load balancing.

[0094] Furthermore, if the address type of the second URL address is a domain name of a service, then:

[0095] Use the resolver to resolve the domain name and resolve the service's IP address based on the service's domain name;

[0096] The user request is forwarded to the service, and all containers under the service perform load balancing on the user request to achieve access to the container service.

[0097] If the address type of the second URL address is the domain name of the service, the domain name is first resolved using the resolver when configuring the nginx container to obtain the IP address of the service, and then the user request is forwarded to the service according to the IP address of the service. All containers under the service load balance the user request to achieve access to the container service.

[0098] In the embodiment of the present invention, the nginx service is exposed to the outside of the cluster. Nginx is used as a traffic entry to obtain and parse the variable parameters of the URL. In the container scenario, the nginx container is used to dynamically parse the variable parameters in the request, and the variable parameters are spliced ​​and recombined into a new URL, and the external traffic is forwarded to the spliced ​​new URL address;

[0099] The services of the nginx container are exposed to the outside world. Users can access the services according to preset configurations or rules. The nginx container is used to parse the URL with variables and reorganize it into a new URL for forwarding. This enables the Kubernetes cluster container service to be exposed to the outside world and achieves the purpose of accessing the services on the container.

[0100] In an optional implementation manner provided by the embodiment of the present invention, the method further includes:

[0101] The container corresponding to the second URL address obtains a request result according to the user request;

[0102] The request result is returned to the user. After the user accesses the container service, the container service responds to the user's request and returns the request result to the user according to the user's request.

[0103] Among the common ways of exposing container services in a Kubernetes cluster, the loadbalancer mode (abbreviated as lb mode) is shown in the following figure: Figure 4 As shown:

[0104] Figure 4 Although k8s provides an interface, it is only a definition and does not provide an implementation. It cannot complete the traffic forwarding and cannot achieve the effect of traffic forwarding. LB requires additional support to be implemented, such as public cloud services or the development of LB components.

[0105] Compared with the existing LB mode, the embodiment of the present invention does not require a public cloud LB. The nginx container is used to parse the URL with variables and reorganize it into a new URL for forwarding, so as to realize the external exposure of the kubernetes cluster container service.

[0106] Among the common ways to expose container services in a kubernetes cluster, there are many ways to implement ingress controller in ingress mode, including nginx, haproxy, istio, etc. Taking nginx ingress controller as an example, you need to create an ingress controller and define ingress resources.

[0107] The schematic diagram of ingress mode is as follows Figure 5 As shown: The steps to define ingress resources can be to create for1.mydomain.com to point to the backend App1 service (172.21.10.40:80). If there is an additional App2 service (172.21.10.41:80) during use, you need to create a new ingress to point the domain name for2.mydomain.com to the App2 service, or update the previously created ingress to complete the binding of for2.mydomain.com and App2 service;

[0108] At this point, users can access different container applications on the backend based on different domain names of the portal: users accessing for1.mydomain.com can access the backend App1 service (172.21.10.40:80), which is forwarded to the backend container (10.10.10.10:8080 or 10.10.10.20:8080) through the service; users accessing for2.mydomain.com can access the backend App2 service (172.21.10.41:80), which is forwarded to the backend container (10.10.10.30:8080) through the service;

[0109] It can be seen that the existing ingress backend depends on the service, and different domain names are routed to different backend services. If a service is added when an application is added, the original ingress needs to be modified, or a new ingress needs to be added for processing. After adding a business, the corresponding resolved domain name needs to be added to the ingress of the service, and then the business party uses the new domain name to access the service. In addition, it is also necessary to maintain the ingress resources while maintaining the application service.

[0110] Compared with the existing ingress mode, the embodiment of the present invention does not require the Kubernetes cluster to have an ingresscontroller, does not need to establish different domain names for different businesses, and does not need to modify or add ingress policies. When adding a business, it is only necessary to add a service and a pod corresponding to the app. There is no need to constantly maintain the ingress policy as the business changes, and there is no need to maintain the ingress objects in Kubernetes according to changes in the business.

[0111] A schematic diagram of a method for accessing a container service provided by an embodiment of the present invention is shown in FIG. Figure 6 As shown in the figure, the solid line is the external traffic of the kubernetes cluster, and the dotted line is the internal traffic of the kubernetes cluster. Pod can be simply understood as a container, the smallest unit of k8s scheduling. If you want to create or delete a container on different physical servers, you need to operate the pod; service is a group of container applications with the same function that provide a unified entry address and distribute the request load to each container application on the backend;

[0112] In the embodiment of the present invention, external traffic accesses the nginx container through the nodeport with port number 30080, and the nginx container is forwarded to the service and pod respectively according to the address accessed by the external traffic; the number 1 indicates that the address accessed by the external traffic is the IP address of the service, and accessing the service is equivalent to load balancing the two container applications app1 pod1 and app1 pod2, and the number 2 indicates that the address accessed by the external traffic is the IP address of the pod, accessing the container application app1 pod1 or accessing the container application app1 pod2.

[0113] In the embodiment of the present invention, the nodeport method is used to expose the nginx service to the outside of the cluster. Nginx is used as the traffic entrance to obtain and parse the variable parameters of the URL. In the container scenario, the nginx container is used to dynamically parse the variable parameters in the request, and the variable parameters are spliced ​​and recombined into a new URL, and the external traffic is forwarded to the spliced ​​new URL address;

[0114] The services of the nginx container are exposed to the outside world. Users can access the services according to preset configurations or rules. The nginx container is used to parse the URL with variables and reorganize it into a new URL for forwarding. This enables the Kubernetes cluster container service to be exposed to the outside world and achieves the purpose of accessing the services on the container.

[0115] From the above description, it can be seen that the present invention achieves the following technical effects:

[0116] Compared with the existing nodeport mode, the embodiment of the present invention does not need to configure a nodeport for each service, only one entrance is needed, and only the port exposed by nginx is needed, so a large number of host ports will not be occupied, and port conflicts will not occur; moreover, when modifying or adding services, only the service and pod need to be changed accordingly, which has no effect on the nodeport port, does not require additional port numbers to be occupied, and does not require occupying too many ports on the cluster hosts;

[0117] Compared with the existing LB mode, the embodiment of the present invention does not require a public cloud LB, and uses an nginx container to parse the URL with variables and reorganize it into a new URL for forwarding, thereby realizing the external exposure of the kubernetes cluster container service;

[0118] Compared with the existing ingress mode, the embodiment of the present invention does not require the kubernetes cluster to have an ingresscontroller, does not need to establish different domain names for different businesses, does not need to modify or add ingress policies, and the access process is simple to operate; when adding a business, it only needs to add a service and a pod corresponding to the app, and there is no need to constantly maintain the ingress policy as the business changes, and there is no need to maintain the ingress objects in kubernetes according to the changes in the business, thereby reducing the maintenance cost; when the business changes, it is only necessary to modify the containers and services corresponding to the business, and there is no need to maintain the ingress resources;

[0119] The embodiment of the present invention exposes the service of the nginx container itself to the outside, and the user accesses it according to the preset configuration or rules. The nginx container is used to parse the URL with variables and reorganize it into a new URL for forwarding, thereby realizing the external exposure of the kubernetes cluster container service and achieving the purpose of accessing the service on the container, solving the problems of complex and cumbersome operation and high maintenance cost of the existing kubernetes cluster container service external exposure technology.

[0120] It should be noted that the steps shown in the flowcharts of the accompanying drawings can be executed in a computer system such as a set of computer executable instructions, and that, although a logical order is shown in the flowcharts, in some cases, the steps shown or described can be executed in an order different from that shown here.

[0121] The embodiment of the present invention also provides a container service access system for implementing the container service access method. Figure 7 As shown, the system includes:

[0122] The external exposure unit 71 is used to create an nginx container and expose the nginx container to the outside of the kubernetes cluster through the IP address and port of the physical machine;

[0123] A configuration unit 72 is used to configure the nginx container, and receive a first URL address requested by a user through the configured nginx container, wherein the first URL address includes an IP address and a port of the physical machine;

[0124] A recombining unit 73, configured to parse and recombine the first URL address to obtain a second URL address;

[0125] The forwarding unit 74 is used to forward the user request to the second URL address through the nginx container to forward the external traffic of the kubernetes cluster to the inside of the cluster.

[0126] The embodiment of the present invention further provides an electronic device, such as Figure 8 As shown, the electronic device includes one or more processors 81 and a memory 82. Figure 8 A processor 81 is taken as an example.

[0127] The controller may further include: an input device 83 and an output device 84 .

[0128] The processor 81, the memory 82, the input device 83 and the output device 84 may be connected via a bus or other means. Figure 8 The example of connecting through bus is taken in the following.

[0129] The processor 81 can be a central processing unit (CPU), or other general-purpose processors, a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field-programmable gate array (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, or a combination of the above chips. The general-purpose processor can be a microprocessor or any conventional processor.

[0130] The memory 82 is a non-transitory computer-readable storage medium that can be used to store non-transitory software programs, non-transitory computer executable programs and modules, such as program instructions / modules corresponding to the control method in the embodiment of the present invention. The processor 81 executes various functional applications and data processing of the server by running the non-transitory software programs, instructions and modules stored in the memory 82, that is, the access method of the container service of the above method embodiment is implemented.

[0131] The memory 82 may include a program storage area and a data storage area, wherein the program storage area may store an operating system, an application required for at least one function; the data storage area may store data created according to the use of a processing device operated by the server, etc. In addition, the memory 82 may include a high-speed random access memory, and may also include a non-transitory memory, such as at least one disk storage device, a flash memory device, or other non-transitory solid-state storage device. In some embodiments, the memory 82 may optionally include a memory remotely arranged relative to the processor 81, and these remote memories may be connected to a network connection device via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.

[0132] The input device 83 can receive input digital or character information, and generate key signal input related to user settings and function control of the processing device of the server. The output device 84 can include display devices such as a display screen.

[0133] One or more modules are stored in the memory 82, and when executed by one or more processors 81, the execution is as follows: Figure 1 The method shown.

[0134] Those skilled in the art can understand that the implementation of all or part of the processes in the above-mentioned embodiment method can be completed by instructing the relevant hardware through a computer program, and the program can be stored in a computer-readable storage medium. When the program is executed, it can include the processes of the embodiments of the above-mentioned motor control methods. Among them, the storage medium can be a disk, an optical disk, a read-only memory (ROM), a random access memory (RAM), a flash memory (FM), a hard disk drive (HDD), or a solid-state drive (SSD), etc.; the storage medium can also include a combination of the above-mentioned types of memory.

[0135] Although the embodiments of the present invention have been described in conjunction with the accompanying drawings, those skilled in the art may make various modifications and variations without departing from the spirit and scope of the present invention, and such modifications and variations are all within the scope defined by the appended claims.

Claims

1. A method for accessing a container service, characterized in that: include: Create an nginx container and expose it to the outside of the kubernetes cluster through the IP address and port of the physical machine; The nginx container is configured, and a first URL address requested by a user to be accessed is received through the configured nginx container, wherein the first URL address includes the IP address and port of the physical machine; Parse and reorganize the first URL address to obtain a second URL address; Forward the user request to the second URL address through the nginx container to forward the external traffic of the kubernetes cluster to the inside of the cluster; Wherein, configuring the nginx container includes: The location instruction is configured to match the first URL address requested by the user; Configure the resolver to the cluster DNS server address so that when the user requests to access the domain name of the service, the domain name resolution is performed to obtain the IP address of the service; The proxy forwarding is configured to obtain the IP address and port number of the reverse proxy, so as to forward the user request to the second URL address obtained by recombining the IP address and port number of the reverse proxy; The first URL address is parsed and reorganized to obtain a second URL address, including: Parse the IP address variable and the port number variable in the first URL address to obtain the IP address and port number of the reverse proxy; Concatenate the IP address and port number of the reverse proxy to obtain a second URL address; The forwarding of the user request to the second URL address through the nginx container includes: Determine the address type of the second URL address; If the address type of the second URL address is the IP address of the service, the user request is forwarded to the service, and all containers under the service perform load balancing on the user request to achieve access to the container service; If the address type of the second URL address is the IP address of the container, the user request is forwarded to the container to access the container service.

2. The method according to claim 1, characterized in that Exposing the nginx container to the outside of the kubernetes cluster through the IP address and port of the physical machine includes: Use the nginx container as the entrance of external traffic of the kubernetes cluster, and use nodeport to expose the nginx container to the outside of the kubernetes cluster through the IP address and port of the physical machine; Receive a user's access request to the nginx container through the nodeport.

3. The method according to claim 1, characterized in that: If the address type of the second URL address is the domain name of the service, then: Use the resolver to resolve the domain name and resolve the service's IP address based on the service's domain name; The user request is forwarded to the service, and all containers under the service perform load balancing on the user request to achieve access to the container service.

4. The method according to claim 1, characterized in that: The method further comprises: The container corresponding to the second URL address obtains a request result according to the user request; The request result is returned to the user.

5. A container service access system, characterized in that: include: An external exposure unit, used to create an nginx container and expose the nginx container to the outside of the kubernetes cluster through the IP address and port of the physical machine; A configuration unit, configured to configure the nginx container, and receive a first URL address requested by a user through the configured nginx container, wherein the first URL address includes an IP address and a port of the physical machine; A recombining unit, used for parsing and recombining the first URL address to obtain a second URL address; A forwarding unit, used to forward the user request to the second URL address through the nginx container, so as to forward the external traffic of the kubernetes cluster to the inside of the cluster; Wherein, configuring the nginx container includes: The location instruction is configured to match the first URL address requested by the user; Configure the resolver to the cluster DNS server address so that when the user requests to access the domain name of the service, the domain name resolution is performed to obtain the IP address of the service; The proxy forwarding is configured to obtain the IP address and port number of the reverse proxy, so as to forward the user request to the second URL address obtained by recombining the IP address and port number of the reverse proxy; The first URL address is parsed and reorganized to obtain a second URL address, including: Parse the IP address variable and the port number variable in the first URL address to obtain the IP address and port number of the reverse proxy; The reverse proxy's IP address and port number are concatenated to obtain a second URL address. The forwarding of the user request to the second URL address through the nginx container includes: Determine the address type of the second URL address; If the address type of the second URL address is the IP address of the service, the user request is forwarded to the service, and all containers under the service perform load balancing on the user request to achieve access to the container service; If the address type of the second URL address is the IP address of the container, the user request is forwarded to the container to access the container service.

6. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer instructions, and the computer instructions are used to enable a computer to execute the container service access method according to any one of claims 1 to 4.

7. An electronic device, characterized in that: The electronic device includes: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores a computer program executable by the at least one processor, and the computer program is executed by the at least one processor so that the at least one processor executes the container service access method according to any one of claims 1 to 4.