Access request response method and device, storage medium
By obtaining the external network segment to be allocated and determining the target network segment in the Kubernetes container cloud, and assigning the IP address to respond to access requests, the IP waste problem when macvlan or ipvlan is solved, and the on-demand allocation of IP addresses is realized. Reduced resource waste.
Patent Information
- Application Number
- CN202210109420.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-01-28
- Publication Date
- 2024-11-26
- Estimated Expiration
- 2042-01-28
AI Technical Summary
In Kubernetes native container cloud network, the problem of IP address waste has not been effectively solved when using macvlan or ipvlan to allocate IP to the main network of POD.
By obtaining the external network segment to be allocated in the container cloud, the target segment of the same network segment is determined based on the node IP address of the target node, and the external network IP address to be allocated is allocated to the target node. When receiving the external network access request, the external network access request is received , select the appropriate IP address to respond to the request, thereby realizing on-demand allocation of IP addresses.
It effectively reduces the waste of IP resources, realizes the on-demand allocation of IP addresses, and avoids unnecessary waste of IP resources.
Smart Images

Figure CN114448937B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of communications, and in particular to a method and device for responding to an access request, and a storage medium. Background Art
[0002] The network of the container cloud platform is the cornerstone of the platform. POD is the basis for applications to provide external services. In the existing Kubernetes native container cloud network solutions, the general solutions are as follows:
[0003] 1) Use EIP, such as Figure 1 As shown:
[0004] Alibaba Cloud, AWS and other public cloud vendors all support elastic public IP (EIP), which can be used to deal with the situation where Pods need independent public network addresses in some scenarios. Taking Alibaba Cloud as an example, to mount an independent public network EIP for a Pod, you only need to modify the relevant permissions of its network plug-in terway and specify the EIP for the Pod in the template: k8s.aliyun.com / POD-with-eip: "true"; when a Pod is created, it will automatically find an unused EIP in the region and associate it with the intranet network card of the POD. It should be noted that the EIP is not actually directly assigned to the network card corresponding to the Pod, but the traffic is forwarded to the corresponding POD through NAT.
[0005] 2) Use single network card macvlan / ipvlan, such as Figure 2 As shown:
[0006] Use macvlan or ipvlan cni to assign an IP to the main network (eth0) of the POD as the IP in the Kubernetes cluster. The underlying layer needs to be second- and third-layer devices to ensure the intercommunication of these POD network cards.
[0007] 3) Use multus to allocate multiple network cards, such as Figure 3 As shown:
[0008] Multus can provide multiple network interfaces for PODs running on kubernetes. It can combine multiple CNI plugins to configure different types of networks for PODs. Multus uses the concept of "delegates" to combine multiple CNI plugins and designates a master plugin as the main network (eth0) of the POD as the IP in the Kubernetes cluster.
[0009] In the related art, the solution of using a single network card macvlan / ipvlan will cause a waste of IP addresses.
[0010] In the related art, using macvlan or ipvlan cni to allocate IP to the main network of the POD will cause problems such as waste of IP addresses, and no effective solution has been proposed yet. Summary of the invention
[0011] The embodiment of the present invention provides a method and device for responding to an access request, and a storage medium, so as to at least solve the problem in the related art that using macvlan or ipvlan cni to allocate IP to the main network of the POD will cause waste of IP addresses.
[0012] According to an embodiment of the present invention, a method for responding to an access request is provided, comprising: obtaining an external network segment to be allocated corresponding to a container cloud, wherein the external network segment to be allocated comprises: a plurality of external network IP addresses to be allocated; determining a target network segment in the same network segment as the node IP address in the external network segment to be allocated according to the node IP address of the target node; allocating the external network IP address to be allocated in the target network segment to the target node; and selecting a target IP address from the plurality of external network IP addresses to be allocated in the target network segment when a first POD in the target node receives an access request sent by the external network, and responding to the access request through the target IP address.
[0013] In an exemplary embodiment, a target network segment that is located in the same network segment as the node IP address is determined in the external network segment to be allocated based on the node IP address of the target node, including: determining a first mask corresponding to the node IP address; performing an AND operation on the node IP address and the first mask to obtain a first result, and performing an AND operation on the IP address in the external network segment and the first mask to obtain a second result; determining a third result consistent with the first result in the second result, and using the external network segment corresponding to the third result as the target network segment that is located in the same network segment as the node IP address.
[0014] In an exemplary embodiment, allocating the external IP address to be allocated in the target network segment to the target node includes: annotating the target network segment to the target node in a preset manner; and when the target network segment is successfully annotated to the target node, determining that the external IP address to be allocated in the target network segment is an available IP address for the target node.
[0015] In an exemplary embodiment, after allocating multiple external IP addresses to be allocated in the target network segment to the target node, the method further includes: determining whether interaction is required between any two nodes in a container cloud, the container cloud including the target node; in the case where it is determined that interaction is required between any two nodes in the container cloud, notifying the target server to create the first POD in the container cloud, and creating annotation information for the first POD, wherein the annotation information is used to indicate whether the first POD requires an external IP address; in the case where the target server successfully creates the first POD and the annotation information of the first POD, determining whether to allocate the first POD to a node in the container cloud according to the annotation information of the first POD.
[0016] In an exemplary embodiment, determining whether to assign the first POD to a node in a container cloud is performed based on annotation information of the first POD, including: when it is determined based on the annotation information of the first POD that the first POD needs an external network IP address, determining to assign the first POD to a node in the container cloud that has an external network IP address to be assigned; when it is determined based on the annotation information of the first POD that the first POD does not need an external network IP address, determining to assign the first POD to any one of all nodes in the container cloud.
[0017] In an exemplary embodiment, after allocating the external IP address to be allocated in the target network segment to the target node, the method further includes: returning an allocation result for the first POD according to the annotation information of the first POD, wherein the allocation result indicates at least one of the following: a target IP address allocated to the first POD, or a null value; when the allocation result indicates the target IP address allocated to the first POD, setting the external network card of the first POD, wherein the IP address of the external network card is the target IP address; creating an external network routing table for the first POD according to the external network card of the first POD, so that when the external network sends an access request to the first POD, the access request is responded to according to the external network routing table.
[0018] In an exemplary embodiment, an external network routing table of the first POD is created according to the external network card of the first POD, including: matching the source IP of the external network routing table to the IP address of the external network card; setting the default route in the external network routing table to the external network card, and when the first POD in the target node receives an access request sent by the external network, responding to the access request through the external network card.
[0019] In an exemplary embodiment, after creating the external network routing table of the first POD according to the external network network card of the first POD, the method further includes: assigning a target intranet IP address to the first POD; setting the intranet network card of the first POD, wherein the IP address of the intranet network card is the target intranet IP address; creating the intranet routing table of the first POD according to the intranet network card of the first POD, so that when the first POD in the target node accesses other PODs in the intranet node, the target message is sent according to the intranet routing table, wherein the source IP address of the intranet routing table is the IP address of the intranet network card.
[0020] According to another embodiment of the embodiment of the present invention, there is also provided a device for responding to access requests, including: an acquisition module, used to acquire an external network segment to be allocated corresponding to a container cloud, wherein the external network segment to be allocated includes: multiple external network IP addresses to be allocated; a determination module, used to determine a target network segment in the same network segment as the node IP address in the external network segment to be allocated according to the node IP address of the target node; an allocation module, used to allocate the external network IP address to be allocated in the target network segment to the target node; and a response module, used to select a target IP address from the multiple external network IP addresses to be allocated in the target network segment when the first POD in the target node receives an access request sent by the external network, and respond to the access request through the target IP address.
[0021] According to another aspect of an embodiment of the present invention, a computer-readable storage medium is provided, in which a computer program is stored, wherein the computer program is configured to execute the above-mentioned access request response method when running.
[0022] According to another aspect of an embodiment of the present invention, there is provided an electronic device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the access request response method through the computer program.
[0023] In an embodiment of the present invention, an external network segment to be allocated corresponding to a container cloud is obtained, wherein the external network segment to be allocated includes: a plurality of external network IP addresses to be allocated; a target network segment located in the same network segment as the node IP address is determined in the external network segment to be allocated according to the node IP address of the target node; the external network IP address to be allocated in the target network segment is allocated to the target node; when the first POD in the target node receives an access request sent by the external network, a target IP address is selected from the plurality of external network IP addresses to be allocated in the target network segment, and the access request is responded to through the target IP address; the above-mentioned technical scheme is adopted to solve the problem that using macvlan or ipvlan cni to allocate IP to the main network of the POD will cause a waste of IP addresses, and further, the technical scheme of the present invention is used to achieve on-demand allocation of IP addresses and reduce unnecessary waste of IP resources. BRIEF DESCRIPTION OF THE DRAWINGS
[0024] The drawings described herein are used to provide a further understanding of the present invention and constitute a part of this application. The exemplary embodiments of the present invention and their descriptions are used to explain the present invention and do not constitute an improper limitation of the present invention. In the drawings:
[0025] Figure 1 It is a schematic diagram of the interconnection between the internal and external networks in the EIP mode in the prior art of the present invention;
[0026] Figure 2 It is a schematic diagram of the interconnection between the internal and external networks in a single network card mode in the prior art of the present invention;
[0027] Figure 3 It is a schematic diagram of the interconnection between internal and external networks in the prior art of allocating multiple network cards;
[0028] Figure 4 It is a hardware structure block diagram of a computer terminal of a method for responding to an access request according to an embodiment of the present invention;
[0029] Figure 5 is a flowchart of a method for responding to an access request according to an embodiment of the present invention;
[0030] Figure 6 is a schematic diagram of a method for responding to an access request according to an optional embodiment of the present invention (I);
[0031] Figure 7 is a schematic diagram of a method for responding to an access request according to an optional embodiment of the present invention (II);
[0032] Figure 8 is a schematic diagram of a method for responding to an access request according to an optional embodiment of the present invention (III);
[0033] Fig. 9 is a timing diagram of a method for responding to an access request according to an optional embodiment of the present invention;
[0034] Fig.10 is a schematic diagram of a method for responding to an access request according to an optional embodiment of the present invention (IV);
[0035] Fig.11 It is a structural block diagram of a device for responding to an access request according to an embodiment of the present invention. DETAILED DESCRIPTION
[0036] 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.
[0037] 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 that the embodiments of the present invention described herein can be implemented in an order other than those illustrated or 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 that are clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.
[0038] The method embodiments provided in the embodiments of the present application can be executed in a mobile terminal, a computer terminal or a similar computing device. Taking running on a computer terminal as an example, Figure 4 FIG. 1 is a hardware structure block diagram of a computer terminal of a method for responding to an access request according to an embodiment of the present invention. Figure 1 As shown, the computer terminal may include one or more ( Figure 1 Only one is shown in the figure) processor 102 (processor 102 may include but is not limited to a processing device such as a microprocessor MCU or a programmable logic device FPGA) and a memory 104 for storing data. In an exemplary embodiment, the computer terminal may also include a transmission device 106 and an input / output device 108 for communication functions. It can be understood by those skilled in the art that Figure 1The structure shown is only for illustration and does not limit the structure of the above-mentioned computer terminal. Figure 1 More or fewer components as shown, or with Figure 1 Equivalent functions or comparisons shown Figure 1 A different configuration with more features is shown.
[0039] The memory 104 can be used to store computer programs, for example, software programs and modules of application software, such as the computer program corresponding to the access request response method in the embodiment of the present invention. The processor 102 executes various functional applications and data processing by running the computer program stored in the memory 104, that is, to implement the above method. The memory 104 may include a high-speed random access memory, and may also include a non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some examples, the memory 104 may further include a memory remotely arranged relative to the processor 102, and these remote memories can be connected to the computer terminal 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.
[0040] The transmission device 106 is used to receive or send data via a network. The specific example of the above network may include a wireless network provided by a communication provider of a computer terminal. In one example, the transmission device 106 includes a network adapter (Network Interface Controller, referred to as NIC), which can be connected to other network devices through a base station so as to communicate with the Internet. In one example, the transmission device 106 can be a radio frequency (RF) module, which is used to communicate with the Internet wirelessly.
[0041] In this embodiment, a method for responding to an access request is provided, which is applied to the above-mentioned computer terminal. Figure 5 : is a flowchart of a method for responding to an access request according to an embodiment of the present invention, and the process includes the following steps:
[0042] Step S502, obtaining an external network segment to be allocated corresponding to the container cloud, wherein the external network segment to be allocated includes: a plurality of external network IP addresses to be allocated;
[0043] Step S504, determining a target network segment that is located in the same network segment as the node IP address in the external network segment to be allocated according to the node IP address of the target node;
[0044] Step S506, allocating the external network IP address to be allocated in the target network segment to the target node;
[0045] Step S508, when the first POD in the target node receives an access request sent by the external network, it selects a target IP address from multiple external IP addresses to be allocated in the target network segment, and responds to the access request through the target IP address.
[0046] Through the above steps, the external network segment to be allocated corresponding to the container cloud is obtained, wherein the external network segment to be allocated includes: multiple external network IP addresses to be allocated; according to the node IP address of the target node, the target network segment located in the same network segment as the node IP address is determined in the external network segment to be allocated; the external network IP address to be allocated in the target network segment is allocated to the target node; when the first POD in the target node receives an access request sent by the external network, the target IP address is selected from the multiple external network IP addresses to be allocated in the target network segment, and the access request is responded to through the target IP address, which solves the problem in the related art that using macvlan or ipvlan cni to allocate IP to the main network of the POD will cause waste of IP addresses, and then the technical solution of the present invention achieves on-demand allocation of IP addresses and reduces unnecessary waste of IP resources.
[0047] In an exemplary embodiment, a target network segment that is located in the same network segment as the node IP address is determined in the external network segment to be allocated based on the node IP address of the target node, including: determining a first mask corresponding to the node IP address; performing an AND operation on the node IP address and the first mask to obtain a first result, and performing an AND operation on the IP address in the external network segment and the first mask to obtain a second result; determining a third result consistent with the first result in the second result, and using the external network segment corresponding to the third result as the target network segment that is located in the same network segment as the node IP address.
[0048] It should be noted that the above embodiment records a method for determining a target network segment in the same network segment as the node IP address in the external network segment to be allocated, specifically: calculating the first mask of the node IP address and the second masks corresponding to the multiple network segments respectively, determining a consistent third mask among the multiple second masks according to the first mask, and allocating the network segment corresponding to the third mask to the target node, that is, all IPs in the target network segment are in the same network segment as the target node; for example, the IP of node 1 is: 10.37.0. 12 / 24, network segment 1 is: 10.37.0.200-10.37.0.220, then the support network segment 1 is recorded in the node 1 annotation; the IP of node 2 is: 10.45.0.12 / 24, network segment 1 is: 10.32.0.200-10.32.0.220, then node 2 has no network segment support, that is, node 2 has no IP resources. It should be noted that the above IP addresses and network segments are only for a better understanding of the embodiments of the present invention, and the embodiments of the present invention are not limited to this.
[0049] In an exemplary embodiment, allocating the external IP address to be allocated in the target network segment to the target node includes: annotating the target network segment to the target node in a preset manner; and when the target network segment is successfully annotated to the target node, determining that the external IP address to be allocated in the target network segment is an available IP address for the target node.
[0050] Through a preset method, such as annotation, the target network segment is annotated to the target node, marked as an available IP resource for the target node, and written to the storage system etcd through CRD.
[0051] In an exemplary embodiment, after allocating multiple external IP addresses to be allocated in the target network segment to the target node, it is determined whether any two nodes in the container cloud need to interact, and the container cloud includes the target node; when it is determined that any two nodes in the container cloud need to interact, the target server is notified to create the first POD in the container cloud, and to create annotation information for the first POD, wherein the annotation information is used to indicate whether the first POD needs an external IP address; when the target server successfully creates the first POD and the annotation information of the first POD, it is determined whether to allocate the first POD to a node in the container cloud according to the annotation information of the first POD.
[0052] Specifically, fill in the template whether any two nodes in the container cloud need to be interconnected, then notify the api-server to create the first Pod, and determine whether the first POD needs an external IP address, and determine the allocation of the first POD based on whether the first POD needs an external IP address.
[0053] In an exemplary embodiment, determining whether to assign the first POD to a node in a container cloud is performed based on annotation information of the first POD, including: when it is determined based on the annotation information of the first POD that the first POD needs an external network IP address, determining to assign the first POD to a node in the container cloud that has an external network IP address to be assigned; when it is determined based on the annotation information of the first POD that the first POD does not need an external network IP address, determining to assign the first POD to any one of all nodes in the container cloud.
[0054] It should be noted that the scheduler has added a new scheduling IP resource scheduling module. If the first POD needs an external IP address, the first node can only be allocated to the node when there are IP resources on the node. However, if the POD does not need an external IP address, the first POD will be directly allocated to the node.
[0055] For example, when creating the first POD and the second POD: the first POD does not need to be configured with an external network IP, so node1 and node2 will pass the scheduler filtering and can eventually be scheduled to node1 and node22. The second POD needs to be configured with an external network. During the filtering stage, node2 cannot run the second POD because it does not have an external network IP resource. After IP resource filtering, the second POD can only be scheduled to node1.
[0056] In an exemplary embodiment, after the external IP address to be allocated in the target network segment is allocated to the target node, the allocation result for the first POD is returned according to the annotation information of the first POD, wherein the allocation result indicates at least one of the following: the target IP address allocated to the first POD, or a null value; when the allocation result indicates the target IP address allocated to the first POD, the external network card of the first POD is set, wherein the IP address of the external network card is the target IP address; an external network routing table of the first POD is created according to the external network card of the first POD, so that when the external network sends an access request to the first POD, the access request is responded to according to the external network routing table.
[0057] After allocating the external IP address to be allocated in the target network segment to the target node and allocating the first POD to the target node, if the first POD needs an external IP address, allocate the target IP address to the first POD; if the first POD does not need an external IP address, allocate a null value to the first POD; in the case of the target IP address allocated to the first POD, use the target IP address as the source IP address of the external routing table to establish the external routing table.
[0058] In one embodiment, an external network routing table of the first POD is created according to the external network card of the first POD, including: matching the source IP of the external network routing table to the IP address of the external network card; setting the default route in the external network routing table to the external network card, and when the first POD in the target node receives an access request sent by the external network, responding to the access request through the external network card.
[0059] For example, assume that the external network card is named net0, configure a new routing table, the routing table ID is smaller than the system-created routing table ID, and match the source IP address to the external network card IP address. Then set the default route of the external network routing table to go through net0, so as to send the target message to the second POD through the IP address of the external network card. Compared with using multus to allocate multiple network cards, the embodiment of the present invention uses policy routing to solve the asymmetric routing of multiple network cards in POD; and the embodiment of the present invention is based on the cloud-native chained CNI mechanism. Compared with the multus mechanism, the CNIs under the chained CNI mechanism are more loosely coupled, which is convenient for flexible replacement according to business needs.
[0060] In an exemplary embodiment, after creating the external network routing table of the first POD according to the external network card of the first POD, the target intranet IP address is assigned to the first POD; the intranet network card of the first POD is set, wherein the IP address of the intranet network card is the target intranet IP address; the intranet routing table of the first POD is created according to the intranet network card of the first POD, so that when the first POD in the target node accesses other PODs in the intranet node, the target message is sent according to the intranet routing table, wherein the source IP address of the intranet routing table is the IP address of the intranet network card. The intra-cluster communication of the container cloud does not go through the tunnel, and the access to the external network IP outside the cluster of the container cloud does not need to go through the container cloud.
[0061] The calico-ipam plug-in assigns an intranet IP address to the first POD. The calico plug-in creates an intranet network card and sets the intranet routing table and the default intranet route of the first POD.
[0062] Furthermore, when it is determined to delete the first POD, the resource item corresponding to the target IP address is marked as idle, and the external network card and the external network routing table are deleted to prohibit other PODs in the target node from accessing other nodes in the external network, and the target message is sent according to the external network routing table.
[0063] In order to better understand the process of the method for responding to the access request above, the implementation method flow of the response to the access request above is described below in combination with an optional embodiment, but it is not intended to limit the technical solution of the embodiment of the present invention.
[0064] In this embodiment, a method for responding to an access request is provided. In this embodiment, a macvlan network card is used as the external network card of the POD, and a network card allocated by calico is used as the internal network card of the POD. Figure 6 is a schematic diagram of a method for responding to an access request according to an optional embodiment of the present invention (I), such as Figure 6 As shown in the figure, nodes in the container cloud can access each other through the second and third layer networks, and each node can cross network segments.
[0065] The following describes the process of starting a multi-NIC POD. The specific steps are as follows:
[0066] Step 1: The administrator collects available external network segment information (equivalent to the external network segment to be allocated in the above embodiment) and saves it to the cluster storage system etcd through crd. If the node can support a certain network segment, the so-called support means that all IPs in the network segment are in the same network segment as the node (it can also be understood as using the node's mask), and the network segment is annotated to the corresponding node through annotation, marking it as an available IP resource for the node. Figure 7 is a schematic diagram (II) of a method for responding to an access request according to an optional embodiment of the present invention, such as Figure 7 As shown in the figure, the administrator has planned three available external network segments in advance and written them to etcd in crd. At this time, it is necessary to record the support of seg1 in the node1 annotation and the support of seg2 in the node2 annotation, while seg3 has no node to support and node3 has no network segment to support. In other words, node1 and node2 have IP resources, but node3 has no IP resources.
[0067] Step 2: Fill in the template whether each node needs to be interconnected, and then notify the api-server to create a Pod (equivalent to the first POD in the above embodiment);
[0068] Step 3: The scheduler adds a new scheduling module for ip resources. If the POD needs an external IP address, the node can pass the filter only if the ip resource exists on the node. If the POD does not need an external IP value, it will pass the filter directly.
[0069] Figure 8 Schematic diagram (III) of a method for responding to an access request according to an optional embodiment of the present invention, such as Figure 8 As shown in the figure, the user creates POD1 and POD2. POD1 does not need to be configured with an external network IP address. Then both node1 and node2 will pass through the scheduler filtering (that is, the filter stage), and there may be other scheduling processes (which can be other filters or scores, etc.), and finally it is assumed that they are scheduled to node2. However, POD2 needs to be configured with an external network. In the filtering stage, node2 cannot run POD2 because it does not have an external network IP resource. After IP resource filtering, POD2 can only be scheduled to node1.
[0070] Step 4: After the scheduler assigns the POD to the specified node, kubelet will create a container runtime environment for the POD. During this process, cni will be called to create a network (specifically, the cmdAdd method in these cni will be called), such as Fig. 9 As shown, the specific steps are as follows:
[0071] Step S401: cni runtime sends a request to dhc-ipam to add a network;
[0072] Step S402: dhc-ipam confirms whether an external IP address is needed based on the POD annotation. If an external IP address is needed, an available external IP address is determined, recorded in the returned result, and marked as used in the resource item corresponding to the IP address; if an external IP address is not needed, a null value is directly returned;
[0073] Step S403: cni runtime sends a request to dhc-macvlan to add a network;
[0074] Step S404: dhc-macvlan returns directly based on the return result of dhc-ipam if the result is null; if the result is not null, it is necessary to set up a macvlan network card (equivalent to the external network card in the above embodiment), the IP address is taken from the return result of dhc-ipam, and the network card name and configuration are taken from the network configuration file (the network card name cannot be eth0). In addition to the system route generated by the macvlan network card, the plug-in will perform policy routing settings. For example, the macvlan network card is named net0, and a new routing table is configured with an ID smaller than the system-created routing table, matching the source IP address of the net0 network card IP address. Then fill in the default route of this routing table so that all routes go through net0, so that the source IP address is the net0 network card IP address, and all responses to access requests from the external network go through the net0 network card.
[0075] Step S405: calico and calico-ipam completely use the calico native image. The calico-ipam plug-in assigns an intranet IP to the POD.
[0076] Step S406: The calico plug-in creates a veth pair network card (equivalent to the intranet network card in the above embodiment) and sets relevant rules, including the default route of the POD.
[0077] After the multi-NIC POD is created, the intranet and extranet interconnection between the multi-NIC PODs is as follows: Fig.10 As shown. It should be noted that when the source IP is the macvlan network card IP, macvlan is used as its default route; in other cases, the default route set by calico is used as its default route; when the Pod actively accesses the external network, the default route will point to the calico route to enter the cluster. At this time, the path needs to pass through the host, but the return path is still the calico network card, and no asymmetric routing will be generated. To access the Pod within the cluster, the BGP route of calico is the underlay path, which has better performance and a simpler network, so access within the cluster should use the intranet access.
[0078] Step 5: When the Pod is deleted, the cni in step 4 is called to delete the network.
[0079] Specifically, if dhc-ipam uses an external network card, it needs to be marked as free in the resource item corresponding to the IP; if dhc-macvlan has a macvlan network card, the macvlan network card and related rules will be destroyed; calico and calico-ipam will destroy the internal network card and related rules.
[0080] Compared with using multus to allocate multiple network cards, the embodiment of the present invention uses policy routing to solve the asymmetric routing of multiple network cards in POD; and the embodiment of the present invention is based on the cloud-native chained CNI mechanism. Compared with the multus mechanism, the CNIs under the chained CNI mechanism are more loosely coupled, which is convenient for flexible replacement according to business needs. Compared with the single network card macvlan / ipvlan solution, the embodiment of the present invention perfectly supports container cloud multi-segment node management and IP on-demand allocation, and the cluster arp broadcast messages are less. Compared with the use of EIP, the embodiment of the present invention does not use overlay in the cluster through intranet IP communication, and does not need to go through NAT after accessing the external network IP outside the cluster, and the performance is better under the same physical machine and kernel configuration. In the private cloud scenario, the embodiment of the present invention further provides a method for using the planned private network available IP address resources, which does not require additional operations such as account IP binding, and is more convenient to use.
[0081] Through the description of the above implementation methods, those skilled in the art can clearly understand that the method according to the above embodiment can be implemented by means of software plus a necessary general hardware platform, and of course can also be implemented by hardware, but in many cases the former is a better implementation method. Based on such an understanding, the technical solution of the present invention is essentially or the part that contributes to the prior art can be embodied in the form of a software product, which is stored in a storage medium (such as ROM / RAM, a magnetic disk, or an optical disk), and includes a number of instructions for a terminal device (which can be a mobile phone, a computer, a server, or a network device, etc.) to execute the methods of various embodiments of the present invention.
[0082] In this embodiment, a response device for access request is also provided, and the response device for access request is used to implement the above-mentioned embodiment and preferred implementation mode, and the descriptions have been made no further. As used below, the term "module" can implement a combination of software and / or hardware of a predetermined function. Although the device described in the following embodiments is preferably implemented in software, the implementation of hardware, or a combination of software and hardware is also possible and conceivable.
[0083] Fig.11 is a structural block diagram of a device for responding to an access request according to an embodiment of the present invention; Fig.11 As shown, including:
[0084] The acquisition module 1102 is used to acquire an external network segment to be allocated corresponding to the container cloud, wherein the external network segment to be allocated includes: a plurality of external network IP addresses to be allocated;
[0085] A determination module 1104 is used to determine, according to the node IP address of the target node, a target network segment in the external network segment to be allocated that is located in the same network segment as the node IP address;
[0086] An allocating module 1106 is used to allocate the external network IP address to be allocated in the target network segment to the target node;
[0087] The response module 1108 is used to select a target IP address from multiple external IP addresses to be allocated in the target network segment when the first POD in the target node receives an access request sent by the external network, and respond to the access request through the target IP address.
[0088] Through the above-mentioned device, the external network segment to be allocated corresponding to the container cloud is obtained, wherein the external network segment to be allocated includes: multiple external network IP addresses to be allocated; according to the node IP address of the target node, the target network segment located in the same network segment as the node IP address is determined in the external network segment to be allocated; the external network IP address to be allocated in the target network segment is allocated to the target node; when the first POD in the target node receives an access request sent by the external network, the target IP address is selected from the multiple external network IP addresses to be allocated in the target network segment, and the access request is responded to through the target IP address, which solves the problem in the related art that using macvlan or ipvlan cni to allocate IP to the main network of the POD will cause waste of IP addresses, and then the technical solution of the present invention achieves on-demand allocation of IP addresses and reduces unnecessary waste of IP resources.
[0089] In an exemplary embodiment, the determination module is also used to determine a first mask corresponding to the node IP address and a second mask corresponding to the external network segment to be allocated; determine a third mask consistent with the first mask in the second mask, and use the external network segment corresponding to the third mask as the target segment that is in the same segment as the node IP address.
[0090] In an exemplary embodiment, the allocation module is also used to annotate the target network segment to the target node in a preset manner; when the target network segment is successfully annotated to the target node, determine that the external network IP address to be allocated in the target network segment is an available IP address of the target node.
[0091] In an exemplary embodiment, the determination module is also used to determine whether interaction is required between any two nodes in the container cloud, which includes the target node; when it is determined that interaction is required between any two nodes in the container cloud, the target server is notified to create the first POD in the container cloud, and to create annotation information for the first POD, wherein the annotation information is used to indicate whether the first POD requires an external network IP address; when the target server successfully creates the first POD and the annotation information of the first POD, it is determined whether to assign the first POD to a node in the container cloud according to the annotation information of the first POD.
[0092] In an exemplary embodiment, the determination module is also used to determine that the first POD is assigned to a node in the container cloud with an external IP address to be assigned when it is determined according to the annotation information of the first POD that the first POD needs an external IP address; and to determine that the first POD is assigned to any one of all the nodes in the container cloud when it is determined according to the annotation information of the first POD that the first POD does not need an external IP address.
[0093] In an exemplary embodiment, the allocation module is also used to return an allocation result for the first POD based on the annotation information of the first POD, wherein the allocation result indicates at least one of the following: a target IP address assigned to the first POD, or a null value; when the allocation result indicates the target IP address assigned to the first POD, setting the external network card of the first POD, wherein the IP address of the external network card is the target IP address; creating an external network routing table for the first POD based on the external network card of the first POD, so that when the external network sends an access request to the first POD, the access request is responded to according to the external network routing table.
[0094] In an exemplary embodiment, the determination module is also used to match the source IP of the external network routing table to the IP address of the external network card; set the default route in the external network routing table to the external network card, and when the first POD in the target node receives an access request sent by the external network, respond to the access request through the external network card.
[0095] In an exemplary embodiment, the allocation module is also used to allocate a target intranet IP address to the first POD; set the intranet network card of the first POD, wherein the IP address of the intranet network card is the target intranet IP address; create an intranet routing table of the first POD according to the intranet network card of the first POD, so that when the first POD in the target node accesses other PODs in the intranet node, the target message is sent according to the intranet routing table, wherein the source IP address of the intranet routing table is the IP address of the intranet network card.
[0096] An embodiment of the present invention further provides a storage medium, which includes a stored program, wherein the program executes any of the above methods when it is run.
[0097] Optionally, in this embodiment, the storage medium may be configured to store program codes for executing the following steps:
[0098] S1, obtaining an external network segment to be allocated corresponding to the container cloud, wherein the external network segment to be allocated includes: a plurality of external network IP addresses to be allocated;
[0099] S2, determining a target network segment in the same network segment as the node IP address in the external network segment to be allocated according to the node IP address of the target node;
[0100] S3, allocating the external network IP address to be allocated in the target network segment to the target node;
[0101] S4, when the first POD in the target node receives an access request sent by the external network, it selects a target IP address from multiple external IP addresses to be allocated in the target network segment, and responds to the access request through the target IP address.
[0102] An embodiment of the present invention further provides an electronic device, including a memory and a processor, wherein a computer program is stored in the memory, and the processor is configured to run the computer program to execute the steps in any one of the above method embodiments.
[0103] Optionally, the electronic device may further include a transmission device and an input / output device, wherein the transmission device is connected to the processor, and the input / output device is connected to the processor.
[0104] Optionally, in this embodiment, the processor may be configured to perform the following steps through a computer program:
[0105] S1, obtaining an external network segment to be allocated corresponding to the container cloud, wherein the external network segment to be allocated includes: a plurality of external network IP addresses to be allocated;
[0106] S2, determining a target network segment in the same network segment as the node IP address in the external network segment to be allocated according to the node IP address of the target node;
[0107] S3, allocating the external network IP address to be allocated in the target network segment to the target node;
[0108] S4, when the first POD in the target node receives an access request sent by the external network, it selects a target IP address from multiple external IP addresses to be allocated in the target network segment, and responds to the access request through the target IP address.
[0109] Optionally, in this embodiment, the above-mentioned storage medium may include but is not limited to: a USB flash drive, a read-only memory (ROM), a random access memory (RAM), a mobile hard disk, a magnetic disk or an optical disk, and other media that can store program codes.
[0110] Optionally, the specific examples in this embodiment may refer to the examples described in the above embodiments and optional implementation modes, and this embodiment will not be described in detail here.
[0111] Obviously, those skilled in the art should understand that the above modules or steps of the present invention can be implemented by a general computing device, they can be concentrated on a single computing device, or distributed on a network composed of multiple computing devices, and optionally, they can be implemented by a program code executable by a computing device, so that they can be stored in a storage device and executed by the computing device, and in some cases, the steps shown or described can be executed in a different order than here, or they can be made into individual integrated circuit modules, or multiple modules or steps therein can be made into a single integrated circuit module for implementation. Thus, the present invention is not limited to any specific combination of hardware and software.
[0112] The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. For those skilled in the art, the present invention may have various modifications and variations. Any modification, equivalent replacement, improvement, etc. made within the principle of the present invention shall be included in the protection scope of the present invention.
Claims
1. A method for responding to an access request, characterized in that: include: Obtain an external network segment to be allocated corresponding to the container cloud, wherein the external network segment to be allocated includes: multiple external network IP addresses to be allocated; Determine, according to the node IP address of the target node, a target network segment in the external network segment to be allocated that is located in the same network segment as the node IP address; Allocate the external network IP address to be allocated in the target network segment to the target node; When the first POD in the target node receives an access request sent by the external network, it selects a target IP address from a plurality of external IP addresses to be allocated in the target network segment, and responds to the access request through the target IP address; Among them, after the external IP address to be allocated in the target network segment is allocated to the target node, the first POD is allocated to the target node. When the first POD needs an external IP address, the target IP address is allocated to the first POD; when the first POD does not need an external IP address, a null value is allocated to the first POD.
2. The method for responding to an access request according to claim 1, characterized in that: Determining a target network segment located in the same network segment as the node IP address in the external network segment to be allocated according to the node IP address of the target node, including: Determine a first mask corresponding to the node IP address; Performing an AND operation on the node IP address and the first mask to obtain a first result, and performing an AND operation on the IP address in the external network segment and the first mask to obtain a second result; A third result consistent with the first result is determined in the second result, and the external network segment corresponding to the third result is used as the target network segment that is located in the same network segment as the node IP address.
3. The method for responding to an access request according to claim 1, characterized in that: Allocating the external network IP address to be allocated in the target network segment to the target node includes: Annotating the target network segment to the target node in a preset manner; When the target network segment is successfully annotated to the target node, it is determined that the external network IP address to be allocated in the target network segment is an available IP address of the target node.
4. The method for responding to an access request according to claim 1, characterized in that: After allocating a plurality of to-be-allocated external network IP addresses in the target network segment to the target node, the method further comprises: Determine whether any two nodes in a container cloud need to interact, the container cloud including the target node; In the case where it is determined that any two nodes in the container cloud need to interact, the target server is notified to create the first POD in the container cloud, and to create annotation information of the first POD, wherein the annotation information is used to indicate whether the first POD needs an external network IP address; In the case that the target server successfully creates the first POD and the annotation information of the first POD, it is determined whether to allocate the first POD to a node in the container cloud according to the annotation information of the first POD.
5. The method for responding to an access request according to claim 4, characterized in that: Determining whether to allocate the first POD to a node in the container cloud according to the annotation information of the first POD includes: In a case where it is determined according to the annotation information of the first POD that the first POD needs an external network IP address, determining to allocate the first POD to a node in the container cloud that has an external network IP address to be allocated; When it is determined according to the annotation information of the first POD that the first POD does not need an external network IP address, it is determined to allocate the first POD to any node among all the nodes in the container cloud.
6. The method for responding to an access request according to claim 1, characterized in that: After allocating the external network IP address to be allocated in the target network segment to the target node, the method further includes: Returning an allocation result for the first POD according to the annotation information of the first POD, wherein the allocation result indicates at least one of the following: a target IP address allocated to the first POD, or a null value; In the case where the allocation result indicates a target IP address allocated to the first POD, setting an external network card of the first POD, wherein the IP address of the external network card is the target IP address; An external network routing table of the first POD is created according to the external network card of the first POD, so that when the external network sends an access request to the first POD, the access request is responded to according to the external network routing table.
7. The method for responding to an access request according to claim 6, characterized in that: Creating an external network routing table of the first POD according to the external network card of the first POD includes: The source IP matching the external network routing table is the IP address of the external network card; The default route in the external network routing table is set to the external network card, and when the first POD in the target node receives an access request sent by the external network, the first POD responds to the access request through the external network card.
8. The method for responding to an access request according to claim 6, characterized in that: After creating the external network routing table of the first POD according to the external network card of the first POD, the method further includes: Allocate a target intranet IP address to the first POD; Setting the intranet network card of the first POD, wherein the IP address of the intranet network card is the target intranet IP address; An intranet routing table of the first POD is created according to the intranet network card of the first POD, so that when the first POD in the target node accesses other PODs in the intranet node, the target message is sent according to the intranet routing table, wherein the source IP address of the intranet routing table is the IP address of the intranet network card.
9. A device for responding to an access request, characterized in that: include: An acquisition module is used to acquire an external network segment to be allocated corresponding to the container cloud, wherein the external network segment to be allocated includes: a plurality of external network IP addresses to be allocated; A determination module, configured to determine, according to the node IP address of the target node, a target network segment in the external network segment to be allocated that is located in the same network segment as the node IP address; An allocation module, configured to allocate the external network IP address to be allocated in the target network segment to the target node; A response module, configured to select a target IP address from a plurality of to-be-allocated external IP addresses in the target network segment and respond to the access request through the target IP address when the first POD in the target node receives an access request sent by the external network; Among them, the allocation module is used to allocate the first POD to the target node. When the first POD needs an external network IP address, the target IP address is allocated to the first POD; when the first POD does not need an external network IP address, a null value is allocated to the first POD.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium includes a stored program, wherein the program executes the method described in any one of claims 1 to 8 when executed.
