A container IP address allocation method and device for a container cloud platform
By creating allocation set objects and IP address record objects in Kubernetes, the allocation of container IP addresses can be dynamically adjusted, solving the problem of low IP address allocation efficiency in container orchestration systems and achieving flexible allocation and container availability within a certain range.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- CHINA CONSTRUCTION BANK
- Filing Date
- 2024-11-07
- Publication Date
- 2026-08-04
AI Technical Summary
In existing technologies, container IP address allocation in Kubernetes container orchestration systems is usually random or one-to-one, which cannot meet the application scenarios where containers are bound to multiple IP addresses, especially in security management where there is a problem of low allocation efficiency.
By creating allocation set objects and IP address record objects, IP addresses can be allocated to containers within a certain range of IP addresses. Custom resource objects can be used to record the IP address usage status, monitor container upgrade or rebuild events, and dynamically adjust IP address allocation.
It improves the flexibility and efficiency of container IP address allocation, ensuring that containers can still be used normally within the predetermined IP address range after upgrades or rebuilds, thus meeting security management requirements.
Smart Images

Figure CN119172361B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of computer technology, and specifically to a method and apparatus for allocating container IP addresses for container cloud platforms. Background Technology
[0002] Kubernetes (K8s) is an open-source container orchestration platform used to automate the deployment, scaling, and management of containerized applications. It provides containerized applications with the full lifecycle management capabilities required for containers, including container deployment, resource management, cluster scheduling, elastic scaling, and service discovery.
[0003] In current open-source Kubernetes container orchestration systems and container networking solutions, the allocation of Internet Protocol (IP) addresses to containers is typically random. To achieve fixed container addresses, schemes have emerged that map container names to IP addresses or bind containers to target IPs. However, in practical applications, there are scenarios where a one-to-one mapping between containers and IP addresses is not necessary; instead, IP addresses need to be allocated to containers within a certain range. Therefore, how to allocate IP addresses to containers within a defined range has become a crucial issue that urgently needs to be addressed in this field. Summary of the Invention
[0004] To address the problems in the prior art, embodiments of the present invention provide a container IP address allocation method and apparatus for container cloud platforms, which can at least partially solve the problems existing in the prior art.
[0005] In a first aspect, this invention proposes a container IP address allocation method for container cloud platforms, comprising:
[0006] Receive a container creation request, the container creation request carrying the container's annotation information, the annotation information including the allocation set object used by the container; wherein, the allocation set object is pre-created, corresponding to multiple IP address record objects, each IP address record object having a corresponding IP address;
[0007] Based on the allocation set object, query to obtain multiple IP address record objects corresponding to the allocation set object and the usage status of each IP address record object;
[0008] If it is determined that there is an IP address record object with an unused status among the multiple IP address record objects corresponding to the allocation set object, then an unused IP address record object is allocated to the container;
[0009] If an upgrade or rebuild event of the container is detected, the allocation set object used by the container is obtained from the annotation information of the container;
[0010] Based on the allocation set object, obtain the IP address record object corresponding to the allocation set object and the usage status of each IP address record object;
[0011] If it is determined that there is an IP address record object in the IP address record object corresponding to the allocation set object that is in an unused state, then an unused IP address record object is allocated to the container.
[0012] Secondly, the present invention provides a container IP address allocation device for a container cloud platform, comprising:
[0013] The first receiving unit is used to receive a container creation request. The container creation request carries the container's annotation information, which includes an allocation set object used by the container. The allocation set object is pre-created and corresponds to multiple IP address record objects, each of which has a corresponding IP address.
[0014] The first query unit is used to query and obtain multiple IP address record objects corresponding to the allocation set object and the usage status of each IP address record object based on the allocation set object.
[0015] The first allocation unit is configured to allocate an unused IP address record object to the container after determining that there is an unused IP address record object among the multiple IP address record objects corresponding to the allocation set object.
[0016] The monitoring unit is used to obtain the allocation set object used by the container from the annotation information of the container if an application upgrade or rebuild event corresponding to the container is detected.
[0017] The second query unit is used to query the IP address record object corresponding to the allocation set object and the usage status of each IP address record object based on the allocation set object.
[0018] The second allocation unit is used to allocate an unused IP address record object to the container after determining that there is an unused IP address record object in the IP address record object corresponding to the allocation set object.
[0019] Thirdly, the present invention provides a computer device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the program to implement the container IP address allocation method for container cloud platforms as described in any of the above embodiments.
[0020] Fourthly, the present invention provides a computer-readable storage medium storing a computer program, which, when executed by a processor, implements the container IP address allocation method for container cloud platforms described in any of the above embodiments.
[0021] Fifthly, the present invention provides a computer program product, the computer program product comprising a computer program, which, when executed by a processor, implements the container IP address allocation method for container cloud platforms described in any of the above embodiments.
[0022] The present invention provides a container IP address allocation method and apparatus for a container cloud platform. The method receives a container creation request, the creation request carrying annotation information of the container, the annotation information including an allocation set object used by the container; wherein the allocation set object is pre-created and corresponds to multiple IP address record objects, each IP address record object having a corresponding IP address; the method queries the multiple IP address record objects corresponding to the allocation set object and the usage status of each IP address record object based on the allocation set object; if it is determined that there is an IP address record object with an unused usage status among the multiple IP address record objects corresponding to the allocation set object, then one unused IP address record object is allocated to the container. IP address record objects are assigned to the container; if an upgrade or rebuild event of the container is detected, the allocation set object used by the container is obtained from the annotation information of the container; the IP address record objects corresponding to the allocation set object and the usage status of each IP address record object are obtained by querying the allocation set object; if it is determined that there are unused IP address record objects among the IP address record objects corresponding to the allocation set object, an unused IP address record object is assigned to the container. The allocation set object is created to realize the allocation of container IP addresses, realizing the allocation of container IP addresses within a certain range of IP addresses, and improving the flexibility of container IP address allocation. Attached Figure Description
[0023] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort. In the drawings:
[0024] Figure 1 This is a flowchart illustrating the container IP address allocation method for container cloud platforms provided in the first embodiment of the present invention.
[0025] Figure 2 This is a flowchart illustrating the container IP address allocation method for container cloud platforms provided in the second embodiment of the present invention.
[0026] Figure 3 This is a flowchart illustrating the container IP address allocation method for container cloud platforms provided in the third embodiment of the present invention.
[0027] Figure 4 This is a flowchart illustrating the container IP address allocation method for container cloud platforms provided in the fourth embodiment of the present invention.
[0028] Figure 5 This is a flowchart illustrating the container IP address allocation method for container cloud platforms provided in the fifth embodiment of the present invention.
[0029] Figure 6 This is a flowchart illustrating the container IP address allocation method for container cloud platforms provided in the sixth embodiment of the present invention.
[0030] Figure 7 This is a flowchart illustrating the container IP address allocation method for container cloud platforms provided in the seventh embodiment of the present invention.
[0031] Figure 8 This is a schematic diagram of the structure of a container IP address allocation device for a container cloud platform provided in the eighth embodiment of the present invention.
[0032] Figure 9 This is a schematic diagram of the structure of a container IP address allocation device for a container cloud platform provided in the ninth embodiment of the present invention.
[0033] Figure 10 This is a schematic diagram of the structure of a container IP address allocation device for a container cloud platform provided in the tenth embodiment of the present invention.
[0034] Figure 11 This is a schematic diagram of the structure of a container IP address allocation device for a container cloud platform provided in the eleventh embodiment of the present invention.
[0035] Figure 12 This is a schematic diagram of the container IP address allocation device for a container cloud platform provided in the twelfth embodiment of the present invention.
[0036] Figure 13 This is a schematic diagram of the structure of a container IP address allocation device for a container cloud platform provided in the thirteenth embodiment of the present invention.
[0037] Figure 14 This is a schematic diagram of the structure of a container IP address allocation device for a container cloud platform provided in the fourteenth embodiment of the present invention.
[0038] Figure 15This is a schematic diagram of the physical structure of a computer device provided in the fifteenth embodiment of the present invention. Detailed Implementation
[0039] To make the objectives, technical solutions, and advantages of the embodiments of the present invention clearer, the embodiments of the present invention will be further described in detail below with reference to the accompanying drawings. Here, the illustrative embodiments and descriptions of the present invention are used to explain the present invention, but are not intended to limit the present invention. It should be noted that, unless otherwise specified, the embodiments and features in the embodiments of this application can be arbitrarily combined with each other.
[0040] The acquisition, transmission, storage, use, and processing of data in this application all comply with the relevant provisions of national laws and regulations.
[0041] The information collected in the technical solution of this application is information and data authorized by the user or fully authorized by all parties. The collection, storage, use, processing, transmission, provision, disclosure and application of the relevant data all comply with the relevant laws, regulations and standards of the relevant countries and regions, necessary confidentiality measures have been taken, and they do not violate public order and good morals. Corresponding operation portals are provided for users to choose to authorize or refuse.
[0042] It should be noted that in the embodiments of this application, certain software, components, models and other existing solutions in the industry may be mentioned. These should be regarded as exemplary and are only intended to illustrate the feasibility of implementing the technical solution of this application. However, it does not mean that the applicant has used or necessarily used the solution.
[0043] To facilitate understanding of the technical solution provided in this application, the relevant content of the technical solution in this application will be explained below.
[0044] In Kubernetes, container IP addresses are typically assigned randomly. While existing technologies achieve a one-to-one correspondence between containers and IP addresses, in practice, there are situations where a strict one-to-one mapping between containers and IP addresses is not required, but rather that a container needs to be associated with multiple IP addresses. Current technologies lack a solution for this. For example, for security management purposes, some container applications may use security mechanisms such as IP address whitelists when accessing other applications. Only containers whose IP addresses are on the whitelist are allowed to access the relevant applications. In this case, assigning a container an IP address that is on the whitelist is sufficient. Although assigning a unique IP address to a container based on an IP address on the whitelist can enable access to relevant applications, for multiple containers, the binding relationship between each container and IP address needs to be configured individually beforehand, resulting in low allocation efficiency.
[0045] To address the aforementioned issues, this invention provides a container IP address allocation method for container cloud platforms. By creating allocation set objects and IP address record objects, it enables the allocation of IP addresses to containers within a certain IP address range, thereby improving the flexibility of IP address allocation. Furthermore, compared to the existing technology's one-to-one correspondence between containers and IP addresses, it improves the efficiency of IP address allocation.
[0046] The following describes the specific implementation process of the container IP address allocation method for container cloud platforms provided in this embodiment of the invention, using a server as the execution subject as an example. It should be understood that the execution subject of the container IP address allocation method for container cloud platforms provided in this embodiment of the invention is not limited to a server.
[0047] Figure 1 This is a flowchart illustrating the container IP address allocation method for container cloud platforms provided in the first embodiment of the present invention, as shown below. Figure 1 As shown in the figure, the container IP address allocation method for container cloud platforms provided in this embodiment of the invention includes:
[0048] S101. Receive a container creation request, the container creation request carries the container's annotation information, the annotation information includes the allocation set object used by the container; wherein, the allocation set object is pre-created, corresponding to multiple IP address record objects, and each IP address record object has a corresponding IP address;
[0049] Specifically, when creating a container, a user can configure the container's annotation information, specifying the allocation set object used by the container in the annotation information, and then send a container creation request to the server through a client. The container creation request carries the container's annotation information, including the allocation set object used by the container. The server receives the container creation request and obtains the allocation set object used by the container from it. The allocation set object is a custom resource object used to record a set of IP address record objects and the usage status of each IP address record object. The allocation set object is pre-created and corresponds to multiple IP address record objects, each IP address record object having a corresponding IP address. The client includes, but is not limited to, desktop computers, laptops, and tablets.
[0050] S102. Based on the allocation set object, query to obtain multiple IP address record objects corresponding to the allocation set object and the usage status of each IP address record object;
[0051] Specifically, the server can query the allocation set object to obtain multiple IP address record objects included in the allocation set object, as well as the usage status of each IP address record object. The usage status is either "used" or "unused." If an IP address record object has been assigned to a container, its usage status is "used"; if it has not been assigned to a container, its usage status is "unused." The allocation set object records the usage status of each corresponding IP address record object.
[0052] S103. If it is determined that there is an IP address record object whose usage status is unused among the multiple IP address record objects corresponding to the allocation set object, then an unused IP address record object is allocated to the container.
[0053] Specifically, the server will determine the usage status of multiple IP address record objects corresponding to the allocation set object. If there are IP address record objects with an unused usage status, then an IP address record object with an unused usage status can be allocated to the container. The IP address corresponding to the IP address record object is used as the IP address of the container, thereby completing the allocation of the container's IP address.
[0054] S104. If an upgrade or rebuild event of the container is detected, the allocation set object used by the container is obtained from the annotation information of the container.
[0055] Specifically, in Kubernetes, when a container is upgraded or rebuilt, its IP address changes. For some applications that require specific container IP addresses, this change can cause the application to malfunction after the upgrade or rebuild. After detecting the container's upgrade or rebuild event, the server can obtain the allocation set object used by the container from the container's annotation information.
[0056] For example, application X corresponding to container Z needs to access application Y, and application Y requires that only IP addresses within the IP address whitelist be allowed to access it. When container Z is upgraded or rebuilt, its IP address will change. To ensure that application X can still access application Y after container Z is upgraded or rebuilt, an allocation set object B can be created based on the IP address whitelist. An IP address can then be assigned to container Z based on allocation set object B, so that the IP address corresponding to container Z after upgrade or rebuild will still be within the IP address whitelist required by Y.
[0057] S105. Based on the allocation set object, query to obtain the IP address record object corresponding to the allocation set object and the usage status of each IP address record object;
[0058] Specifically, the server can query the IP address record objects corresponding to the allocation set object and the usage status of each IP address record object based on the allocation set object.
[0059] S106. If it is determined that there is an IP address record object in the IP address record object corresponding to the allocation set object that is in an unused state, then an unused IP address record object is allocated to the container.
[0060] Specifically, the server determines whether there is an IP address record object with an unused usage status among the IP address record objects corresponding to the allocation set object. If so, it obtains an IP address record object with an unused usage status and allocates it to the container. This ensures that after the container is upgraded or rebuilt, the allocated IP address is within the IP address range corresponding to the allocation set object, enabling the application corresponding to the container to function normally.
[0061] This invention provides a container IP address allocation method for container cloud platforms. The method receives a container creation request, which carries annotation information about the container. This annotation information includes an allocation set object used by the container. The allocation set object is pre-created and corresponds to multiple IP address record objects, each with a corresponding IP address. The method queries the allocation set object to obtain the multiple IP address record objects corresponding to it and their usage status. If it is determined that there is an unused IP address record object among the multiple IP address record objects corresponding to the allocation set object, then an unused IP address is allocated to the container. Address record objects are assigned to the container; if an upgrade or rebuild event of the container is detected, the allocation set object used by the container is obtained from the container's annotation information; the IP address record objects corresponding to the allocation set object and the usage status of each IP address record object are obtained by querying the allocation set object; if it is determined that there are unused IP address record objects among the IP address record objects corresponding to the allocation set object, an unused IP address record object is assigned to the container. The allocation set object is created to achieve container IP address allocation, realizing container IP address allocation within a certain IP address range, thus improving the flexibility of container IP address allocation. Furthermore, after a container upgrade or rebuild, container IP addresses can still be allocated within the original IP address range, ensuring container availability.
[0062] Figure 2 This is a flowchart illustrating the container IP address allocation method for container cloud platforms provided in the second embodiment of the present invention, as shown below. Figure 2As shown, based on the above embodiments, the container IP address allocation method for container cloud platforms provided by the embodiments of the present invention further includes:
[0063] S201. If it is determined that the usage status of all IP address record objects corresponding to the allocation set object is "used", then a first IP address record object is created corresponding to the allocation set object, and an IP address is assigned to the first IP address record object; wherein, the first IP address record object is a new IP address record object;
[0064] Specifically, the server determines the usage status of multiple IP address record objects corresponding to the allocation set object. If all IP address record objects corresponding to the allocation set object are in use, the server creates a new address record object as the first IP address record object, associates the first IP address record object with the allocation set object, and then assigns an IP address to the first IP address record object. Understandably, the server will select an unused IP address and assign it to the first IP address record object.
[0065] For example, in Kubernetes, a resource object A is pre-created as an allocation set object, labeled AllocSet-A. When the server determines that all IP address record objects corresponding to allocation set object A are in use, a new IP address record object a can be created, labeled Aa, indicating that IP address record object a is an IP address record object corresponding to allocation set object A.
[0066] S202. Assign the first IP address record object to the container and mark the usage status of the first IP address record object as used.
[0067] Specifically, the server allocates the first IP address record object to the container, and the IP address corresponding to the first IP address record object becomes the IP address of the container. The server records the usage status of the first IP address record object as "used" in the allocation set object.
[0068] Figure 3 This is a flowchart illustrating the container IP address allocation method for container cloud platforms provided in the third embodiment of the present invention, as shown below. Figure 3 As shown, based on the above embodiments, the container IP address allocation method for container cloud platforms provided by the embodiments of the present invention further includes:
[0069] S301. Bind the name of the container to the IP address corresponding to the IP address record object assigned to the container and store it in the database;
[0070] Specifically, after the container is allocated and obtains an IP address record object, it can bind the container's name to the IP address corresponding to the allocated IP address record object and store it in a database. The database records the correspondence between the container and the IP address.
[0071] S302. If an upgrade or rebuild event of the container is detected and the name of the container is stored in the database, then the corresponding IP address is obtained from the database according to the name of the container and assigned to the container.
[0072] Specifically, after the server detects an upgrade or rebuild event of the container, it can query the database according to the name of the container. If the name of the container is found, the server can find the IP address corresponding to the container according to the name of the container and assign the IP address of the container to the container, thereby realizing the fixation of the IP address of the container after the upgrade or rebuild.
[0073] Figure 4 This is a flowchart illustrating the container IP address allocation method for container cloud platforms provided in the fourth embodiment of the present invention, as shown below. Figure 4 As shown, based on the above embodiments, the container IP address allocation method for container cloud platforms provided by the embodiments of the present invention further includes:
[0074] S401. If it is determined that the usage status of all IP address record objects corresponding to the allocation set object is "used", then a second IP address record object is created corresponding to the allocation set object, and an IP address is assigned to the second IP address record object; wherein, the second IP address record object is a new IP address record object.
[0075] Specifically, after detecting an upgrade or rebuild event of the container, the server determines whether there is an unused IP address record object among the IP address record objects corresponding to the allocation set object. If not, it means that all IP address record objects corresponding to the allocation set object used by the container are already in use. To avoid container creation failure, the server creates a new address record object as a second IP address record object, maps the second IP address record object to the allocation set object, and then assigns an IP address to the second IP address record object. Understandably, the server will select an unused IP address to assign to the second IP address record object.
[0076] S402. Assign the second IP address record object to the container and mark the usage status of the second IP address record object as used.
[0077] Specifically, the server assigns the second IP address record object to the container after the application upgrade or reconstruction. The IP address corresponding to the second IP address record object becomes the IP address of the container, thus completing the allocation of the container's IP address. If the container's application has IP address restrictions, the application corresponding to the container cannot be used normally after the IP address allocation is completed. In this case, relevant technical personnel need to authorize access to the IP address corresponding to the second IP address record object.
[0078] Based on the above embodiments, the container IP address allocation method for container cloud platforms provided by the embodiments of the present invention further includes:
[0079] If it is determined that the allocation set object is a whitelist object, then an IP address whitelist addition request is sent, and the IP address whitelist addition request carries the IP address corresponding to the second IP address record object.
[0080] Specifically, the server determines whether the allocation set object is a whitelisted object. Allocation set objects created using an IP address whitelist are whitelisted objects; those not created using an IP address whitelist are not. After creating an allocation set object, the server can record whether it is a whitelisted object for later querying. If the allocation set object is a whitelisted object, since the created second IP address record object corresponds to the allocation set object, but the IP address corresponding to the second IP address record object is not in the IP address whitelist, the server will send an IP address whitelist addition request. This request carries the IP address corresponding to the second IP address record object, prompting relevant personnel to add the IP address corresponding to the second IP address record object to the IP address whitelist, thereby enabling the container corresponding to the second IP address record object to function normally.
[0081] Figure 5 This is a flowchart illustrating the container IP address allocation method for container cloud platforms provided in the fifth embodiment of the present invention, as shown below. Figure 5 As shown, based on the above embodiments, the step of creating an allocation set object further includes:
[0082] S501. Receive a request to create an allocation set object, wherein the request to create the allocation set object includes the configuration information of the allocation set object;
[0083] Specifically, when creating an allocation set object, the user can customize the configuration information of the allocation set object, which may include its name, label, IP address list, and number of IP address record objects. Then, the client sends a creation request for the allocation set object to the server. The server receives the creation request for the allocation set object, which includes the configuration information of the allocation set object.
[0084] S502. Create the allocation set object based on the IP address list or the number of IP address record objects included in the configuration information of the allocation set object.
[0085] Specifically, if the configuration information of the allocation set object includes an IP address list, the server creates the allocation set object based on the IP address list included in the configuration information. This involves first creating an allocation set object label, and then creating a corresponding number of IP address record objects based on the number of IP addresses in the IP address list. Each IP address record object has a unique corresponding IP address record object label, and each IP address record object is assigned an IP address from the IP address list. The IP address record object label corresponds to the allocation set object label. The IP address list can be an IP address whitelist.
[0086] If the configuration information of the allocation set object includes the number of IP address record objects, the server will create the allocation set object according to the number of IP address record objects included in the configuration information. Specifically, it first creates an allocation set object label for the allocation set object, and then creates a corresponding number of IP address record objects based on the number of IP address record objects. Each IP address record object has a unique corresponding IP address record object label, and each IP address record object is assigned an IP address. The IP address record object label corresponds to the allocation set object label. The number of IP address record objects refers to the total number of IP address record objects that need to be created for the allocation set object. The number of IP address record objects is usually multiple.
[0087] Figure 6 This is a flowchart illustrating the container IP address allocation method for container cloud platforms provided in the sixth embodiment of the present invention, as shown below. Figure 6 As shown, based on the above embodiments, the container IP address allocation method for container cloud platforms provided by the embodiments of the present invention further includes:
[0088] S601. Receive a container deletion request, wherein the container deletion request includes the identifier corresponding to the container;
[0089] Specifically, when a user deletes a container, they can send a container deletion request to the server through a client. This request includes the identifier corresponding to the container. The server can receive the container deletion request. Each container has a unique identifier.
[0090] S602. Obtain the IP address record object corresponding to the container by querying the identifier corresponding to the container;
[0091] Specifically, the server can query the IP address record object corresponding to the container based on the identifier corresponding to the container. Since the container is to be deleted, the IP address record object corresponding to the container is also idle, so the IP address record object corresponding to the container can be released and the IP address corresponding to the IP address record object can be recycled.
[0092] S603. Change the usage status of the IP address record object corresponding to the container to unused.
[0093] Specifically, after the server queries the IP address record object corresponding to the container, it changes the usage status of the IP address record object corresponding to the container to unused, thereby releasing the deleted IP address record object corresponding to the container and reclaiming the IP address corresponding to the IP address record object.
[0094] Based on the above embodiments, the IP address further includes IPv4 address and IPv6 address.
[0095] Specifically, the IP addresses include both IPv4 (Internet Protocol version 4) and IPv6 (Internet Protocol version 6) addresses. Containers assigned these IP addresses can communicate with both IPv4 and IPv6 networks. Similarly, applications corresponding to these containers, after being upgraded or rebuilt, can also communicate with both IPv4 and IPv6 networks.
[0096] The following section uses the allocation of container IP addresses on a Kubernetes-based container cloud platform as an example to illustrate the specific implementation process of the container IP address allocation method for container cloud platforms provided in this embodiment of the invention.
[0097] In real-world scenarios, due to security management requirements, some applications enable security mechanisms such as IP address whitelists when accessing other applications. However, in Kubernetes container scenarios, container IP addresses change after upgrades or rebuilds, and the container's IP address may no longer meet the requirements of the IP address whitelist. The container IP address allocation method proposed in this application for container cloud platforms allocates IP addresses from the whitelist to the container based on an allocation set object created during container creation, improving the flexibility of container IP address allocation. Furthermore, it ensures that containers can still be allocated whitelisted IP addresses during upgrades or rebuilds, guaranteeing container availability after upgrades or rebuilds.
[0098] Figure 7 This is a flowchart illustrating the container IP address allocation method for container cloud platforms provided in the seventh embodiment of the present invention, as shown below. Figure 7 As shown, the specific process for allocating container IP addresses in Kubernetes is as follows:
[0099] Step 1: Create an allocation set object.
[0100] To assign IP addresses from the whitelist to containers, you need to use Kubernetes Custom Resource Definitions (CRDs) to create allocation set objects based on the IP address whitelist. CRDs are a type of Kubernetes custom resource used to store structured data, enabling extensions to the Kubernetes API and enhancing capabilities not natively available in Kubernetes.
[0101] The user defines the configuration information for the allocation set object, including the name AllocSet, the IP address whitelist, and the label AllocSet-ABC. The client then sends a creation request for the allocation set object carrying this configuration information to a server E in Kubernetes. Server E creates n IP address record objects (IPSets) based on the number of IP addresses (n) included in the IP address whitelist, sets the usage status of each IPSet to unused, and assigns each IP address from the IP address whitelist to one IPSet. There is a one-to-one correspondence between IPSets and IP addresses in the IP address whitelist. Each IPSet includes a label; the label for the i-th IPSet is ABC-IPSeti, where i is a positive integer less than or equal to n. For example, the label for the 5th IPSet is ABC-IPSet5.
[0102] The second step is to assign an IP address to the created container.
[0103] Users create containers using an IP address whitelist. During container creation, annotation information is configured, including an allocation set object (AllocSet). A container creation request carrying this annotation information is sent to server E. Server E retrieves the tag AllocSet-ABC based on AllocSet, and then retrieves n IP address record objects (IPSet) corresponding to the allocation set object AllocSet based on ABC. From these n IP address record objects (IPSet), an IP address record object (IPSet) that is currently unused is selected and assigned to the container. The IP address corresponding to this IP address record object (IPSet) becomes the container's IP address.
[0104] The third step is to assign IP addresses to the upgraded or rebuilt containers.
[0105] After a container is upgraded or rebuilt, server E obtains the AllocSet used by the container from the container's annotation information. Then, it queries the AllocSet to obtain the n IP address record objects IPSet corresponding to the AllocSet. Finally, it selects an IP address record object IPSet that is not in use from the n IP address record objects IPSet and assigns it to the container. The IP address corresponding to the IP address record object IPSet is the container's IP address.
[0106] Step 4: Release the IP address record object.
[0107] After receiving a container deletion request, server E can obtain the IP address record object IPSet allocated by the container, change the usage status of the IP address record object IPSet to unused, release the IP address record object, and thus reclaim the IP address.
[0108] In this embodiment of the invention, a custom allocation set object, AllocSet, is used to create IPSets and record their usage status. When a container is created, the AllocSet is declared, binding the container to the AllocSet. This allows the container to be allocated IP addresses within the range of IP addresses corresponding to the AllocSet, and even after the container is rebuilt or upgraded, it can still be allocated IP addresses within the range of IP addresses corresponding to the server. Furthermore, when a container is deleted, the usage status of the IPSet corresponding to the container can be changed to reclaim the IP addresses.
[0109] Figure 8 This is a schematic diagram of the structure of the container IP address allocation device for container cloud platforms provided in the eighth embodiment of the present invention, as shown below. Figure 8As shown, the container IP address allocation device for container cloud platforms provided in this embodiment of the invention includes a first receiving unit 801, a first query unit 802, a first allocation unit 803, a monitoring unit 804, a second query unit 805, and a second allocation unit 806, wherein:
[0110] The first receiving unit 801 is used to receive a container creation request, the container creation request carrying the container's annotation information, the annotation information including the allocation set object used by the container; wherein, the allocation set object is pre-created, corresponding to multiple IP address record objects, each IP address record object having a corresponding IP address; the first querying unit 802 is used to query and obtain the multiple IP address record objects corresponding to the allocation set object and the usage status of each IP address record object according to the allocation set object; the first allocation unit 803 is used to determine if there are any IP address records among the multiple IP address record objects corresponding to the allocation set object whose usage status is unused. After recording the object, an unused IP address record object is allocated to the container; the monitoring unit 804 is used to obtain the allocation set object used by the container from the annotation information of the container if an application upgrade or rebuild event corresponding to the container is detected; the second query unit 805 is used to query the allocation set object to obtain the IP address record object corresponding to the allocation set object and the usage status of each IP address record object; the second allocation unit 806 is used to allocate an unused IP address record object to the container after determining that there is an unused IP address record object among the IP address record objects corresponding to the allocation set object.
[0111] Specifically, when creating a container, a user can configure the container's annotation information, specifying the allocation set object used by the container in the annotation information, and then send a container creation request to the first receiving unit 801 through a client. The container creation request carries the container's annotation information, including the allocation set object used by the container. The first receiving unit 801 receives the container creation request and obtains the allocation set object used by the container. The allocation set object is a custom resource object used to record a set of IP address record objects and the usage status of each IP address record object. The allocation set object is pre-created and corresponds to multiple IP address record objects, each with a corresponding IP address. The client includes, but is not limited to, desktop computers, laptops, and tablets.
[0112] The first query unit 802 can query the allocation set object to obtain multiple IP address record objects included in the allocation set object and the usage status of each IP address record object. The usage status is either "used" or "unused". If an IP address record object has been assigned to a container, then the usage status of the IP address record object is "used"; if an IP address record object has not been assigned to a container, then the usage status of the IP address record object is "unused". The allocation set object records the usage status of each corresponding IP address record object.
[0113] The first allocation unit 803 will determine the usage status of multiple IP address record objects corresponding to the allocation set object. If there are IP address record objects with an unused usage status, then an IP address record object with an unused usage status can be allocated to the container. The IP address corresponding to the IP address record object is used as the IP address of the container, thereby completing the allocation of the container IP address.
[0114] In Kubernetes (K8s), when a container is upgraded or rebuilt, its IP address changes. For some applications that require specific container IP addresses, this change can cause the application to malfunction after the upgrade or rebuild. After detecting the container upgrade or rebuild event, the monitoring unit 804 can obtain the allocation set object used by the container from the container's annotation information.
[0115] The second query unit 805 can query the IP address record objects corresponding to the allocation set object and the usage status of each IP address record object based on the allocation set object.
[0116] The second allocation unit 806 determines whether there is an IP address record object with an unused usage status among the IP address record objects corresponding to the allocation set object. If so, it acquires an IP address record object with an unused usage status and allocates it to the container. This ensures that after the container is upgraded or rebuilt, the allocated IP address is within the IP address range corresponding to the allocation set object, enabling the application corresponding to the container to function normally.
[0117] The container IP address allocation device for container cloud platforms provided in this invention receives a container creation request. The container creation request carries annotation information of the container, including an allocation set object used by the container. The allocation set object is pre-created and corresponds to multiple IP address record objects, each with a corresponding IP address. The device queries the allocation set object to obtain the multiple IP address record objects corresponding to the allocation set object and the usage status of each IP address record object. If it is determined that there is an IP address record object with an unused usage status among the multiple IP address record objects corresponding to the allocation set object, then an unused IP address is allocated to the allocation set object. Address record objects are assigned to the container; if an upgrade or rebuild event of the container is detected, the allocation set object used by the container is obtained from the container's annotation information; the IP address record objects corresponding to the allocation set object and the usage status of each IP address record object are obtained by querying the allocation set object; if it is determined that there are unused IP address record objects among the IP address record objects corresponding to the allocation set object, an unused IP address record object is assigned to the container. The allocation set object is created to achieve container IP address allocation, realizing container IP address allocation within a certain IP address range, thus improving the flexibility of container IP address allocation. Furthermore, after a container upgrade or rebuild, container IP addresses can still be allocated within the original IP address range, ensuring container availability.
[0118] Figure 9 This is a schematic diagram of the structure of a container IP address allocation device for a container cloud platform provided in the ninth embodiment of the present invention, as shown below. Figure 9 As shown, based on the above embodiments, the container IP address allocation device for container cloud platforms provided in this embodiment of the invention further includes a first creation unit 807 and a third allocation unit 808, wherein:
[0119] The first creation unit 807 is used to create a first IP address record object corresponding to the allocation set object after determining that the usage status of the IP address record objects corresponding to the allocation set object is used, and to allocate an IP address to the first IP address record object; wherein, the first IP address record object is a new IP address record object; the third allocation unit 808 is used to allocate the first IP address record object to the container and mark the usage status of the first IP address record object as used.
[0120] Figure 10 This is a schematic diagram of the structure of a container IP address allocation device for a container cloud platform provided in the tenth embodiment of the present invention, as shown below. Figure 10As shown, based on the above embodiments, the container IP address allocation device for container cloud platforms provided in this embodiment of the invention further includes a storage unit 809 and a fourth allocation unit 810, wherein:
[0121] Storage unit 809 is used to bind and store the name of the container with the IP address corresponding to the IP address record object assigned to the container in the database; the fourth allocation unit 810 is used to obtain the corresponding IP address from the database according to the name of the container and allocate it to the container if an upgrade or rebuild event of the container is detected and the name of the container is stored in the database.
[0122] Figure 11 This is a schematic diagram of the structure of the container IP address allocation device for container cloud platforms provided in the eleventh embodiment of the present invention, as shown below. Figure 11 As shown, based on the above embodiments, the container IP address allocation device for container cloud platforms provided in this embodiment of the invention further includes a second creation unit 811 and a fifth allocation unit 812, wherein:
[0123] The second creation unit 811 is used to create a second IP address record object corresponding to the allocation set object after determining that the usage status of the IP address record objects corresponding to the allocation set object is used, and to allocate an IP address to the second IP address record object; wherein, the second IP address record object is a new IP address record object; the fifth allocation unit 812 is used to allocate the second IP address record object to the container and mark the usage status of the second IP address record object as used.
[0124] Figure 12 This is a schematic diagram of the structure of a container IP address allocation device for a container cloud platform provided in the twelfth embodiment of the present invention, as shown below. Figure 12 As shown, based on the above embodiments, the container IP address allocation device for container cloud platforms provided in this embodiment of the invention further includes a sending unit 813, wherein:
[0125] The sending unit 813 is used to send an IP address whitelist addition request after determining that the allocation set object is a whitelist object. The IP address whitelist addition request carries the IP address corresponding to the second IP address record object.
[0126] Figure 13 This is a schematic diagram of the structure of a container IP address allocation device for a container cloud platform provided in the thirteenth embodiment of the present invention, as shown below. Figure 13As shown, based on the above embodiments, the container IP address allocation device for container cloud platforms provided in this embodiment of the invention further includes a second receiving unit 814 and a third creating unit 815, wherein:
[0127] The second receiving unit 814 is used to receive a creation request for an allocation set object, the creation request for the allocation set object including the configuration information of the allocation set object; the third creation unit 815 is used to create the allocation set object according to the IP address list or the number of IP address record objects included in the configuration information of the allocation set object.
[0128] Figure 14 This is a schematic diagram of the structure of a container IP address allocation device for a container cloud platform provided in the fourteenth embodiment of the present invention, as shown below. Figure 14 As shown, based on the above embodiments, the container IP address allocation device for container cloud platforms provided in this embodiment of the invention further includes a third receiving unit 816, a third querying unit 817, and a changing unit 818, wherein:
[0129] The third receiving unit 816 is used to receive a deletion request for a container, the deletion request for a container including an identifier corresponding to the container; the third querying unit 817 is used to query and obtain the IP address record object corresponding to the container based on the identifier corresponding to the container; the changing unit 818 is used to change the usage status of the IP address record object corresponding to the container to unused.
[0130] Based on the above embodiments, the IP address further includes IPv4 address and IPv6 address.
[0131] The embodiments of the device provided in this invention can be used to execute the processing flow of the above-described method embodiments. Its functions will not be repeated here, but can be referred to the detailed description of the above-described method embodiments.
[0132] It should be noted that the container IP address allocation method and apparatus for container cloud platforms provided in this embodiment of the invention can be used in the financial field, or in any technical field other than the financial field. This embodiment of the invention does not limit the application field of a container IP address allocation method and apparatus for container cloud platforms.
[0133] Figure 15 This is a schematic diagram of the physical structure of a computer device provided in an embodiment of the present invention, as shown below. Figure 15As shown, the computer device may include a processor 1501, a communications interface 1502, a memory 1503, and a communication bus 1504. The processor 1501, communications interface 1502, and memory 1503 communicate with each other via the communication bus 1504. The processor 1501 can call logical instructions in the memory 1503 to execute the methods provided in the above embodiments, such as: receiving a container creation request, the container creation request carrying annotation information of the container, the annotation information including an allocation set object used by the container; wherein the allocation set object is pre-created, corresponding to multiple IP address record objects, each IP address record object having a corresponding IP address; querying the multiple IP address record objects corresponding to the allocation set object and the usage status of each IP address record object based on the allocation set object; if it is determined that there is an IP address record object with an unused usage status among the multiple IP address record objects corresponding to the allocation set object, then allocating an unused IP address record object to the container.
[0134] Furthermore, the logical instructions in the aforementioned memory 1503 can be implemented as software functional units and, when sold or used as independent products, can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention, essentially, or the part that contributes to the prior art, or a part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of the present invention. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.
[0135] This embodiment discloses a computer program product, which includes a computer program. When the computer program is executed by a processor, the computer can execute the methods provided in the above-described method embodiments, such as: receiving a container creation request, the container creation request carrying annotation information of the container, the annotation information including an allocation set object used by the container; wherein the allocation set object is pre-created and corresponds to multiple IP address record objects, each IP address record object having a corresponding IP address; querying the multiple IP address record objects corresponding to the allocation set object and the usage status of each IP address record object according to the allocation set object; if it is determined that there is an IP address record object with an unused usage status among the multiple IP address record objects corresponding to the allocation set object, then allocating an unused IP address record object to the container.
[0136] This embodiment provides a computer-readable storage medium storing a computer program. When the computer program is executed by a processor, it causes the computer to perform the methods provided in the above-described method embodiments. For example, the methods include: receiving a container creation request, the container creation request carrying annotation information of the container, the annotation information including an allocation set object used by the container; wherein the allocation set object is pre-created and corresponds to multiple IP address record objects, each IP address record object having a corresponding IP address; querying the multiple IP address record objects corresponding to the allocation set object and the usage status of each IP address record object based on the allocation set object; if it is determined that there is an IP address record object with an unused usage status among the multiple IP address record objects corresponding to the allocation set object, then allocating an unused IP address record object to the container.
[0137] Those skilled in the art will understand that embodiments of the present invention can be provided as methods, systems, or computer program products. Therefore, the present invention can take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, the present invention can take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0138] This invention is described with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of the invention. It will be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, generate instructions for implementing the flowchart illustrations and / or block diagrams. Figure 1 One or more processes and / or boxes Figure 1 A device that provides the functions specified in one or more boxes.
[0139] These computer program instructions may also be stored in a computer-readable storage medium that can direct a computer or other programmable data processing device to function in a particular manner, such that the instructions stored in the computer-readable storage medium produce an article of manufacture including instruction means, which are implemented in a process Figure 1 One or more processes and / or boxes Figure 1 The function specified in one or more boxes.
[0140] These computer program instructions may also be loaded onto a computer or other programmable data processing equipment to cause a series of operational steps to be performed on the computer or other programmable equipment to produce a computer-implemented process, thereby providing instructions that execute on the computer or other programmable equipment for implementing the process. Figure 1 One or more processes and / or boxes Figure 1 The steps of the function specified in one or more boxes.
[0141] In the description of this specification, the references to terms such as "an embodiment," "a specific embodiment," "some embodiments," "for example," "example," "specific example," or "some examples," etc., indicate that a specific feature, structure, material, or characteristic described in connection with that embodiment or example is included in at least one embodiment or example of the invention. In this specification, the illustrative expressions of the above terms do not necessarily refer to the same embodiment or example. Furthermore, the specific features, structures, materials, or characteristics described may be combined in any suitable manner in one or more embodiments or examples.
[0142] The specific embodiments described above further illustrate the purpose, technical solution, and beneficial effects of the present invention. It should be understood that the above descriptions are merely specific embodiments of the present invention and are not intended to limit the scope of protection of the present invention. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of the present invention should be included within the scope of protection of the present invention.
Claims
1. A method for allocating container IP addresses for a container cloud platform, characterized in that, include: The system receives a container creation request, which carries annotation information for the container. This annotation information includes an allocation set object used by the container. The allocation set object is a pre-created Kubernetes custom resource object, corresponding to multiple IP address record objects, each with a corresponding IP address. The allocation set object records a set of IP address record objects and their usage status. During container creation, the system declares the allocation set object used, thus binding the container to the allocation set object it uses. Based on the allocation set object, query to obtain multiple IP address record objects corresponding to the allocation set object and the usage status of each IP address record object; If it is determined that there is an IP address record object with an unused status among the multiple IP address record objects corresponding to the allocation set object, then an unused IP address record object is allocated to the container; If an upgrade or rebuild event of the container is detected, the allocation set object used by the container is obtained from the annotation information of the container; Based on the allocation set object, obtain the IP address record object corresponding to the allocation set object and the usage status of each IP address record object; If it is determined that there is an IP address record object in the IP address record object corresponding to the allocation set object that is in an unused state, then an unused IP address record object is allocated to the container.
2. The method according to claim 1, characterized in that, Also includes: If it is determined that the usage status of all IP address record objects corresponding to the allocation set object is "used", then a first IP address record object is created corresponding to the allocation set object, and an IP address is assigned to the first IP address record object; wherein, the first IP address record object is a new IP address record object; Assign the first IP address record object to the container and mark the usage status of the first IP address record object as used.
3. The method according to claim 1, characterized in that, Also includes: If it is determined that the usage status of all IP address record objects corresponding to the allocation set object is "used", then a second IP address record object is created to correspond to the allocation set object, and an IP address is assigned to the second IP address record object; wherein, the second IP address record object is a new IP address record object; Assign the second IP address record object to the container and mark the usage status of the second IP address record object as used.
4. The method according to claim 3, characterized in that, Also includes: If it is determined that the allocation set object is a whitelist object, then an IP address whitelist addition request is sent, and the IP address whitelist addition request carries the IP address corresponding to the second IP address record object.
5. The method according to claim 1, characterized in that, The steps to create an allocation set object include: Receive a request to create an allocation set object, the request for creating the allocation set object including the configuration information of the allocation set object; The allocation set object is created based on the IP address list or the number of IP address record objects included in the configuration information of the allocation set object.
6. The method according to claim 1, characterized in that, Also includes: Receive a deletion request for a container, wherein the deletion request for the container includes the identifier corresponding to the container; Based on the identifier corresponding to the container, the IP address record object corresponding to the container is obtained by querying; Change the usage status of the IP address record object corresponding to the container to unused.
7. The method according to any one of claims 1 to 6, characterized in that, The IP address includes IPv4 address and IPv6 address.
8. A container IP address allocation device for a container cloud platform, characterized in that, include: The first receiving unit is used to receive a container creation request. The container creation request carries the container's annotation information, which includes the allocation set object used by the container. The allocation set object is a pre-created Kubernetes custom resource object, corresponding to multiple IP address record objects, each with a corresponding IP address. The allocation set object is used to record a set of IP address record objects and the usage status of each IP address record object. When the container is created, the binding between the container and the allocation set object used by the container is achieved by declaring the allocation set used. The first query unit is used to query and obtain multiple IP address record objects corresponding to the allocation set object and the usage status of each IP address record object based on the allocation set object. The first allocation unit is configured to allocate an unused IP address record object to the container after determining that there is an unused IP address record object among the multiple IP address record objects corresponding to the allocation set object. The monitoring unit is used to obtain the allocation set object used by the container from the annotation information of the container if an application upgrade or rebuild event corresponding to the container is detected. The second query unit is used to query the IP address record object corresponding to the allocation set object and the usage status of each IP address record object based on the allocation set object. The second allocation unit is used to allocate an unused IP address record object to the container after determining that there is an unused IP address record object in the IP address record object corresponding to the allocation set object.
9. The apparatus according to claim 8, characterized in that, Also includes: The first creation unit is configured to, after determining that the usage status of all IP address record objects corresponding to the allocation set object is "used", create a first IP address record object corresponding to the allocation set object and allocate an IP address to the first IP address record object; wherein, the first IP address record object is a new IP address record object; The third allocation unit is used to allocate the first IP address record object to the container and mark the usage status of the first IP address record object as used.
10. The apparatus according to claim 8, characterized in that, Also includes: The second creation unit is used to create a second IP address record object corresponding to the allocation set object after determining that the usage status of all IP address record objects corresponding to the allocation set object is "used", and to allocate an IP address to the second IP address record object; wherein, the second IP address record object is a new IP address record object; The fourth allocation unit is used to allocate the second IP address record object to the container and mark the usage status of the second IP address record object as used.
11. The apparatus according to claim 10, characterized in that, Also includes: The sending unit is configured to send an IP address whitelist addition request after determining that the allocation set object is a whitelist object, the IP address whitelist addition request carrying the IP address corresponding to the second IP address record object.
12. The apparatus according to claim 8, characterized in that, Also includes: The second receiving unit is used to receive a creation request for an allocation set object, wherein the creation request for the allocation set object includes the configuration information of the allocation set object; The third creation unit is used to create the allocation set object based on the IP address list or the number of IP address record objects included in the configuration information of the allocation set object.
13. The apparatus according to claim 8, characterized in that, Also includes: The third receiving unit is used to receive a deletion request for a container, wherein the deletion request for a container includes the identifier corresponding to the container; The third query unit is used to query and obtain the IP address record object corresponding to the container based on the identifier corresponding to the container; The change unit is used to change the usage status of the IP address record object corresponding to the container to unused.
14. The apparatus according to any one of claims 8 to 13, characterized in that, The IP address includes IPv4 address and IPv6 address.
15. A computer device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, When the processor executes the computer program, it implements the method according to any one of claims 1 to 7.
16. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program that, when executed by a processor, implements the method of any one of claims 1 to 7.
17. A computer program product, characterized in that, The computer program product includes a computer program that, when executed by a processor, implements the method of any one of claims 1 to 7.