Method for creating physical network, related device, electronic equipment and storage medium
By automatically selecting the virtual network device with the largest number of idle IPs by the callback plugin to create a physical network for the target service node, the low construction efficiency caused by manually specifying the virtual network device name in the existing technology is solved, and more efficient physical network construction and reasonable IP address allocation are achieved.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- SHENZHEN LEXIN SOFTWARE TECH CO LTD
- Filing Date
- 2023-09-15
- Publication Date
- 2026-04-10
AI Technical Summary
In existing technologies, when creating a physical network for enterprise service nodes, it is necessary to manually specify the virtual network device name, resulting in low efficiency in physical network construction.
The callback plugin automatically determines whether the target service node's tag file contains a physical network tag and obtains the number of idle IPs of the virtual network device. It then automatically selects the virtual network device with the largest number of idle IPs to create a physical network for the target service node.
It improves the efficiency of physical network construction, optimizes the allocation of virtual network devices, reduces the steps of manual specification, and ensures the reasonable allocation of IP addresses.
Smart Images

Figure CN117081888B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of container network, and particularly relates to a method for creating a physical network, a related device, an electronic device and a storage medium. BACKGROUND
[0002] The basic network of some enterprises is a layer 2 network, and the layer 2 network does not support a Border Gateway Protocol (BGP). In this case, if the enterprise deploys services in the form of service nodes (pods) in a cluster, in order to enable the service nodes to communicate with services outside the cluster, a physical network (Macvlan network) needs to be built for the service nodes.
[0003] In an existing physical network solution, a Classless Inter-Domain Routing (CIDR) pool (a virtual network device cluster) allocated to a cluster network includes multiple virtual network devices (vlan virtual devices), each of which corresponds to multiple IP addresses. When a physical network is created for a service node, a code needs to be manually written to specify the virtual network device name of the service node, and the virtual network device name needs to be written into a container network creation request, so as to determine which IP address of which virtual network device to use to build the physical network for the service node. Therefore, in the prior art, the process of creating a physical network for a service node is relatively cumbersome, resulting in low efficiency of building a physical network. SUMMARY
[0004] The embodiments of the present application provide a method for creating a physical network, a related device, an electronic device and a storage medium, which can improve the efficiency of building a physical network.
[0005] In a first aspect, the embodiments of the present application provide a method for creating a physical network, which is applied to a container network creation device in a k8s cluster, the container network creation device includes a callback plug-in, a network configuration plug-in and a physical network plug-in, and the method includes the following steps.
[0006] When the callback plug-in listens to a creation event of a target service node, the callback plug-in judges whether a physical network label is contained in a target marker file, and the target marker file is a marker file corresponding to the target service node;
[0007] If the physical network label is contained in the target marker file, the callback plug-in acquires the number of idle IP addresses of each virtual network device in a preset target virtual network device cluster;
[0008] The callback plug-in determines a virtual network device with the largest number of idle IPs as a target virtual network device, generates a target container network creation request according to a target virtual network device name of the target virtual network device, and sends the target container network creation request to the network configuration plug-in.
[0009] The network configuration plug-in invokes the physical network plug-in to create a physical network for the target service node according to the target container network creation request.
[0010] In a second aspect, the embodiments of the present application further provide a container network creation apparatus, which comprises a callback plug-in, a network configuration plug-in and a physical network plug-in.
[0011] The callback plug-in is configured to, when a creation event of a target service node is listened to, judge whether a physical network label is contained in a target marker file, the target marker file being a marker file corresponding to the target service node; if the physical network label is contained in the target marker file, obtain a number of idle IPs of each virtual network device in a preset target virtual network device cluster; determine a virtual network device with the largest number of idle IPs as a target virtual network device, generate a target container network creation request according to a target virtual network device name of the target virtual network device, and send the target container network creation request to the network configuration plug-in.
[0012] The network configuration plug-in is configured to invoke the physical network plug-in to create a physical network for the target service node according to the target container network creation request.
[0013] In a third aspect, the embodiments of the present application further provide an electronic device, which comprises a memory and a processor, the memory storing a computer program, and the processor implementing the above method when executing the computer program.
[0014] In a fourth aspect, the embodiments of the present application further provide a computer readable storage medium, which stores a computer program, the computer program comprising program instructions, and the program instructions being executable by a processor to implement the above method.
[0015] The embodiment of the present application provides a physical network creation method, a related device, an electronic device and a storage medium. The method is applied to a container network creation device in a k8s cluster, the container network creation device comprises a callback plug-in, a network configuration plug-in and a physical network plug-in, and the method comprises the following steps: when the callback plug-in listens to a creation event of a target service node, the callback plug-in judges whether a physical network label is contained in a target marker file, the target marker file is a marker file corresponding to the target service node; if the physical network label is contained in the target marker file, the callback plug-in acquires the number of idle IP addresses of each virtual network device in a preset target virtual network device cluster; the callback plug-in determines a virtual network device with the maximum number of idle IP addresses as a target virtual network device, generates a target container network creation request according to a target virtual network device name of the target virtual network device, and sends the target container network creation request to the network configuration plug-in; and the network configuration plug-in calls the physical network plug-in to create a physical network for the target service node according to the target container network creation request. In the embodiment of the present application, when the callback plug-in listens to the creation event of the target service node, it is automatically checked whether the physical network label is contained in the marker file corresponding to the target service node, if the physical network label is contained, the target virtual network device name of the target service node is automatically determined, and the target virtual network device name does not need to be manually specified. On the one hand, the target virtual network device name can be automatically determined when the target container network creation request is generated, and manual specification is not needed, so that the construction efficiency of the physical network is improved. On the other hand, the number of idle IP addresses corresponding to the target virtual network device selected by the embodiment is the maximum, the virtual network device with the larger number of idle IP addresses is preferentially selected, and the rationality of virtual network device allocation is improved. BRIEF DESCRIPTION OF DRAWINGS
[0016] In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings needed in the embodiment description will be briefly introduced. Obviously, the drawings in the following description are some embodiments of the present application, and other drawings can also be obtained by those skilled in the art without creative labor.
[0017] Figure 1 A flowchart of the physical network creation method provided by the embodiment of the present application is shown in the figure.
[0018] Figure 2 A data flow direction schematic diagram of the physical network creation method provided by the embodiment of the present application is shown in the figure.
[0019] Figure 3 A schematic block diagram of the container network creation device provided by the embodiment of the present application is shown in the figure.
[0020] Figure 4 A schematic block diagram of an electronic device according to an embodiment of the present application is provided. DETAILED DESCRIPTION
[0021] The technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the drawings in the embodiments of the present application. Obviously, the described embodiments are some of the embodiments of the present application but not all of the embodiments of the present application. Based on the embodiments in the present application, all other embodiments obtained by a person of ordinary skill in the art without creative effort are within the scope of protection of the present application.
[0022] It should be understood that, when used in the specification and the appended claims, the terms "comprise" and "include" indicate the presence of the described features, integers, steps, operations, elements, and / or components but do not preclude the presence or addition of one or more other features, integers, steps, operations, elements, components, and / or groups thereof.
[0023] It should also be understood that the terms used in the specification of the present application are only for the purpose of describing specific embodiments and are not intended to limit the present application. As used in the specification and the appended claims of the present application, unless otherwise clearly indicated by the context, the singular forms "a", "an" and "the" are intended to include the plural forms.
[0024] It should be further understood that the term "and / or" used in the specification and the appended claims of the present application means any combination of one or more of the associated listed items and all possible combinations thereof, and includes these combinations.
[0025] The embodiments of the present application provide a physical network creation method, related apparatus, electronic device and storage medium.
[0026] The container network creation method is applied to an electronic device, which can be a device with network connection function such as a router. Specifically, the electronic device in the embodiments is provided with a container network creation apparatus in a k8s (Kubernetes) cluster, which includes a callback plug-in, a cluster network plug-in, a network configuration plug-in, a physical network plug-in and an address allocation plug-in.
[0027] Some terms related to the embodiments of the present application are explained as follows:
[0028] Callback plug-in: can be a Webhook plug-in, which is an HTTP callback used to perform a specific action in a specific situation.
[0029] Network configuration plug-in: can be a Multus plug-in, which is a multi-network plug-in allowing a service node to use multiple network plug-ins simultaneously and select a suitable network interface for each service node. In this embodiment, the network configuration plug-in needs to call the cluster network plug-in to connect the newly created service node to the cluster network (i.e., create a cluster network) and call the physical network plug-in to create a virtual network card for the newly created service node and connect the virtual network to the underlying network (i.e., create a physical network). As can be seen, the network configuration plug-in in this embodiment can connect two sets of networks (cluster network and underlying network) for the service node.
[0030] Physical network plug-in: can be a Macvlan plug-in, which can virtually output multiple interfaces for a network card. In this embodiment, a virtual network device is set up on the target service node.
[0031] Cluster network plug-in: can be a Flannel plug-in, which is used to create a cluster network for a service node and enable intercommunication between containers in a k8s cluster.
[0032] Address allocation plug-in: can be an IPAM plug-in, specifically a Whereabouts plug-in in this application, which ensures that each service node has a usable IP address.
[0033] Service node: a pod in a k8s cluster, which includes at least one container. Containers in a pod share a network. In this embodiment, the target service node is a pod that currently needs to create a container network, i.e., a target pod.
[0034] Physical node: a Node node in a k8s cluster, which can host multiple pods. In this embodiment, the target physical node is the node where the target service node (target pod) is located.
[0035] Virtual network device: a vlan virtual device, which can be created under a physical node.
[0036] It should be noted that after receiving a target container network creation request for a target service node, the network configuration plug-in in this embodiment needs to generate a cluster network creation request and a physical network creation request based on the target container network creation request, call the cluster network plug-in to create a cluster network for the target service node based on the cluster network creation request, and call the physical network plug-in to create a physical network for the target service node based on the physical network creation request.
[0037] The step of creating a cluster network (creating a Flannel network, i.e., an Overlay network, in the target service node) for the target service node by the network configuration plug-in is a basic step of creating a container network in the service node in the cluster, and the embodiment of the application mainly describes the step of creating a physical network for the target service node by the network configuration plug-in.
[0038] Figure 1 FIG. 1 is a flowchart of a method for creating a physical network provided by the embodiment of the application. As shown in FIG. 1, the method includes the following steps S110-S140. Figure 1
[0039] S110, when the callback plug-in listens to a creation event of a target service node, the callback plug-in judges whether a physical network label is contained in a target marker file.
[0040] The target marker file is a marker file (a YAML file) corresponding to the target service node.
[0041] In the embodiment, the callback plug-in listens to a creation event of a service node in a k8s cluster, and when the creation event of the target service node is listened to, the callback plug-in actively checks whether a physical network label is contained in a target marker file corresponding to the target service node.
[0042] Specifically, in the embodiment, a user can set whether the target marker file contains the physical network label by specifying a value of the physical network label in the target marker file. When the user specifies that the value of the physical network label in the target marker file is true, it is indicated that the target marker file contains the physical network label. When the user specifies that the value of the physical network label is false, it is indicated that the target marker file does not contain the physical network label. When the target marker file does not contain the physical network label, it is indicated that the physical network does not need to be created for the target service node.
[0043] For example, when the Webhook plug-in listens to a creation event of a target pod, it is judged whether the value of a physical network label (a Mcavlan label) in a YAML file of the target pod is true. If the value is true, it is indicated that the YAML file contains the physical network label, and the physical network needs to be created for the target pod. If the value of the physical network label is false, it is indicated that the YAML file does not contain the physical network label, and the physical network does not need to be created for the target pod.
[0044] In some embodiments, the user can also specify in the target marker file whether the target service node needs external network when creating the target service node. At this time, when the callback plug-in listens to the creation event of the target service node, the callback plug-in checks whether there is a marker that needs to use external network when checking the target marker file corresponding to the target service node.
[0045] Specifically, in the embodiment, the user can specify in the target marker file that the value of the external network access permission tag determines whether the target service node needs external network. When the value of the external network access permission tag is true, it means that the target service node needs to use external network at this time, and the IP address that can access external network needs to be allocated to the target service node subsequently. When the value of the external network access permission tag is false, it means that the target service node does not need to use external network at this time, and the IP address that cannot access external network needs to be allocated to the target service node subsequently.
[0046] S120, if the target marker file contains the physical network tag, the callback plug-in obtains the idle IP quantity of each virtual network device in the preset target virtual network device cluster.
[0047] In the embodiment, if the target marker file contains the physical network tag, that is, the value of the physical network tag is true, the callback plug-in needs to further obtain the idle IP quantity of each virtual network device in the preset target virtual network device cluster at this time.
[0048] For example, when the value of the physical network tag in the YAML file of the target pod is true, the Webhook plug-in further obtains the idle IP quantity of each vlan virtual device in the target virtual network device cluster according to the preset rule.
[0049] In some embodiments, when the user sets the external network access permission tag in the target marker file, the target virtual network device cluster needs to be determined according to the external network access permission tag before the callback plug-in obtains the idle IP quantity of each virtual network device in the preset target virtual network device cluster.
[0050] At this time, two virtual network device clusters (that is, the CIDR is divided into two categories) are set for the system according to whether the service node network needs external network, which respectively include a first virtual network device cluster and a second virtual network device cluster. The first virtual network device cluster includes a plurality of virtual network devices that can access external network, and the second virtual network device cluster includes a plurality of virtual network devices that cannot access external network.
[0051] Each virtual network device that can access external network corresponds to a plurality of IP addresses that can access external network, and each virtual network device that cannot access external network corresponds to a plurality of IP addresses that cannot access external network.
[0052] Specifically, the callback plug-in determines the target virtual network device cluster from the preset first virtual network device cluster and the preset second virtual network device cluster according to the external network access permission tag in the target marker file. When the value of the external network access permission tag is true, the first virtual network device cluster is determined as the target virtual network device cluster, and the target virtual network device needs to be selected from the first virtual network device cluster subsequently. When the value of the external network access permission tag is false, the second virtual network device cluster is determined as the target virtual network device cluster, and the target virtual network device needs to be selected from the second virtual network device cluster subsequently.
[0053] After the target virtual network device cluster is determined, the callback plug-in acquires the idle IP number of each virtual network device in the target virtual network device cluster.
[0054] If the target marker file does not contain the physical network tag, the physical network does not need to be created for the target service node, and only the cluster network needs to be created for the target service node.
[0055] S130, the callback plug-in determines the virtual network device with the largest idle IP number as the target virtual network device, generates a target container network creation request according to the target virtual network device name of the target virtual network device, and sends the target container network creation request to the network configuration plug-in.
[0056] In this embodiment, the callback plug-in determines the virtual network device with the largest idle IP number as the target virtual network device.
[0057] For example, after the Webhook plug-in acquires the idle IP number of each vlan virtual device in the target virtual network device cluster, the vlan virtual device with the largest idle IP number is determined by comparing the idle IP numbers of the vlan virtual devices, the target vlan name (target virtual network device name) of the vlan virtual device is acquired, and the target vlan name is written into the target container network creation request, and the request is sent to the Multus plug-in.
[0058] In some embodiments, in order to ensure that the idle IP in the target virtual network device is sufficient for allocation, the number of idle IP in the target virtual network device also needs to meet the number of replicas of the current service node, at this time, after determining the target virtual network device, the method further includes the following steps: the callback plug-in determines whether the number of idle IP of the target virtual network device is greater than the number of replicas of the service node in the target marker file. If the number of idle IP is greater than the number of replicas of the service node, the target container network creation request is generated according to the target virtual network device name.
[0059] At this time, if the number of idle IP is not greater than the number of replicas of the service node, it means that the remaining IP address of the target virtual network device is not enough for allocation, and an alarm information is generated, which includes error reporting content. At this time, the error reporting content is that the number of idle IP is insufficient. When the staff sees the alarm information, the number of replicas of the service node at this time can be adjusted or the number of IP of the virtual device can be increased according to the error reporting content.
[0060] S140, the network configuration plug-in calls the physical network plug-in to create a physical network for the target service node according to the target container network creation request.
[0061] Specifically, the network configuration plug-in determines target routing parameters from target configuration information in response to the target container network creation request, the target configuration information being network configuration information corresponding to the target virtual network device name preset in the network configuration plug-in; the network configuration plug-in generates a physical network creation request according to the target routing parameters and the target virtual network device name; and the network configuration plug-in calls the physical network plug-in to create a physical network for the target service node according to the physical network creation request.
[0062] In the network configuration plug-in, a plurality of network configuration corresponding relationships of virtual network devices are preset, and the network configuration corresponding relationship includes a corresponding relationship between a virtual network device name and network configuration information.
[0063] For example, after the Multus plug-in receives the target container network creation request sent by the Webhook plug-in, the Macvlan plug-in is called to create a physical network for the target pod according to the target container network creation request. In this embodiment, the physical network is a Macvlan network.
[0064] In some embodiments, the container network creation device further includes an address allocation plug-in; and the network configuration plug-in calls the physical network plug-in to create a physical network for the target service node according to the physical network creation request, including:
[0065] The network configuration plug-in sends the physical network creation request to the physical network plug-in; the physical network plug-in creates a target virtual network card on the target service node with a target virtual network device on a target physical node as a parent device in response to the physical network creation request, the target physical node is a node where the target service node is located, and the target virtual network device is a virtual network device corresponding to the target virtual network device name; the physical network plug-in calls the address allocation plug-in to allocate a target IP address for the target virtual network card from a target IP pool corresponding to the target virtual network device name, and registers a target routing table for the target service node according to the target routing parameter, so that the target service node is connected to a layer 2 network through the target virtual network card, and the creation of the physical network of the target service node is completed.
[0066] The physical network plug-in calls the address allocation plug-in to allocate a target IP address for the target virtual network card from a target IP pool corresponding to the target virtual network device name, and registers a target routing table for the target service node according to the target routing parameter, and the target routing table includes an intra-cluster routing table and an inter-cluster routing table, the intra-cluster routing table is used to indicate that the target service node accesses an address within the target cluster, and the inter-cluster routing table is used to indicate that the target service node accesses an address outside the target cluster.
[0067] The physical network plug-in calls the address allocation plug-in to allocate a target IP address for the target virtual network card from the target IP pool; the physical network plug-in allocates the target routing table for the target virtual network card according to the target routing parameter; the physical network plug-in sends target interface configuration information corresponding to the target virtual network card to the network configuration plug-in, the target interface configuration information includes an interface name corresponding to the target virtual network card, the target IP address, and the target routing table; and the network configuration plug-in saves the target interface configuration information as network configuration information corresponding to the target service node.
[0068] The target routing table includes an intra-cluster routing table and an inter-cluster routing table, the intra-cluster routing table is used to indicate that the target service node accesses an address within the target cluster, and the inter-cluster routing table is used to indicate that the target service node accesses an address outside the target cluster.
[0069] In some embodiments, in order to avoid the situation that the physical network creation fails due to the fact that the target physical node does not have a target virtual network device, when the physical network plug-in receives the physical network creation request, the Macvlan plug-in also needs to check whether the target physical node has a target virtual network device, specifically:
[0070] The physical network plug-in determines whether the target virtual network device name exists in a target vlan configuration file in response to the physical network creation request, the target vlan configuration file storing virtual network device names of all virtual network devices under a target physical node, the target physical node being a node where the target service node is located; if the target virtual network device name does not exist in the target vlan configuration file, the physical network plug-in creates the target virtual network device under the target physical node according to preset vlan creation logic, stores the target virtual network device name in the target vlan configuration file, and then creates a target virtual network card on the target service node with the target virtual network device on the target physical node as a parent device.
[0071] If the target virtual network device name exists in the target vlan configuration file, a target virtual network card is created on the target service node with the target virtual network device on the target physical node as a parent device.
[0072] The address allocation plug-in (Whereabouts plug-in) in the embodiment works as follows:
[0073] 1. The Whereabouts plug-in uses CRD (Custom Resource Definition) to define IP pools, and an administrator can define one or more IP address pools for allocation to service nodes.
[0074] 2. When the physical network plug-in calls the Whereabouts plug-in, the Whereabouts plug-in selects an unused IP address from a corresponding IP pool, associates the selected IP address with a corresponding service node, and allocates the IP address to a virtual network card (network interface) of the service node.
[0075] 3. In the lifecycle of a service node, the Whereabouts plug-in maintains the state of the IP address and ensures that the IP address is not reused by other service nodes.
[0076] 4. When a service node is deleted, Whereabouts releases the corresponding IP address so that it can be used by other service nodes again.
[0077] After the container network of the target service node is created, the target service node can communicate with services outside the k8s cluster through the target virtual network card and the layer 2 network, and the services outside the k8s cluster can communicate with the target service node through direct connection.
[0078] The steps for the target service node to access the first node outside the k8s cluster are as follows:
[0079] The target service node generates a first access request according to the target routing table; the target service node forwards the first access request to the target virtual network device through the target virtual network card; the target virtual network device forwards the first access request to the second layer network through the target physical node, so that the switch in the second layer network sends the first access request to the first node according to the access IP address in the first access request, and the first node is a node outside the k8s cluster.
[0080] The steps for the second node outside the k8s cluster to access the target service node are as follows:
[0081] The target physical node receives a second access request sent by the second node based on the second layer network; the target physical node forwards the second access request to the target virtual network device according to the target IP address in the second access request; the target virtual network device forwards the second access request to the target virtual network card, so that the target service node receives the second access request through the target virtual network card.
[0082] Specifically, as shown in Figure 2 The eth1 network card, eth1.190 (vlan virtual device), and eth1.191 (vlan virtual device) on the Node node 1 inside the k8s cluster and the Node node 2 outside the k8s cluster are combined to form a virtual switch with multiple vlans, and the eth1 network card (virtual network card) on each pod directly accesses the virtual switch, so when the service in the pod wants to access the service outside the k8s cluster, the corresponding access request reaches the corresponding vlan virtual device through the corresponding virtual network card, and then reaches the node (specifically, the eth1 network card of the node), and finally reaches the underlying network, wherein the underlying network in the embodiment of the application is a second layer network, and the access request is sent to the corresponding service through the underlying network.
[0083] Similarly, when the service outside the cluster needs to access the pod inside the cluster, the corresponding access request of the service outside the cluster will first reach the corresponding node, then enter the corresponding vlan virtual device, and then be sent to the corresponding pod through the virtual network card corresponding to the vlan virtual device.
[0084] It can be seen that in the embodiment of the application, the network configuration plug-in can call the physical network plug-in to create a target virtual network card for the target service node, and set a target IP address and a target routing table for the target virtual network card, so that the target service node can be connected with the Layer 2 network through the target virtual network card, and communicate directly with the service outside the cluster through the Layer 2 network. Therefore, the direct communication between the service node and the service outside the cluster can be realized under the premise that the underlying network is a Layer 2 network and no NAT is required.
[0085] In summary, in the embodiment of the application, when the callback plug-in listens to the creation event of the target service node, it automatically checks whether the target service node corresponding marker file contains a physical network label. If the physical network label is contained, the target virtual network device name of the target service node is automatically determined, and the target virtual network device name does not need to be manually specified. On the one hand, the target virtual network device name can be automatically determined when the target container creation request is generated, and manual specification is not required, thereby improving the construction efficiency of the physical network. On the other hand, the target virtual network device selected by the embodiment of the application corresponds to the largest number of idle IPs, and the virtual network device with a larger number of idle IPs is preferentially selected, thereby improving the rationality of virtual network device allocation.
[0086] In addition, the embodiment of the application has the following beneficial effects: the IP address accessible to the external network or the IP address inaccessible to the external network can be automatically allocated to the target service node according to the user's demand; and when the physical network plug-in finds that there is no target virtual network device corresponding to the target virtual network device name under the target physical node, the target virtual network device can be automatically created under the target physical node, and manual access to build the virtual network device is not required, thereby improving the construction efficiency of the physical network.
[0087] Figure 3 is a schematic block diagram of a container network creation device provided by the embodiment of the application. As shown in Figure 3 Corresponding to the above physical network creation method, the application further provides a container network creation device 300. The container network creation device includes a callback plug-in 301, a network configuration plug-in 302, and a physical network plug-in 303 (a cluster network plug-in, an address allocation plug-in, etc. are not shown), wherein:
[0088] The callback plug-in 301 is configured to, when a creation event of a target service node is monitored, determine whether a physical network label is contained in a target marker file, the target marker file being a marker file corresponding to the target service node; if the physical network label is contained in the target marker file, acquire an idle IP number of each virtual network device in a preset target virtual network device cluster; determine a virtual network device with a largest idle IP number as a target virtual network device, generate a target container network creation request according to a target virtual network device name of the target virtual network device, and send the target container network creation request to the network configuration plug-in 302.
[0089] The network configuration plug-in 302 is configured to create a physical network for the target service node by calling the physical network plug-in 303 according to the target container network creation request.
[0090] In some embodiments, before the step of acquiring the idle IP number of each virtual network device in the preset target virtual network device cluster, the callback plug-in 301 is further configured to:
[0091] determine the target virtual network device cluster from a preset first virtual network device cluster and a preset second virtual network device cluster according to an external network access permission label in the target marker file, the first virtual network device cluster including a plurality of virtual network devices that can access an external network, and the second virtual network device cluster including a plurality of virtual network devices that cannot access the external network.
[0092] In some embodiments, after the step of determining the virtual network device with the largest idle IP number as the target virtual network device, the callback plug-in 301 is further configured to:
[0093] determine whether the idle IP number of the target virtual network device is greater than a service node replica number in the target marker file.
[0094] At this time, when the step of generating the target container network creation request according to the target virtual network device name of the target virtual network device is performed, the callback plug-in 301 is specifically configured to, if the idle IP number is greater than the service node replica number, generate the target container network creation request according to the target virtual network device name.
[0095] In some embodiments, when the step of creating the physical network for the target service node by calling the physical network plug-in 303 according to the target container network creation request is performed, the network configuration plug-in 302 is specifically configured to:
[0096] determining target routing parameters from the target configuration information, the target configuration information being the network configuration information corresponding to the target virtual network device name preset in the network configuration plug-in 301; generating a physical network creation request according to the target routing parameters and the target virtual network device name; and invoking the physical network plug-in 303 to create a physical network for the target service node according to the physical network creation request.
[0097] In some embodiments, the container network creation apparatus further comprises an address allocation plug-in; and the network configuration plug-in 302, when performing the step of invoking the physical network plug-in 303 to create a physical network for the target service node according to the physical network creation request, is specifically configured to:
[0098] sending the physical network creation request to the physical network plug-in 303; creating a target virtual network card on the target service node with a target virtual network device on a target physical node as a parent device in response to the physical network creation request by the physical network plug-in 303, the target physical node being a node where the target service node is located, and the target virtual network device being a virtual network device corresponding to the target virtual network device name; and invoking the address allocation plug-in to allocate a target IP address for the target virtual network card from a target IP pool corresponding to the target virtual network device name and register a target routing table for the target service node according to the target routing parameters by the physical network plug-in 303, so that the target service node is connected to a layer 2 network through the target virtual network card, and the creation of the physical network of the target service node is completed.
[0099] In some embodiments, the physical network plug-in 303, when performing the step of invoking the address allocation plug-in to allocate a target IP address for the target virtual network card from a target IP pool corresponding to the target virtual network device name and register a target routing table for the target service node according to the target routing parameters, is specifically configured to:
[0100] allocating a target IP address for the target virtual network card from the target IP pool by the address allocation plug-in; allocating the target routing table for the target virtual network card according to the target routing parameters; sending target interface configuration information corresponding to the target virtual network card to the network configuration plug-in 302, the target interface configuration information including an interface name corresponding to the target virtual network card, the target IP address, and the target routing table; and saving the target interface configuration information as network configuration information corresponding to the target service node by the network configuration plug-in 302.
[0101] In some embodiments, the address allocation plug-in is further configured to release the target IP address when receiving deletion information of the target service node.
[0102] In summary, in the embodiments of the present application, when the callback plug-in 301 listens to the creation event of the target service node, it automatically checks whether the target service node corresponding to the mark file contains a physical network label, and if so, automatically determines the target virtual network device name of the target service node, without the need for manual specification of the target virtual network device name. On the one hand, automatic determination of the target virtual network device name can improve the construction efficiency of the physical network, and on the other hand, the target virtual network device selected by the physical network plug-in 303 corresponds to the largest number of idle IPs, so that the virtual network device with a larger number of idle IPs is preferentially selected, thereby improving the rationality of virtual network device allocation.
[0103] It should be noted that the specific implementation process of the container network creation apparatus and each plug-in can be clearly understood by those skilled in the art, and can be referred to the corresponding description in the foregoing method embodiments. For the convenience and brevity of description, it will not be repeated here.
[0104] The container network creation apparatus can be implemented in the form of a computer program, which can run on an electronic device as shown in Figure 4 .
[0105] Please refer to Figure 4 , Figure 4 is a schematic block diagram of an electronic device provided by an embodiment of the present application. The electronic device 400 can be a router or other device with network connectivity function. Specifically, the electronic device in the embodiment is provided with a container network creation apparatus, which includes a callback plug-in, a network configuration plug-in, and a physical network plug-in,
[0106] Please refer to Figure 4 , the electronic device 400 includes a processor 402, a memory, and a network interface 405 connected through a system bus 401, wherein the memory can include a non-volatile storage medium 403 and an internal memory 404.
[0107] The non-volatile storage medium 403 can store an operating system 4031 and a computer program 4032. The computer program 4032 includes program instructions which, when executed, can cause the processor 402 to perform a method for creating a physical network.
[0108] The processor 402 is configured to provide computing and control capabilities to support the operation of the entire electronic device 400.
[0109] The memory 404 provides an environment for running the computer program 4032 in the non-volatile storage medium 403, which, when executed by the processor 402, enables the processor 402 to perform a method for creating a physical network.
[0110] The network interface 405 is configured to perform network communication with other devices. Figure 4 The structure shown in the figure is only a block diagram of part of the structure related to the scheme of the present application, and does not constitute a limitation on the electronic device 400 to which the scheme of the present application is applied. The specific electronic device 400 can include more or fewer components than those shown in the figure, or combine certain components, or have a different arrangement of components.
[0111] The processor 402 is configured to run the computer program 4032 stored in the memory, and the processor 402 realizes the following steps by invoking the plug-in in the container network creation device:
[0112] When the callback plug-in listens to the creation event of the target service node, the callback plug-in judges whether the target marker file contains a physical network label, and the target marker file is a marker file corresponding to the target service node;
[0113] If the target marker file contains the physical network label, the callback plug-in acquires the number of idle IPs of each virtual network device in a preset target virtual network device cluster;
[0114] The callback plug-in determines the virtual network device with the largest number of idle IPs as the target virtual network device, generates a target container network creation request according to the target virtual network device name of the target virtual network device, and sends the target container network creation request to the network configuration plug-in;
[0115] The network configuration plug-in invokes the physical network plug-in to create a physical network for the target service node according to the target container network creation request.
[0116] It should be understood that in the embodiments of the present application, the processor 402 can be a central processing unit (CPU), and the processor 402 can also be other general-purpose processors, digital signal processors (DSP), application specific integrated circuits (ASIC), field-programmable gate arrays (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. The general-purpose processor can be a microprocessor or any conventional processor.
[0117] It can be understood by those skilled in the art that all or part of the processes in the above-mentioned embodiments can be completed by instructing relevant hardware by a computer program. The computer program includes program instructions, and the computer program can be stored in a storage medium, which is a computer-readable storage medium. The program instructions are executed by at least one processor in the computer system to implement the process steps of the above-mentioned embodiments.
[0118] Therefore, the present application also provides a storage medium. The storage medium can be a computer-readable storage medium. The storage medium stores a computer program, wherein the computer program includes program instructions. The program instructions are executed by a processor to make the processor perform the following steps:
[0119] When the callback plug-in listens to the creation event of the target service node, the callback plug-in judges whether the physical network label is contained in the target marker file, the target marker file being a marker file corresponding to the target service node;
[0120] If the target marker file contains the physical network label, the callback plug-in acquires the number of idle IPs of each virtual network device in a preset target virtual network device cluster;
[0121] The callback plug-in determines the virtual network device with the largest number of idle IPs as a target virtual network device, generates a target container network creation request according to a target virtual network device name of the target virtual network device, and sends the target container network creation request to the network configuration plug-in;
[0122] The network configuration plug-in calls the physical network plug-in to create a physical network for the target service node according to the target container network creation request.
[0123] The storage medium can be a U disk, a mobile hard disk, a read-only memory (ROM), a magnetic disk or an optical disk, and various computer readable storage media that can store program codes.
[0124] Those skilled in the art can realize that the units and algorithm steps of each example described in combination with the embodiments disclosed herein can be realized in electronic hardware, computer software or a combination of both. In order to clearly illustrate the interchangeability of hardware and software, the components and steps of each example have been described in the above description in a general manner. Whether the functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. A person skilled in the art can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of the present application.
[0125] In several embodiments provided in the present application, it should be understood that the disclosed devices and methods can be implemented in other ways. For example, the device embodiments described above are only schematic. For example, the division of each unit is only a logical function division, and actual implementation can have another division manner. For example, a plurality of units or components can be combined or integrated into another system, or some features can be ignored or not executed.
[0126] The steps in the method embodiments of the present application can be adjusted, combined and reduced in sequence according to actual needs. The units in the device embodiments of the present application can be combined, divided and reduced according to actual needs. In addition, each functional unit in each embodiment of the present application can be integrated in one processing unit, or each unit can exist physically, or two or more units can be integrated in one unit.
[0127] The integrated unit, if realized in the form of a software functional unit and sold or used as an independent product, can be stored in a storage medium. Based on such understanding, the technical solutions of the present application essentially or say the parts that make contributions to the prior art, or the whole or part of the technical solutions can be embodied in the form of a software product. The computer software product is stored in a storage medium and includes a plurality of instructions for causing an electronic device (which can be a personal computer, a terminal or a network device, etc.) to execute all or part of the steps of the method described in each embodiment of the present application.
[0128] The above description is only a specific implementation of the present application, but the protection scope of the present application is not limited thereto. Any person skilled in the art can easily think of various equivalent modifications or replacements within the technical scope disclosed in the present application, and these modifications or replacements should be covered in the protection scope of the present application. Therefore, the protection scope of the present application should be subject to the protection scope of the claims.
Claims
1. A method of creating a physical network, characterized by, The method is applied to a container network creation device in a k8s cluster, and the container network creation device comprises a callback plug-in, a network configuration plug-in and a physical network plug-in. When the callback plug-in listens to a creation event of a target service node, the callback plug-in determines whether a physical network label is contained in a target marker file corresponding to the target service node. If the physical network label is contained in the target marker file, the callback plug-in acquires a number of idle IPs of each virtual network device in a preset target virtual network device cluster. The callback plug-in determines a virtual network device with the largest number of idle IPs as a target virtual network device, generates a target container network creation request according to a target virtual network device name of the target virtual network device, and sends the target container network creation request to the network configuration plug-in. The network configuration plug-in calls the physical network plug-in to create a physical network for the target service node according to the target container network creation request.
2. The method of claim 1, wherein, Before the callback plug-in acquires the number of idle IPs of each virtual network device in the preset target virtual network device cluster, the method further comprises: The callback plug-in determines the target virtual network device cluster from a preset first virtual network device cluster and a preset second virtual network device cluster according to an external network access permission label in the target marker file, the first virtual network device cluster comprising a plurality of virtual network devices accessible to an external network, and the second virtual network device cluster comprising a plurality of virtual network devices inaccessible to an external network.
3. The method of claim 1, wherein, After the callback plug-in determines the virtual network device with the largest number of idle IPs as the target virtual network device, the method further comprises: The callback plug-in determines whether the number of idle IPs of the target virtual network device is greater than a number of service node replicas in the target marker file. The generation of the target container network creation request according to the target virtual network device name comprises: If the number of idle IPs is greater than the number of service node replicas, the target container network creation request is generated according to the target virtual network device name.
4. The method according to any one of claims 1 to 3, characterized in that, The network configuration plug-in calls the physical network plug-in to create a physical network for the target service node according to the target container network creation request, comprising: The network configuration plug-in determines a target routing parameter from target configuration information in response to the target container network creation request, the target configuration information being network configuration information corresponding to the target virtual network device name in the network configuration plug-in; The network configuration plug-in generates a physical network creation request according to the target routing parameter and the target virtual network device name; The network configuration plug-in calls the physical network plug-in to create a physical network for the target service node according to the physical network creation request.
5. The method of claim 4, wherein, The container network creation device further comprises an address allocation plug-in; the network configuration plug-in invokes the physical network plug-in to create a physical network for the target service node according to the physical network creation request, comprising: The network configuration plug-in sends the physical network creation request to the physical network plug-in; The physical network plug-in creates a target virtual network card on the target service node with a target virtual network device on a target physical node as a parent device, the target physical node being a node where the target service node is located, and the target virtual network device being a virtual network device corresponding to the target virtual network device name; The physical network plug-in invokes the address allocation plug-in to allocate a target IP address for the target virtual network card from a target IP pool corresponding to the target virtual network device name, and registers a target routing table for the target service node according to the target routing parameter, so that the target service node is connected to a layer 2 network through the target virtual network card, and the creation of the physical network of the target service node is completed.
6. The method of claim 5, wherein, The physical network plug-in invokes the address allocation plug-in to allocate a target IP address for the target virtual network card from a target IP pool corresponding to the target virtual network device name, and registers a target routing table for the target service node according to the target routing parameter, comprising: The physical network plug-in invokes the address allocation plug-in to allocate a target IP address for the target virtual network card from the target IP pool; The physical network plug-in allocates the target routing table for the target virtual network card according to the target routing parameter; The physical network plug-in sends target interface configuration information corresponding to the target virtual network card to the network configuration plug-in, the target interface configuration information comprising an interface name corresponding to the target virtual network card, the target IP address, and the target routing table; The network configuration plug-in saves the target interface configuration information as network configuration information corresponding to the target service node.
7. The method of claim 6, wherein, After the physical network plug-in invokes the address allocation plug-in to allocate a target IP address for the target virtual network card from the target IP pool, the method further comprises: When the address allocation plug-in receives deletion information of the target service node, the address allocation plug-in releases the target IP address.
8. A container network creation apparatus characterized by comprising: The container network creation device comprises a callback plug-in, a network configuration plug-in, and a physical network plug-in, wherein: The callback plug-in is configured to, when a creation event of a target service node is monitored, determine whether a physical network label is included in a target marker file, the target marker file being a marker file corresponding to the target service node; if the physical network label is included in the target marker file, obtain a number of idle IP addresses of each virtual network device in a target virtual network device cluster; determine a virtual network device with a maximum number of idle IP addresses as a target virtual network device, generate a target container network creation request according to a target virtual network device name of the target virtual network device, and send the target container network creation request to the network configuration plug-in; The network configuration plug-in is configured to invoke the physical network plug-in to create a physical network for the target service node according to the target container network creation request.
9. An electronic device comprising a memory, a processor, and a computer program stored on the memory and executable on the processor, characterized in that, The processor implements the method for creating a physical network according to any one of claims 1-7 when executing the computer program.
10. A storage medium, characterized by The storage medium stores a computer program, and the computer program includes program instructions which, when executed by a processor, cause the processor to implement the method for creating a physical network according to any one of claims 1-7.
Citation Information
Patent Citations
Container network configuration method and device, computing node, main node and storage medium
CN114172802A
Container network management system
CN114237812A