Access method, device and equipment of container service and storage medium
By optimizing the routing process of the load balancer in the Kubernetes cluster, and utilizing calico routing and VPC interfaces, traffic can be routed into containers with only two routing table matches, solving the problem of low forwarding efficiency in existing technologies and enabling more efficient access to container services.
Patent Information
- Application Number
- CN202310935095.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-07-27
- Publication Date
- 2026-11-20
- Estimated Expiration
- 2043-07-27
AI Technical Summary
Existing container service access methods suffer from poor forwarding efficiency in Kubernetes clusters, especially when the load balancer and Calico network are interconnected. Multiple routing table matches are required to get traffic into the container, resulting in low efficiency.
After receiving an access request, the load balancer determines the target backend address and container port, uses Calico routing and VPC network interface to direct external traffic to the target VPC, and determines the target container through the OVN routing table. Traffic forwarding can be achieved by matching the routing table only twice.
It improves the forwarding efficiency of container services, reduces the number of routing table matches, and increases traffic access speed.
Smart Images

Figure CN116886701B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of computer technology, and in particular to a method, apparatus, device and storage medium for accessing container services. Background Technology
[0002] Kubernetes (k8s) is an open-source container orchestration platform used to automate the deployment, scaling, and management of containerized applications. In a k8s cluster, a load balancer typically distributes traffic to network devices or services across multiple backend containers for network access.
[0003] Currently, because the network plugin calico in the Kubernetes cluster uses a virtual network that can communicate with the node router, the existing method for accessing container services is generally to use a load balancer to attach a VPC address, then find the node router through the VPC address, and finally forward the data to the container through the node router.
[0004] However, existing methods for accessing container services suffer from poor forwarding efficiency. Summary of the Invention
[0005] This application provides a method, apparatus, device, and storage medium for accessing container services, in order to solve the problem of poor forwarding efficiency in existing methods for accessing container services.
[0006] Firstly, this application provides a method for accessing a container service, including:
[0007] After the load balancer receives an access request from external traffic, it determines the target backend address to be accessed and the container port corresponding to the target backend address based on the access request.
[0008] Determine the target calico route based on the target backend address and the container port corresponding to the target backend address;
[0009] Based on the target calico route, determine the target VPC and the network interface of the target VPC;
[0010] Based on the network interface of the target VPC, external traffic is directed to the target VPC so that the target VPC can determine the target container from the preset OVN routing table according to the target calico route, and the external traffic can access the target container. The target VPC and the target calico route are then used to determine the target container.
[0011] In this application, after the load balancer receives an access request from external traffic, it determines the target backend address to be accessed and the port corresponding to the target backend address based on the access request, including:
[0012] After the load balancer receives access requests from external traffic, it determines the virtual IP address and virtual port of the load balancer based on the access requests.
[0013] Based on the preset load balancing software, determine the target backend address to be accessed in the load balancer, as well as the port corresponding to the target backend address.
[0014] In this application, before determining the target calico route based on the target backend address and the port corresponding to the target backend address, the method further includes:
[0015] Create the target container;
[0016] When the calico IP pool changes, the Kubernetes cluster writes the target calico route into the etcd and ovn routing tables respectively, where the target calico route corresponds to the target container.
[0017] According to etcd, the target calico route is written to the load balancer, and the container address and container port of the target container are also written to the load balancer. The target calico route points to the network interface of the target VPC.
[0018] In this application, when the calico IP pool changes, the Kubernetes cluster writes the target calico route into both the etcd and OVN routing tables, including:
[0019] The Kubernetes cluster uses the CCM component to monitor changes in the Calico IP pool.
[0020] When the calico IP pool changes status, the Kubernetes cluster writes the target calico route information to etcd and to the OVN routing table.
[0021] In this application, based on etcd, the target calico route is written to the load balancer, and the container address and container port of the target container are written to the load balancer, including:
[0022] Invoke the Kubernetes cluster to monitor etcd;
[0023] If etcd sends a change, the target calico route is written into the load balancer's carrier, and the Kubernetes cluster's ccm component is called to write the target container's container address and container port into the load balancer's backend address.
[0024] In this application, the method also includes:
[0025] When the target container accesses external traffic, the node route is determined based on the target container;
[0026] Traffic from the target container is routed to the target VPC via node routing, so that the target VPC forwards external addresses to the NAT gateway, and the NAT gateway performs SNAT processing according to the preset SNAT rules before allowing the target container to access external traffic.
[0027] In this application, before routing traffic from the target container to the target VPC via node routing, causing the target VPC to forward external addresses to the NAT gateway, and performing SNAT processing on the NAT gateway so that return traffic is routed to the target container via the NAT gateway, the method further includes:
[0028] Create the target container;
[0029] When the calico IP pool changes, the Kubernetes cluster configures SNAT rules for the gateway based on the target calico route information. This enables the target VPC to forward external addresses to the NAT gateway, which then performs SNAT processing according to the preset SNAT rules. The target calico route corresponds to the target container.
[0030] Secondly, this application provides an access device for container services, the device comprising:
[0031] The first determination module is used to determine the target backend address to be accessed and the container port corresponding to the target backend address based on the access request after the load balancer receives the access request from external traffic.
[0032] The second determining module is used to determine the target calico route based on the target backend address and the container port corresponding to the target backend address.
[0033] The third determination module is used to determine the target VPC and the network interface of the target VPC based on the target calico route.
[0034] The access module is used to import external traffic to the target VPC based on the target VPC's network interface, so that the target VPC can determine the target container from the preset OVN routing table according to the target calico route, and enable external traffic to access the target container. The target VPC and the target calico route are used for this purpose.
[0035] Thirdly, this application provides an electronic device, including: a processor, and a memory communicatively connected to the processor;
[0036] The memory stores the instructions that the computer executes;
[0037] The processor executes computer execution instructions stored in memory to implement the method of this application.
[0038] Fourthly, this application provides a computer-readable storage medium storing computer-executable instructions, which, when executed by a processor, are used to implement the method of this application.
[0039] The container service access method, apparatus, device, and storage medium provided in this application, after receiving an access request from external traffic in the load balancer, determine the target backend address and the container port corresponding to the target backend address based on the access request; determine the target Calico route based on the target backend address and the container port corresponding to the target backend address; determine the target VPC and the network interface of the target VPC based on the target Calico route; and guide the external traffic to the target VPC based on the network interface of the target VPC. This allows the target VPC to determine the target container from a preset OVN routing table based on the target Calico route, and then allow the external traffic to access the target container. The method of determining the target VPC and the target Calico route involves determining the target backend address and container port through the access request, and then determining the corresponding target Calico route based on the target backend address and container port. After guiding the external traffic to the target VPC according to the target Calico route, the corresponding target container is determined again according to the preset OVN routing table. Therefore, after the external traffic accesses the load balancer, only two routing table matches are needed to redirect the traffic to the target container, thus improving forwarding efficiency. Attached Figure Description
[0040] The accompanying drawings, which are incorporated in and form part of this specification, illustrate embodiments consistent with this application and, together with the description, serve to explain the principles of this application.
[0041] Figure 1 A flowchart illustrating the method for accessing container services provided in this application embodiment;
[0042] Figure 2 Another method for accessing container services provided in this application embodiment;
[0043] Figure 3 Another method for accessing container services provided in this application embodiment;
[0044] Figure 4 Another method for accessing container services provided in this application embodiment;
[0045] Figure 5 A schematic diagram of the structure of the container service access device provided in the embodiments of this application;
[0046] Figure 6 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application.
[0047] The accompanying drawings illustrate specific embodiments of this application, which will be described in more detail below. These drawings and descriptions are not intended to limit the scope of the concept in any way, but rather to illustrate the concept of this application to those skilled in the art through reference to particular embodiments. Detailed Implementation
[0048] Exemplary embodiments will now be described in detail, examples of which are illustrated in the accompanying drawings. When the following description relates to the drawings, unless otherwise indicated, the same numbers in different drawings denote the same or similar elements. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with this application. Rather, they are merely examples of apparatuses and methods consistent with some aspects of this application as detailed in the appended claims.
[0049] In existing technologies, the network plugin Calico in a Kubernetes cluster uses a virtual network. This network can communicate with the node. When accessed through an external load balancer, the load balancer generally communicates with the VPC network, but not directly with the Calico network. Therefore, under normal circumstances, the load balancer backend will be connected to the VPC address. The node is found through the VPC address first, and then the traffic enters the pod through the node. This results in the traffic needing to be matched three times in the routing table before it can be routed into the pod, which is inefficient.
[0050] To address the aforementioned issues, this application provides a method for accessing container services. The method determines the target backend address and container port through an access request, and then determines the corresponding target Calico route based on the target backend address and container port. After directing external traffic to the target VPC according to the target Calico route, the corresponding target container is determined based on a preset OVN routing table. Thus, after external traffic accesses the load balancer, only two routing table matches are needed to redirect the traffic to the target container, thereby improving forwarding efficiency.
[0051] The technical solution of this application and how the technical solution of this application solves the above-mentioned technical problems are described in detail below with specific embodiments. These specific embodiments can be combined with each other, and the same or similar concepts or processes may not be described again in some embodiments. The embodiments of this application will now be described with reference to the accompanying drawings.
[0052] The execution entity of the project creation method provided in this application embodiment can be a server. The server can be a device such as a mobile phone, tablet, or computer. This embodiment does not impose any particular restrictions on the implementation method of the execution entity, as long as the execution entity can, after receiving an access request from external traffic in the load balancer, determine the target backend address and the container port corresponding to the target backend address; determine the target Calico route based on the target backend address and the container port corresponding to the target backend address; determine the target VPC and the network interface of the target VPC based on the target Calico route; and import the external traffic to the target VPC based on the network interface of the target VPC, so that the target VPC can determine the target container from the preset OVN routing table according to the target Calico route, and allow the external traffic to access the target container. The target VPC and the target Calico route are sufficient.
[0053] In this context, a container (pod) can refer to the smallest deployable object in a Kubernetes cluster. It is a collection of one or more containers that share network and storage resources and run on the same node.
[0054] A load balancer is a network device or software used to distribute network traffic across multiple servers or computers to achieve high availability, scalability, and performance optimization. Load balancers can distribute traffic to different servers based on different algorithms (such as round-robin, weighted round-robin, least connections, etc.), thereby avoiding service interruptions caused by overload or failure of a single server.
[0055] A Kubernetes (k8s) cluster can refer to an open-source container orchestration platform used to automate the deployment, scaling, and management of containerized applications. A k8s cluster can run containers on multiple hosts and provides automated container deployment, scaling, and management capabilities, making applications more reliable and scalable.
[0056] Figure 1 This is a flowchart illustrating the method for accessing container services provided in this embodiment. The executing entity of this method can be a server or other servers; this embodiment does not impose any special limitations here. Figure 1 As shown, the method may include:
[0057] S101. After the load balancer receives an access request from external traffic, it determines the target backend address to be accessed and the container port corresponding to the target backend address based on the access request.
[0058] External traffic refers to network requests originating from outside the Kubernetes cluster, such as HTTP (Hypertext Transfer Protocol) requests from the internet or API (Application Programming Interface) requests from other cloud services. Within a Kubernetes cluster, an application's services can be exposed through Service objects, allowing external traffic to access those services. External traffic can access these services through load balancers, Ingress, and other methods.
[0059] An access request refers to a network request initiated from outside the Kubernetes cluster. This request may include the target container and its information. The target container information may include the target backend address and container port. The backend address can be the address of the target server to which the load balancer forwards the access request, and this target server address can be the address of the target container. The load balancer forwards requests to the backend address according to a load balancing algorithm to achieve load balancing and high availability. The container port can be the port of the backend service to which the load balancer forwards the access request. In the load balancer configuration, the IP address and port number of the backend service must be specified to forward requests to the correct backend service. The backend service can be one or more containers, virtual machines, or physical machines. The load balancer distributes requests evenly across these backend services to achieve high availability and high-performance service access.
[0060] In this embodiment of the application, after the load balancer receives an access request from external traffic, it determines the target backend address to be accessed and the port corresponding to the target backend address based on the access request, including:
[0061] After the load balancer receives access requests from external traffic, it determines the virtual IP address and virtual port of the load balancer based on the access requests.
[0062] Based on the preset load balancing software, determine the target backend address to be accessed in the load balancer, as well as the port corresponding to the target backend address.
[0063] The virtual IP address and virtual port of a load balancer refer to the IP address and port configured on the load balancer to receive access requests sent by clients. Using virtual IP addresses and ports, the load balancer can forward and distribute requests to backend servers, thereby achieving load balancing.
[0064] Load balancing software can include LVS (Linux Virtual Server) or Nginx (engine x). LVS can combine multiple servers into a highly available server cluster, distributing client requests to different servers through load balancing algorithms, thereby improving system availability and performance. Nginx can be a high-performance HTTP and reverse proxy web server.
[0065] S102. Determine the target calico route based on the target backend address and the container port corresponding to the target backend address.
[0066] In this context, "Calico routing" can refer to a network plugin within a Kubernetes cluster. Calico is an open-source networking and security solution for container, virtual machine, and bare-metal environments. Calico routing refers to the use of the BGP protocol to publish container IP addresses and routing information to the Calico network, thereby implementing container networking and network policies to improve forwarding efficiency.
[0067] In this embodiment of the application, the target calico route can be written into the load balancer first, so that the target backend address and the container port corresponding to the target backend address can be obtained to determine the target calico route.
[0068] In this embodiment of the application, before determining the target calico route based on the target backend address and the port corresponding to the target backend address, the method further includes:
[0069] Create the target container;
[0070] When the calico IP pool changes, the Kubernetes cluster writes the target calico route into the etcd and ovn routing tables respectively, where the target calico route corresponds to the target container.
[0071] According to etcd, the target calico route is written to the load balancer, and the container address and container port of the target container are also written to the load balancer. The target calico route points to the network interface of the target VPC.
[0072] The calico IP pool refers to the pool of IP addresses used to allocate IP addresses to containers within the Calico network. In this embodiment, the calico IP pool is used when a container is created, and a new network segment is requested and written to etcd in the Kubernetes cluster after the calico IP pool is exhausted.
[0073] The change status of a calico IP pool can be used to indicate whether a new container has been created.
[0074] In a Kubernetes cluster, etcd can be a key-value store used to store all configuration data within the cluster, including nodes, containers, services, volumes, namespaces, etc. etcd is one of the core components of a Kubernetes cluster, responsible for storing and synchronizing all cluster state information, ensuring that all nodes in the cluster can access the latest configuration information.
[0075] In this embodiment, by detecting changes in the calico IP pool, it can be determined whether a new container has been created. By writing the calico route corresponding to the target container into the etcd and ovn routing tables respectively, after load balancing of external traffic access, only two matching of the routing tables is needed to throw the traffic into the pod, resulting in high forwarding efficiency.
[0076] In this embodiment of the application, when the calico IP pool changes, the Kubernetes cluster writes the target calico route into the etcd and OVN routing tables, respectively, including:
[0077] The Kubernetes cluster uses the CCM component to monitor changes in the Calico IP pool.
[0078] When the calico IP pool changes status, the Kubernetes cluster writes the target calico route information to etcd and to the OVN routing table.
[0079] In this embodiment of the application, writing the target calico route to the load balancer according to etcd, and writing the container address and container port of the target container to the load balancer, includes:
[0080] Invoke the Kubernetes cluster to monitor etcd;
[0081] If etcd sends a change, the target calico route is written into the load balancer's carrier, and the Kubernetes cluster's ccm component is called to write the target container's container address and container port into the load balancer's backend address.
[0082] This involves using an externally developed component of the Kubernetes cluster to monitor etcd. This externally developed component can refer to a plugin used to extend the functionality of the Kubernetes cluster. In this embodiment, the externally developed component can receive and process Calico routing information from the CCM component in the Kubernetes cluster and write the routing information to etcd so that other components can read and use this information. In this embodiment, the externally developed component can be written as an HTTP service using languages such as Python, Go, or Java, or it can be written using open-source software such as Consul or ZooKeeper.
[0083] The CCM (Cloud Controller Manager) component is a component in the Kubernetes cluster. The CCM component can listen for changes in the Calico IP pool through the watch mechanism on the API Server in the Kubernetes cluster. When an IP address in the Calico IP pool changes, the CCM component receives a notification and converts the change information into an API request to the cloud service provider to update the routing table in the cloud service provider.
[0084] S103. Based on the target calico route, determine the target VPC and the network interface of the target VPC.
[0085] Among them, the target VPC (Virtual Private Cloud) can refer to a virtualized network environment, which can create an isolated and private network environment on a cloud computing platform. Users can start cloud resources such as virtual machines, storage, and databases in this environment, and can customize network configurations such as IP address ranges, subnets, routing tables, and gateways.
[0086] The network port of the target VPC can refer to the virtual network interface created in the VPC, which can be used to connect different subnets, routing tables, security groups and other network resources to realize network communication and data transmission.
[0087] In this embodiment of the application, the target VPC and the network interface of the target calico route can be determined by viewing the routing table.
[0088] S104. Based on the network interface of the target VPC, external traffic is directed to the target VPC so that the target VPC can determine the target container from the preset OVN routing table according to the target calico route, and the external traffic can access the target container. The target VPC and the target calico route are used for this purpose.
[0089] The OVN routing table can refer to the data structure used to manage routes in OVN (Open Virtual Network, an open-source virtual network solution). The OVN routing table contains network topology information, routing rules, NAT rules, etc. In this embodiment of the application, the information of the target container can be recorded in the OVN routing table in advance so as to determine the target container according to the target calico route.
[0090] The target container can refer to the container used for external traffic access.
[0091] In this embodiment of the application, the method further includes:
[0092] When the target container accesses external traffic, the node route is determined based on the target container;
[0093] Traffic from the target container is routed to the target VPC via node routing, so that the target VPC forwards external addresses to the NAT gateway, and the NAT gateway performs SNAT processing according to the preset SNAT rules before allowing the target container to access external traffic.
[0094] Node.js routing refers to a technique that maps HTTP requests to appropriate handlers or controllers. It helps us build RESTful APIs and web applications. Node.js routing can be implemented using third-party libraries such as Express.js.
[0095] In this embodiment of the application, when deploying a Node.js application using a container, the container's network functionality can be used to determine the route of the Node.js application.
[0096] A NAT (Network Address Translation) gateway is a network device used to translate IP addresses in a private network into IP addresses in a public network, enabling communication over the public network.
[0097] SNAT (Source Network Address Translation) is a network address translation technology used to convert a source IP address into another IP address. A SNAT rule is a set of rules that specify which IP addresses need to be translated using SNAT, and what the translated IP address should be. NAT processing involves converting IP addresses according to these SNAT rules, thereby enabling the target container to access external traffic.
[0098] In this embodiment of the application, before the traffic of the target container is routed to the target VPC via node routing, so that the target VPC forwards external addresses to the NAT gateway and performs SNAT processing on the NAT gateway, so that the return traffic is routed to the target container via the NAT gateway, the method further includes:
[0099] Create the target container;
[0100] When the calico IP pool changes, the Kubernetes cluster configures SNAT rules for the gateway based on the target calico route information. This enables the target VPC to forward external addresses to the NAT gateway, which then performs SNAT processing according to the preset SNAT rules. The target calico route corresponds to the target container.
[0101] The container service access method provided in this application improves upon solutions where the load balancer backend cannot be connected to pod IP addresses and must be connected to node IP addresses. Furthermore, the forwarding process for incoming external traffic requires three routing table matches, significantly reducing forwarding performance. It also addresses the issue where return traffic from a container service accessing an external service also requires multiple routing table matches, further degrading forwarding performance.
[0102] Figure 2 Another method for accessing container services provided in the embodiments of this application, such as Figure 2 As shown, the method includes:
[0103] S201, Create a pod.
[0104] When a pod is created, it occupies a calico IP pool. When the calico IP pool is exhausted, a new network segment is requested and written to etcd in the Kubernetes cluster.
[0105] The S202 and Kubernetes clusters call the CCM component to listen to the Calico IP pool;
[0106] S203. When a change in the calico IP pool is detected, the Kubernetes cluster is invoked to write the calico routing information to etcd used by the external self-developed component, to the OVN routing table, and to access SNAT rules for the NAT gateway.
[0107] When the CCM component in the Kubernetes cluster detects changes in the Calico IP pool, it can call an external self-developed component in the Kubernetes cluster to write Calico routing information into the etcd table used by the self-developed component, as well as write it into the OVN routing table and SNAT rules for the NAT gateway.
[0108] The format for writing to the OVN routing table can be:
[0109] ovn-nbctl lr-route-add vpc_727730898569_796774c999 172.246.135.128 / 26192.168.4.3.
[0110] The format for SNAT rules for NAT gateways can be:
[0111] ovn-nbctl lr-nat-add vpc_727730898569_796774c999 snat10.125.142.69172.246.0.0 / 16.
[0112] The listening key can include:
[0113] / calico / ipam / v2 / host and / calico / resources / v3 / projectcalico.org / nodes.
[0114] The S204 and k8s clusters monitor etcd changes and write calico routes into the carrier of the external server load balancer, where the calico routes point to the vpc network interface.
[0115] S205. Write the pod address and container port to the backend address of the external load balancer via CCM.
[0116] Figure 3 Another method for accessing container services provided in the embodiments of this application, such as Figure 3 As shown, the method includes:
[0117] S301, External traffic access load balancer vip:vport, the load balancer will determine the backend address and the port corresponding to the backend address based on LVS rules or Nginx rules.
[0118] S302. Match the calico route within the load balancer and drive the traffic into the VPC;
[0119] S303, within the VPC, match the OVN routing table to find the node and pod where the target pod is located;
[0120] S304. Direct traffic from the VPC directly into the pod, and return traffic is returned via the original path.
[0121] Figure 4 Another method for accessing container services provided in the embodiments of this application, such as Figure 3 As shown, the method includes:
[0122] S401, traffic within the pod is routed to the VPC via the node route;
[0123] S402, within the VPC, traffic to external addresses is directed to the NAT gateway, and according to SNAT rules, the NAT gateway directs the traffic to the outside.
[0124] S403, the return traffic comes in through NAT.
[0125] Therefore, the alternative container service access method provided in this application embodiment can redirect traffic to the pod by matching the routing table only twice after external traffic accesses the load balancer, resulting in high forwarding efficiency. Simultaneously, when a pod service accesses an external service, the return traffic only requires one routing table match, further improving forwarding performance. Furthermore, the pod network still utilizes the currently most stable Calico network, requiring minimal modifications to significantly improve the user experience.
[0126] Figure 5 A schematic diagram of the structure of an access device for container services provided in an embodiment of this application. For example... Figure 5 As shown, the container service access device 50 includes: a first determining module 501, a second determining module 502, a third determining module 503, and an access module 504. Wherein:
[0127] The first determining module 501 is used to determine the target backend address to be accessed and the container port corresponding to the target backend address based on the access request after the load balancer receives the access request from the external traffic.
[0128] The second determining module 502 is used to determine the target calico route based on the target backend address and the container port corresponding to the target backend address.
[0129] The third determining module 503 is used to determine the target VPC and the network interface of the target VPC based on the target calico route;
[0130] Access module 504 is used to import external traffic to the target VPC based on the network interface of the target VPC, so that the target VPC can determine the target container from the preset OVN routing table according to the target calico route, and enable external traffic to access the target container, wherein the target VPC and the target calico route are used.
[0131] In this embodiment of the application, the first determining module 501 may also be specifically used for:
[0132] After the load balancer receives access requests from external traffic, it determines the virtual IP address and virtual port of the load balancer based on the access requests.
[0133] Based on the preset load balancing software, determine the target backend address to be accessed in the load balancer, as well as the port corresponding to the target backend address.
[0134] In this embodiment of the application, the second determining module 502 may also be specifically used for:
[0135] Create the target container;
[0136] When the calico IP pool changes, the Kubernetes cluster writes the target calico route into the etcd and ovn routing tables respectively, where the target calico route corresponds to the target container.
[0137] According to etcd, the target calico route is written to the load balancer, and the container address and container port of the target container are also written to the load balancer. The target calico route points to the network interface of the target VPC.
[0138] In this embodiment of the application, the second determining module 502 may also be specifically used for:
[0139] The Kubernetes cluster uses the CCM component to monitor changes in the Calico IP pool.
[0140] When the calico IP pool changes status, the Kubernetes cluster writes the target calico route information to etcd and to the OVN routing table.
[0141] In this embodiment of the application, the second determining module 502 may also be specifically used for:
[0142] Invoke the Kubernetes cluster to monitor etcd;
[0143] If etcd sends a change, the target calico route is written into the load balancer's carrier, and the Kubernetes cluster's ccm component is called to write the target container's container address and container port into the load balancer's backend address.
[0144] In this embodiment of the application, the access module 504 can also be specifically used for:
[0145] When the target container accesses external traffic, the node route is determined based on the target container;
[0146] Traffic from the target container is routed to the target VPC via node routing, so that the target VPC forwards external addresses to the NAT gateway, and the NAT gateway performs SNAT processing according to the preset SNAT rules before allowing the target container to access external traffic.
[0147] In this embodiment of the application, the access module 504 can also be specifically used for:
[0148] Create the target container;
[0149] When the calico IP pool changes, the Kubernetes cluster configures SNAT rules for the gateway based on the target calico route information. This enables the target VPC to forward external addresses to the NAT gateway, which then performs SNAT processing according to the preset SNAT rules. The target calico route corresponds to the target container.
[0150] The container service access device 50 provided in this application comprises: a first determining module 501, used to determine the target backend address and the container port corresponding to the target backend address based on the access request after the load balancer receives an access request from external traffic; a second determining module 502, used to determine the target calico route based on the target backend address and the container port corresponding to the target backend address; a third determining module 503, used to determine the target VPC and the network interface of the target VPC based on the target calico route; and an access module 504, used to import external traffic to the target VPC based on the network interface of the target VPC, so that the target VPC can determine the target container from a preset OVN routing table according to the target calico route, and allow external traffic to access the target container. This achieves the effect of improving forwarding efficiency.
[0151] Figure 6 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application. Figure 6 As shown, the electronic device 60 includes:
[0152] The electronic device 60 may include a processor 601 with one or more processing cores, a memory 602 with one or more computer-readable storage media, a communication component 603, and other components. The processor 601, memory 602, and communication component 603 are connected via a bus 604.
[0153] In the specific implementation process, at least one processor 601 executes computer execution instructions stored in memory 602, causing at least one processor 601 to execute the above-described container service access method.
[0154] The specific implementation process of processor 601 can be found in the above method embodiments, and its implementation principle and technical effect are similar. It will not be repeated here.
[0155] In the above Figure 6In the illustrated embodiments, it should be understood that the processor can be a Central Processing Unit (CPU), or other general-purpose processors, digital signal processors (DSPs), application-specific integrated circuits (ASICs), etc. The general-purpose processor can be a microprocessor or any conventional processor. The steps of the method disclosed in this invention can be directly implemented by a hardware processor, or implemented by a combination of hardware and software modules within the processor.
[0156] The memory may include random access memory (RAM) and may also include non-volatile memory (NVM), such as at least one disk storage device.
[0157] The bus can be an Industry Standard Architecture (ISA) bus, a Peripheral Component Interconnect (PCI) bus, or an Extended Industry Standard Architecture (EISA) bus, etc. Buses can be categorized as address buses, data buses, control buses, etc. For ease of illustration, the buses shown in the accompanying drawings are not limited to a single bus or a single type of bus.
[0158] In some embodiments, a computer program product is also provided, including a computer program or instructions that, when executed by a processor, implement the steps in any of the above-described methods for accessing container services.
[0159] For details on the implementation of each of the above operations, please refer to the previous examples, which will not be repeated here.
[0160] Those skilled in the art will understand that all or part of the steps in the various methods of the above embodiments can be performed by instructions, or by instructions controlling related hardware. These instructions can be stored in a computer-readable storage medium and loaded and executed by a processor.
[0161] Therefore, embodiments of this application provide a computer-readable storage medium storing a plurality of instructions that can be loaded by a processor to execute steps in any of the container service access methods provided in embodiments of this application.
[0162] The storage medium may include: read-only memory (ROM), random access memory (RAM), disk or optical disk, etc.
[0163] According to one aspect of this application, a computer program product or computer program is provided, the computer program product or computer program including computer instructions stored in a computer-readable storage medium.
[0164] Since the instructions stored in the storage medium can execute the steps in any of the container service access methods provided in the embodiments of this application, the beneficial effects that any of the container service access methods provided in the embodiments of this application can achieve can be realized, as detailed in the preceding embodiments, and will not be repeated here.
[0165] Other embodiments of this application will readily occur to those skilled in the art upon consideration of the specification and practice of the invention disclosed herein. This application is intended to cover any variations, uses, or adaptations of this application that follow the general principles of this application and include common knowledge or customary techniques in the art not disclosed herein. The specification and examples are to be considered exemplary only, and the true scope and spirit of this application are indicated by the following claims.
[0166] It should be understood that this application is not limited to the precise structure described above and shown in the accompanying drawings, and various modifications and changes can be made without departing from its scope. The scope of this application is limited only by the appended claims.
Claims
1. A method for accessing a container service, characterized in that, The method includes: After the load balancer receives an access request from external traffic, it determines the target backend address to be accessed and the container port corresponding to the target backend address based on the access request. The target network plugin calico route is determined based on the target backend address and the container port corresponding to the target backend address. Based on the target Calico route, determine the target Virtual Private Cloud (VPC) and the network interface of the target VPC; Based on the network interface of the target VPC, the external traffic is directed to the target VPC, so that the target VPC determines the target container from the preset open-source virtual network (OVN) routing table according to the target Calico route, and the external traffic accesses the target container.
2. The method according to claim 1, characterized in that, After the load balancer receives an access request from external traffic, it determines the target backend address to be accessed and the port corresponding to the target backend address based on the access request, including: After the load balancer receives an access request from external traffic, it determines the virtual IP address and virtual port of the load balancer based on the access request. Based on the preset load balancing software, the target backend address to be accessed in the load balancer and the port corresponding to the target backend address are determined.
3. The method according to claim 1, characterized in that, Before determining the target calico route based on the target backend address and the port corresponding to the target backend address, the method further includes: Create the target container; When the Calico IP pool changes, the Kubernetes cluster writes the target Calico route into the etcd and OVN routing tables, respectively. The target Calico route corresponds to the target container. etcd is the key-value store system in the Kubernetes cluster. The Calico IP pool is the pool of IP addresses used to allocate IP addresses to containers in the Calico network. The Calico network is the virtual network used by the Calico network plugin in the Kubernetes cluster. According to etcd, the target calico route is written to the load balancer, and the container address and container port of the target container are written to the load balancer, wherein the target calico route points to the network port of the target VPC.
4. The method according to claim 3, characterized in that, When the calico IP pool changes, the Kubernetes cluster writes the target calico route into the etcd and ovn routing tables, respectively, including: The Kubernetes cluster invokes the Cloud Controller Manager (ccm) component to monitor the changing status of the Calico IP pool; When the change status of the calico IP pool is "changed", the Kubernetes cluster writes the target calico route information to etcd and writes the target calico route information to the OVN routing table.
5. The method according to claim 3, characterized in that, The step of writing the target calico route to the load balancer according to etcd, and writing the container address and container port of the target container to the load balancer, includes: Invoke the Kubernetes cluster to monitor etcd; If etcd sends a change, the target calico route is written into the carrier of the load balancer, and the ccm component of the Kubernetes cluster is invoked to write the container address and container port of the target container into the backend address of the load balancer.
6. The method according to claim 1, characterized in that, The method further includes: When the target container accesses the external traffic, the route of the Node.js application is determined based on the target container; The traffic of the target container is routed into the target VPC through the Node.js application, so that the target VPC forwards the external address to the NAT gateway, and the NAT gateway performs SNAT processing according to the preset source NAT rules before allowing the target container to access the external traffic.
7. The method according to claim 6, characterized in that, Before routing traffic from the target container to the target VPC via the Node.js application's routing, causing the target VPC to forward external addresses to the NAT gateway, and performing SNAT processing on the NAT gateway so that return traffic is routed to the target container via the NAT gateway, the method further includes: Create the target container; When the Calico IP pool changes, the Kubernetes cluster configures the SNAT rules for the NAT gateway based on the target Calico route information. This causes the target VPC to forward external addresses to the NAT gateway, which then performs SNAT processing according to preset SNAT rules. The target Calico route corresponds to the target container; the Calico IP pool is an IP address pool used to allocate IP addresses to containers within the Calico network; and the Calico network is a virtual network used by the Calico network plugin within the Kubernetes cluster.
8. An access device for a container service, characterized in that, The device includes: The first determining module is used to determine the target backend address to be accessed and the container port corresponding to the target backend address based on the access request after the load balancer receives the access request from external traffic. The second determining module is used to determine the target network plugin calico route based on the target backend address and the container port corresponding to the target backend address. The third determining module is used to determine the target virtual private cloud (VPC) and the network interface of the target VPC based on the target Calico route. The access module is used to import the external traffic to the target VPC according to the network interface of the target VPC, so that the target VPC can determine the target container from the preset open source virtual network (OVN) routing table according to the target Calico route, and enable the external traffic to access the target container.
9. An electronic device, characterized in that, include: A processor, and a memory communicatively connected to the processor; The memory stores computer-executed instructions; The processor executes computer execution instructions stored in the memory to implement the method as described in any one of claims 1 to 7.
10. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores computer-executable instructions, which, when executed by a processor, are used to implement the method as described in any one of claims 1 to 7.
Citation Information
Patent Citations
Load balancing method and device, electronic equipment and storage medium
CN109831468A
Network access method and device based on Kubernetes, equipment and medium
CN113572838A
