Pod IP address allocation method and device, medium and electronic equipment

By obtaining the IP address of the Pod to be evicted as a reserved IP address and obtaining different IP addresses from the storage component to allocate to the target Pod, the IP address exchange problem caused by Pod reconstruction in the Redis cluster is solved, ensuring the stability and stability of cluster communication. normal operation of the topology.

CN118694746APending Publication Date: 2024-09-24NEW ORIENTAL EDUCATION & TECH GRP CO LTD
View PDF 0 Cites 1 Cited by

Patent Information

Application Number
CN202411039924.2
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-07-31
Publication Date
2024-09-24

AI Technical Summary

Technical Problem

In the Redis cluster deployed by Kubernetes, IP address recycling and reassignment during Pod reconstruction lead to communication chaos. Existing technology cannot effectively avoid IP address exchange and black hole routing problems, affecting cluster topology and communication stability.

Method used

Obtain the IP address of the Pod to be evicted as a reserved IP address, store it in the reserved component, and obtain different IP addresses from the storage component that stores multiple IP addresses to allocate to the Pod to be allocated, ensuring that the target Pod is consistent with the Pod to be evicted. The IP addresses are different to avoid IP address swapping.

Benefits of technology

It effectively avoids IP address exchange between Redis clusters, ensures normal communication within the cluster and between different clusters, reduces the risk of client connection errors, and improves the stability of the server and business end.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118694746A
    Figure CN118694746A
Patent Text Reader

Abstract

The invention provides a Pod IP address allocation method and device, a medium and electronic equipment, and relates to the technical field of communication, and the method comprises the steps: obtaining an IP address of a to-be-expelled Pod as a reserved IP address, and storing the reserved IP address into a reserved component; the Pod with the IP address to be allocated is obtained to serve as a target Pod, and the Pod to be expelled and the target Pod belong to different Redis clusters; the IP address different from the reserved IP address in the reserved component is acquired from the storage component storing the plurality of IP addresses as the target IP address, the target IP address is allocated to the target Pod, and the target IP address allocated by the target Pod is different from the reserved IP address used by the Pod to be expelled, so that the IP addresses between different Redis clusters are prevented from being exchanged; therefore, normal communication in different clusters and between different clusters is realized.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present disclosure relates to the field of communication technology, and in particular to a method, device, medium and electronic device for allocating an IP address of a Pod. Background Art

[0002] Kubernetes is a container-based cluster management platform. The Redis cluster deployed by Kubernetes includes multiple computing nodes (Node). Multiple container groups (Pod) are deployed in each computing node. Each container group encapsulates one or more containers (Container) for carrying software programs. A Pod has only one IP address, and multiple containers in the same Pod share the IP address. When a Pod is rebuilt, the IP address of the Pod will be recycled. If the IP address is used for other Pods immediately, it will cause communication confusion. Summary of the invention

[0003] The present disclosure provides a method, device, medium and electronic device for allocating IP addresses of a Pod, aiming to solve the above-mentioned problem.

[0004] In order to achieve the above-mentioned object, the present disclosure provides a method for allocating IP addresses of Pods, the method comprising: obtaining an IP address of a Pod to be evicted as a reserved IP address, and storing the reserved IP address in a reserved component; obtaining a Pod to which an IP address is to be allocated as a target Pod, wherein the Pod to be evicted and the target Pod belong to different Redis clusters; obtaining an IP address different from the reserved IP address in the reserved component from a storage component storing multiple IP addresses as a target IP address, and allocating the target IP address to the target Pod.

[0005] Optionally, the storage component includes a first storage area and a second storage area, the reserved IP address is stored in the first storage area, and the allocatable IP address is stored in the second storage area, and obtaining an IP address different from the reserved IP address in the reserved component as the target IP address from a storage component storing multiple IP addresses includes: obtaining the allocatable IP address from the second storage area of ​​the storage component as the target IP address.

[0006] Optionally, the method further includes: when the reserved IP address in the reserved component meets a preset condition, deleting the reserved IP address from the reserved component, and storing the reserved IP in the first storage area of ​​the storage component into the second storage area.

[0007] Optionally, after obtaining the IP address of the Pod to be evicted as the reserved IP address, the method further includes: Storing the storage time of the reserved IP address in the reservation component into the configuration mapping component; When the reserved IP address in the reserved component meets a preset condition, deleting the reserved IP address from the reserved component includes: Obtaining the storage time corresponding to the reserved IP address from the configuration mapping component; Calculate the storage duration of the reserved IP address in the reserved component according to the storage time and the current time; When the storage duration corresponding to the reserved IP address in the reserved component is greater than the preset duration, the reserved IP address is deleted from the reserved component.

[0008] Optionally, after obtaining the IP address of the Pod to be evicted as the reserved IP address, the method further includes: storing the reserved IP address in the configuration mapping component at the time of storing the reserved IP address in the reservation component, wherein the configuration mapping component stores N reserved IP addresses, where N is a positive integer; when the reserved IP address in the reservation component meets a preset condition, deleting the reserved IP address from the reservation component, including: when the number of the reserved IP addresses in the reservation component N exceeds When it is greater than a preset number M, obtain N storage moments from the configuration mapping component, where M is a positive integer; calculate the storage duration of each of the N reserved IP addresses in the reserved component according to the N storage moments and the current moment; determine (NM) target durations and M reserved durations from the N storage durations, where any one of the (NM) target durations is greater than any one of the M reserved durations; and delete the (NM) reserved IP addresses corresponding to the (NM) target durations from the reserved component.

[0009] Optionally, the storage component further includes a third storage area, and the third storage area is used to store the allocated IP addresses. After allocating the target IP address to the target Pod, the method further includes: storing the target IP address from the second storage area into the third storage area.

[0010] Optionally, allocating the target IP address to the target Pod includes: allocating the target IP address to the target Pod by controlling an address management component.

[0011] The present disclosure also provides a device for allocating IP addresses of Pods, the device comprising: a reservation module, used to obtain the IP address of the Pod to be evicted as the reserved IP address, and store the reserved IP address in a reservation component; an acquisition module, used to obtain the Pod to which the IP address is to be allocated as a target Pod, wherein the Pod to be evicted and the target Pod belong to different Redis clusters; an allocation module, used to obtain an IP address different from the reserved IP address in the reservation component from a storage component storing multiple IP addresses as the target IP address, and allocate the target IP address to the target Pod.

[0012] The present disclosure also provides a non-temporary computer-readable storage medium having a computer program stored thereon, which implements the steps of the method described in the first aspect when the program is executed by a processor.

[0013] The present disclosure also provides an electronic device, the electronic device comprising: a memory having a computer program stored thereon; A processor is used to execute the computer program in the memory to implement the steps of the method described in the first aspect.

[0014] The present disclosure provides a method, device, medium and electronic device for allocating IP addresses of Pods, which include obtaining an IP address of a Pod to be evicted as a reserved IP address, and storing the reserved IP address in a reserved component; obtaining a Pod to which the IP address is to be allocated as a target Pod, wherein the Pod to be evicted and the target Pod belong to different Redis clusters; then obtaining an IP address different from the reserved IP address in the reserved component from a storage component storing multiple IP addresses as the target IP address, and allocating the target IP address to the target Pod, wherein the target IP address allocated to the target Pod is different from the reserved IP address used by the Pod to be evicted, thereby avoiding the exchange of IP addresses between different Redis clusters, thereby enabling normal communication within different clusters and between different clusters.

[0015] Other features and advantages of the present disclosure will be described in detail in the following detailed description. BRIEF DESCRIPTION OF THE DRAWINGS

[0016] The accompanying drawings are used to provide a further understanding of the present disclosure and constitute a part of the specification. Together with the following specific embodiments, they are used to explain the present disclosure but do not constitute a limitation of the present disclosure. In the accompanying drawings: Figure 1 It is a flowchart of a method for allocating IP addresses of Pods shown in an exemplary embodiment of the present disclosure; Figure 2is a system topology diagram of a method for allocating IP addresses applied to a Pod, shown in an exemplary embodiment of the present disclosure; Figure 3 It is a flowchart of a method for allocating IP addresses of Pods shown in an exemplary embodiment of the present disclosure; Figure 4 It is a flowchart of a method for allocating IP addresses of Pods shown in an exemplary embodiment of the present disclosure; Figure 5 It is a block diagram of a device for allocating IP addresses of a Pod according to an exemplary embodiment; Figure 6 is a block diagram of an electronic device according to an exemplary embodiment; Figure 7 It is a block diagram of an electronic device according to an exemplary embodiment. DETAILED DESCRIPTION

[0017] Exemplary embodiments will be described in detail herein, examples of which are shown in the accompanying drawings. When the following description refers to the drawings, the same numbers in different drawings represent the same or similar elements unless otherwise indicated. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with the present disclosure. Instead, they are merely examples of devices and methods consistent with some aspects of the present disclosure as detailed in the appended claims.

[0018] Kubernetes is a container-based cluster management platform and a cloud-native technology for managing, troubleshooting, and automatically deploying containerized applications. The Redis cluster deployed by Kubernetes includes multiple computing nodes (Node). Multiple container groups (Pod) are deployed in each Node, and each container group encapsulates one or more containers (Container) for carrying software programs. A Pod has only one IP address, and multiple containers in the same Pod share the IP address. When a Pod is rebuilt, the IP address of the Pod will be recycled. If the IP address is used for other Pods immediately, this phenomenon can be understood as the exchange or change of the IP of the Pods of the two clusters, which will bring the following problems: (1) When instances in a Redis cluster communicate through the Gossip protocol, passwords are not verified, causing multiple Redis clusters to form a "large cluster". That is, multiple Redis clusters are considered to be one Redis cluster, making the topology inconsistent with expectations and causing communication confusion within the Redis cluster and between multiple Redis clusters. (2) The client of the original Pod will still connect to the old IP, but the IP is now occupied by another cluster, causing the client of the original Pod to connect to the wrong cluster, causing communication confusion. In addition, if the password is incorrect, it will keep retrying, which will cause interruptions to the client system.

[0019] When applying Kubernetes, it is very important to manage and configure container networks. As a third-party container network plug-in for Kubernetes, Calico provides a container network solution for Kubernetes, allowing containers in the cluster to communicate with each other and interact with external networks. For example, the IP address of the Pod is automatically and dynamically assigned by Calico. However, as the Pod is rebuilt, the IP address assigned by Calico may change, that is, the aforementioned IP is exchanged. For containerized Redis clusters, Pod reconstruction may be unavoidable. How to ensure that the Redis cluster topology is not confused, the client does not connect to the wrong cluster, and ensure the stable operation of the server and business ends is imminent.

[0020] Based on this, the prior art provides a fixed IP solution based on the Host-local CNI plug-in and fixed nodes: Kube-controller-manager assigns non-conflicting IP segments to each Kubernetes Node object, which are stored in Node.Spec.PodCIDR, and Host-local uses the IP segment for IP allocation. To implement a fixed IP, the Pod must first be rebuilt and scheduled to the original host, and secondly, the IP information of each Pod must be recorded in a file. When a Pod is created for the first time, the relevant information of the Pod's IP address is recorded in a file. When the Pod is rebuilt next time, the IP address is taken from the corresponding file and assigned to the Pod.

[0021] The existing technology also provides a solution for creating a Pod by specifying an IP: Calico IPAM supports starting the Pod by specifying an IP in the Pod's Annotation, for example: "cni.projectcalico.org / ipAddrs":"[\"192.168.0.1\"]". In this way, when IPAM (IP address management) allocates an IP, it will allocate the IP to the Pod each time, achieving the effect of a fixed IP.

[0022] The inventors found that the fixed IP solution based on the Host-local CNI plug-in and fixed nodes has the following problems: (1) In the usual mechanism, since the Kubernetes scheduler makes decisions based on multiple algorithms, such as node resource utilization, node selector, storage affinity, etc., all hosts in the cluster (hosts can be considered as nodes) are filtered and scored, and a host with the highest score is selected. The host with the highest score will run the rebuilt Pod, so each time a Pod is rebuilt, it will be randomly assigned to a host. Secondly, a Redis cluster has multiple Pods. In order to ensure high availability, it is necessary to ensure that the Pods are not on the same host as much as possible. Based on the Host-local CNI plug-in and the fixed IP solution of the fixed node, it is necessary to add a node selector each time the Pod is created through the Webhook mechanism on the basis of the usual mechanism, but this violates the scheduling principle.

[0023] (2) Based on the previous problem, the fixed IP solution based on the Host-local CNI plug-in and fixed nodes can only be scheduled based on storage affinity. When the Pod is first created, the scheduler selects a node, and CSI (Channel State Information) provides storage volumes on the node. After the Pod is rebuilt, the scheduler will automatically schedule it to the original node based on the storage volume. This requires that the host must store the relevant information of the Pod and the IP address information that is fixedly associated with the Pod.

[0024] (3) Currently, the Calico Host-local CNI plug-in does not support fixed IP addresses, and secondary development is required on this basis: add the Pod's IP address to a file for persistent storage, reassign the original IP address to the Pod after reconstruction, and add a timed release of the IP address function. The above changes need to be merged with the upgrade of the Calico version.

[0025] The inventors also found that the solution of creating a Pod based on a specified IP has the following problems: (1) This solution requires specifying an IP address before creating a Pod. This IP address cannot conflict with the IP addresses already allocated in the cluster. This requires the development of a specified IP address allocation mechanism to obtain all IP addresses and occupied IP addresses from the cluster, calculate the free IP addresses for allocation.

[0026] (2) Since stateless services and stateful services are deployed in a mixed manner in the Kubernetes cluster, how to ensure that the IP address is not assigned to the stateless service at the moment of Pod reconstruction? A new mechanism needs to be developed to ensure this requirement. There are three main solutions: a). Modify the code for allocating and releasing IP addresses in Calico IPAM; b). Maintain an IPReservation CR object and add the IP address to be reserved when deleting the Pod, so that Calico will not assign the IP address corresponding to the Pod to the Pod; c). All stateless and stateful Pods in the cluster have specified IP addresses; (3) If the Pod is not scheduled to the original host when it is rebuilt, that is, the created Pod runs on other hosts, it is necessary to enable IP borrowing, but this will lead to the blackhole routing problem, that is, Calico will allocate an IPAMBlock (i.e., an IP block) to each Kubernetes Node. When allocating an IPAMBlock, it will add a blackhole (for example, 172.24.143.32 / 28) to the host that is close to the IPAMBlock (for example, 172-24-143-32-28 and other 16 IPs). When there is no detailed route with a higher priority (172.24.143.33 dev calibfccc3056f0 scope link), it will be discarded by the blackhole. When the IP is guaranteed to not exist, the request is not extended to the router until it knows that the target is unreachable, causing pressure on the router. If the Pod is rebuilt and drifted to another host, the original IP address is required to be used under the solution of specifying the IP to create the Pod. The IP address in the IPAMBlock on the original host needs to be borrowed, resulting in the Pod on the old host being unable to access the IP address on the new host, and the access information is lost by the blackhole on the old host. This will cause the communication between Redis cluster instances to be unreachable.

[0027] (4) If IP borrowing is not enabled, the Pod will fail to allocate an IP address when it is scheduled to a new host after reconstruction. Therefore, it can only be scheduled to the original host. This requires considering how to schedule to the original host.

[0028] In view of the above technical problems, the inventors have discovered and proposed a method, device, medium and electronic device for allocating IP addresses to Pods after long-term research. The IP address of the Pod to be evicted is used as a reserved IP address. When the Pod to be allocated an IP address needs to be allocated an IP address, an IP address other than the reserved IP address is selected and allocated to the Pod to be allocated an IP address, thereby avoiding chaotic communication between the containers of the Pod to be evicted and the Pod to be allocated an IP address. The specific method for allocating IP addresses to Pods is described in the subsequent embodiments.

[0029] To do this, see Figure 1 , Figure 1is a flow chart of a method for allocating IP addresses of a Pod shown in an exemplary embodiment of the present disclosure. The method for allocating IP addresses of a Pod can be applied to Figure 2 The method 100 for allocating IP addresses of Pods, electronic devices, and computer-readable storage media shown in the figure. In this embodiment, an electronic device is used as an example, wherein the electronic device can be a server, and the server can be an independent physical server, or a server cluster or distributed system composed of multiple physical servers, or a cloud server. Figure 1 The process shown is described in detail, and the method for allocating IP addresses of the Pod may specifically include the following steps: Step S110: Obtain the IP address of the Pod to be evicted as a reserved IP address, and store the reserved IP address in a reserved component.

[0030] Due to the limitation of the central processing unit (CPU) and memory of the Redis cluster, the application running on the Pod crashes, fails to respond to requests, and other errors occur, the host where the Pod is located fails or is under maintenance, the resource limitations of the host where the Pod is located, or the operator manually modifies or deletes the Pod, the Pod associated with it will be evicted. The expulsion in this step can be understood as being deleted, where the expulsion can include active expulsion, such as when the electronic device receives the Delete operation corresponding to the Pod, the Pod is actively expelled. Expulsion can also include passive expulsion, such as when the electronic device receives the Drain operation corresponding to the Pod, the Pod is passively expelled.

[0031] The electronic device is connected to multiple hosts. When a Pod is deleted at a certain host, the Pod is a Pod to be evicted. The host will initiate a deletion request with relevant information of the Pod to be evicted. The relevant information may include information about the Pod itself and the IP address configured for the Pod to be evicted, and the host will send the deletion request to the electronic device through the Kube-APIServer component on the electronic device side. Among them, Kube-APIServer mainly provides some API (Application Programming Interface) interfaces. The storage component stores all IP addresses of each Redis cluster in the multiple Redis clusters it manages. The reserved component of the electronic device is used to store IP addresses that are not allocated temporarily. For example, the storage component is Etcd and the reserved component is IPReservations. After obtaining the deletion request, the electronic device stores the IP address of the Pod to be evicted as a reserved IP address in the reserved component, which means that the reserved IP address is not allocated to the Pod that needs the IP address temporarily. For example, the IP address 201.24.136.21 is a reserved IP address.

[0032] Optionally, the Pod to be evicted can be a stateful service Pod. A stateful service (StatefulSet) can be understood as a correlation between data or information. The electronic device obtains a deletion request, and when the information of the Pod to be evicted carried in the deletion request meets the characteristics of a stateful service, for example, when the label of the Pod carried in the deletion request contains statefulset.kubernetes.io / pod-name, it is confirmed that it meets the characteristics of a stateful service, and the IP address of the Pod to be evicted is used as the reserved IP address. Otherwise, the information of the Pod to be evicted does not meet the characteristics of a stateful service, that is, the information of the Pod to be evicted meets the characteristics of a stateless service, and there is no need to reserve the IP address of the Pod to be evicted.

[0033] Step S120: Acquire a Pod to which an IP address is to be assigned as a target Pod, wherein the Pod to be evicted and the target Pod belong to different Redis clusters.

[0034] It is understandable that the target Pod is a Pod that has been rebuilt and has not yet been assigned an IP address.

[0035] Step S130: Acquire an IP address different from the reserved IP address in the reserved component as a target IP address from a storage component storing multiple IP addresses, and assign the target IP address to the target Pod.

[0036] The Pod to be evicted and the target Pod belong to different Redis clusters. To avoid confusion in communication between different Redis clusters, the reserved IP address is not allocated to the target Pod. An IP address different from the reserved IP address in the reserved component is obtained from a storage component storing multiple IP addresses as the target IP address. It can be understood that the target IP address is different from the reserved IP address. The target IP address is allocated to the target Pod.

[0037] Optionally, the target Pod in this embodiment may be a stateful service Pod.

[0038] The method for allocating IP addresses of Pods provided in this embodiment obtains the IP address of the Pod to be evicted as the reserved IP address, and stores the reserved IP address in the reserved component; obtains the Pod to which the IP address is to be allocated as the target Pod, wherein the Pod to be evicted and the target Pod belong to different Redis clusters; then obtains an IP address different from the reserved IP address in the reserved component from a storage component storing multiple IP addresses as the target IP address, and allocates the target IP address to the target Pod, wherein the target IP address allocated to the target Pod is different from the reserved IP address used by the Pod to be evicted, thereby avoiding the exchange of IP addresses between different Redis clusters, thereby enabling normal communication within different clusters and between different clusters.

[0039] In one embodiment, the storage component includes a first storage area and a second storage area. The first storage area stores a reserved IP address. Exemplarily, when the reserved IP address is stored in the reserved component, the reserved IP address is stored in the first storage area. It is possible that the reserved IP address in the first storage area is also unallocatable. The second storage area stores an allocable IP address that can be used by the rebuilt Pod. Step S130 may include: obtaining an allocable IP address from the second storage area of ​​the storage component as the target IP address.

[0040] Each Redis cluster in the multiple Redis clusters includes one or more Pods, each Pod needs to be configured with an IP address, and all Pods may be rebuilt, and the rebuilt Pods need to be assigned new IP addresses. In the aforementioned process, there is IP address recovery and reservation in the reserved component, so the IP address is constantly consumed, and the unallocated reserved IP addresses accumulated in the reserved component are increasing, so that the allocable IP addresses are constantly decreasing. In order to ensure that the Pod can be assigned an IP address, the normal communication of the container inside the Pod is guaranteed, and the Pods in the Redis cluster can communicate normally. Therefore, a release mechanism can be set for the reserved IP address to release the reserved IP address for subsequent Pod use. Exemplarily, when the reserved IP address in the reserved component meets the preset conditions, the reserved IP address is released, such as deleting the reserved IP address from the reserved component, and storing the reserved IP in the first storage area of ​​the storage component in the second storage area. It can be understood that the reserved IP address does not exist in the reserved component and the first storage area.

[0041] After obtaining the IP address of the Pod to be evicted as the reserved IP address, the method for allocating the IP address of the Pod also includes: storing the storage time of the reserved IP address in the reserved component in a configuration mapping component, for example, the configuration mapping component can be IP Info ConfigMaps, and optionally, the configuration mapping component stores the correspondence between the reserved IP address and the storage time corresponding to the reserved IP address. In one embodiment of releasing the reserved IP address, the storage time corresponding to the reserved IP address is obtained from the configuration mapping component, for example, the storage time can be 12:00. According to the storage time and the current time, the storage duration of the reserved IP address in the reserved component is calculated, for example, the time difference between the current time and the storage time is calculated as the storage duration, and the current time can be the time when the storage time corresponding to the reserved IP address is read from the configuration mapping component, or it can be the time when the storage duration is started. When the storage duration corresponding to the reserved IP address in the reservation component is greater than the preset duration, there is enough time to delete the topology information corresponding to the Pod to be evicted, the IP address of the Pod to be evicted in the cluster where the Pod to be evicted is located, etc., and there will be no communication confusion when the reserved IP is allocated to other Pods. Therefore, the reserved IP address can be deleted from the reservation component for subsequent allocation to ensure that there are enough IP addresses available for allocation.

[0042] After obtaining the IP address of the Pod to be evicted as the reserved IP address, the method for allocating the IP address of the Pod also includes: storing the reserved IP address in the configuration mapping component at the storage time of the reserved component, for example, the configuration mapping component can be IP Info ConfigMaps. Wherein, the configuration mapping component stores N reserved IP addresses, and N is a positive integer. It should be noted that the N reserved IP addresses in the configuration mapping component may not be stored at one time, but gradually accumulated as Pods are evicted in the cluster. In another embodiment of releasing the reserved IP address, when the number N of the reserved IP addresses in the reservation component is greater than the preset number M, N storage times are obtained from the configuration mapping component, where M is a positive integer, for example, M can be 100, and M can also be set as follows: obtain the host with the largest number of running Pods among all hosts in the Redis cluster, and the number of running Pods is maxPods, and the preset multiple of maxPods is M, and optionally, the preset multiple can be 1.2 times, 2 times, 3.1 times, etc. According to the N storage moments and the current moment, the storage duration of each of the N reserved IP addresses stored in the reserved component is calculated. For example, the time difference between the current moment and the storage moment is calculated as the storage duration. The current moment may be the moment of reading the storage moment corresponding to the reserved IP address from the configuration mapping component, or the moment of starting to calculate the storage duration. From the N storage durations, (NM) target durations and M reserved durations are determined, wherein any one of the (NM) target durations is greater than any one of the M reserved durations. It can be understood that the (NM) longest ones are selected as the target durations from the N storage durations. The (NM) reserved IP addresses corresponding to the (NM) target durations are deleted from the reserved component so that the reserved IP addresses in the reserved component are kept within M. The deleted reserved IP addresses are used for subsequent allocation to ensure that there are enough IP addresses to be allocated so that the communication of the Redis cluster can be carried out continuously.

[0043] Optionally, the storage component further includes a third storage area, and the third storage area is used to store the allocated IP addresses. After step S130, the method for allocating IP addresses of the Pod further includes: storing the target IP address from the second storage area into the third storage area. The first storage area in the storage component stores non-allocatable IP addresses, the second storage area stores allocable IP addresses, and the third storage area stores allocated IP addresses, so that multiple IP addresses are reasonably managed.

[0044] In one implementation, step S130 includes: allocating the target IP address to the target Pod by controlling the address management component.

[0045] For example, the reservation component is the IPReservations component and the configuration mapping component is the IP InfoConfigMap component. Figure 2 The topology diagram includes: a user terminal 210 and an electronic device 220 connected to the client, wherein the electronic device may be a server. The electronic device 220 includes a Kube-APIServer component, a Capo component, an IPReservations component, an IP Info ConfigMap component, and Calio Networking. The Capo component is a self-developed component, and the Capo component includes a Webhook Server module and a Timer module.

[0046] The client 210 initiates a deletion request due to a Drain operation or a Delete operation, and the electronic device 220 receives the deletion request through the Kube-APIServer component thereon. In response to the deletion request, the electronic device stores the reserved IP address corresponding to the Pod to be evicted carried in the deletion request received by the Kube-APIServer component into the IPReservations component through the WebhookServer module in the Capo component, and stores the storage time corresponding to the reserved IP address into the IP Info ConfigMap component through the Timer module in the Capo component.

[0047] The reserved IP address (that is, the aforementioned storage of the reserved IP address in the reserved component) and the release strategy of the reserved IP address are all through Figure 2 For example, the electronic device deletes the reserved IP address from the reserved component through the Capo component when the reserved IP address in the reserved component meets the preset condition, and stores the reserved IP in the first storage area of ​​the storage component into the second storage area.

[0048] The IP address allocation strategy is implemented through the address management component, the address management component (IP Address Management, referred to as IPAM). The address management component is located in Figure 2 Shown in Calio Networking.

[0049] The address management component originally has the function of allocating IP addresses. If the reserved IP addresses, reserved IP address release and other strategies in this embodiment are integrated into the address management component, then the address management component needs to be redeveloped. However, the address management component in Calio Networking is associated and coupled with the other components in Calio Networking. In the process of developing the address management component, the other components in Calio Networking will inevitably be considered, resulting in high development difficulty and high development cost. This embodiment uses a separate Capo component, which is not coupled with the components in Calio Networking. When developing the Capo component, there is no need to consider the components in Calio Networking, which reduces the development and transformation costs. The present disclosure uses the existing features of Kubernetes CRD, Webhook and Calico, and combines the existing capabilities to develop new components (i.e., Capo components) to solve the problem of Redis cluster anomalies in cloud native scenarios. In addition, since the Capo component has little correlation with other existing components, the Capo component has good compatibility and does not need to be secondary developed in the Calico CNI source code, so there is no need to consider the compatibility issues of later Calico version upgrades. In addition, the Capo component also has the advantages of low deployment cost (that is, the Capo component runs in Kubernetes in the form of a container, with high deployment efficiency) and high availability (that is, Capo runs three instances at the same time, and the three instances serve as backup for each other, ensuring high concurrency when calling Webhook, and supporting automatic expansion).

[0050] It should be noted that the role of the Kube-APIServer component is to provide a communication interface. Figure 2 Only the Kube-APIServer component for communication between the client 210 and the electronic device 220 is shown. In fact, the connection between each component in the electronic device requires the Kube-APIServer component to provide a communication interface. The Kube-APIServer component between each component is in Figure 2 Not shown.

[0051] It should also be noted that the explanations of the deposit time, reserved IP address, Pod to be evicted, etc. involved in this embodiment can be found in the aforementioned embodiments and will not be repeated in this embodiment.

[0052] Combination Figure 2 , reserve the IP address of the Pod to be evicted, that is, the step of storing the reserved IP address in the reservation component, refer to Figure 3, this step includes: Kubectl (Kubernetes command line tool) or Client (user end) generates a deletion request for expelling or deleting the Pod of the Redis cluster, and the Pod requested to be deleted in the deletion request is the aforementioned Pod to be evicted; Kubectl or Client receives the deletion request through the Kube-APIServer component; the deletion request received through the Kube-APIServer component is then called by the Webhook Server module in the Capo component to reserve the reserved IP address of the Pod to be evicted in IPReservations, and persist the reserved IP address in the Etcd component. Persistence in the Etcd component can be understood as persistently storing the reserved IP address in the first storage area; after persistence is successful, the Etcd component returns the persistence information through the Kube-APIServer component; the returned persistence information is returned to the Capo component through the Kube-APIServer component. It is also necessary to save the storage time corresponding to the reserved address, and store the storage time in the configuration mapping component ConfigMaps through the Timer module in Capo. In addition, the storage time needs to be synchronized and persisted in the Etcd component, such as Figure 3 , send the aforementioned storage time to the Etcd component through the Kube-APIServer component, control the Etcd component to persistently store the storage time, and return the persistent information returned by the Etcd component to the Capo component through the Kube-APIServer component. After the aforementioned storage of the reserved IP address and its storage time is completed, the Capo component returns a successful Pod deletion, and then the Kube-APIServer component returns a successful Pod deletion message to Kubectl or Client to instruct Kubectl or Client to locally delete the relevant information of the Pod to be deleted.

[0053] Optionally, the Capo component detects whether the IP address needs to be released once every preset period. For example, the preset period may be 5 seconds.

[0054] Optionally, in Figure 3 After the reserved IP address ends, Kube-APIServer sends a deletion request, triggering Kubelet to release IP resources and call Calico CNI to execute cmdDel logic to release the Pod IP. Among them, Calico CNI and Kubelet are both components in Calio Networking, and their functions are similar to the IPAM component in Calio Networking, both of which are used to manage IP addresses.

[0055] Combination Figure 2 , the mechanism for releasing IP addresses can be found in Figure 4 , including: formulating a scheduled task in the Capo component, judging through the Capo component that the reserved IP address meets the timing condition, that is, the storage duration corresponding to the reserved IP address is greater than the preset duration, and using the Kube-APIServer component through the Capo component to control ConfigMaps to release the reserved IP address that meets the condition, that is, deleting the reserved IP address from the reserved component, and storing the reserved IP in the first storage area of ​​the storage component into the second storage area, and calling Kube-APIServer to persist to the Etcd component. Similarly, the storage time is deleted in the IP Info ConfigMaps resource object, and Kube-APIServer is called to persist to the Etcd component.

[0056] The method for allocating IP addresses for Pods provided in this embodiment allocates the target IP address to the target Pod by controlling the address management component IPAM. Calico IPAM will not automatically allocate the IP in the IPReservations resource object to the container, but allocates it from the remaining IPs, so that the target IP address is different from the reserved IP address, so the IP address will not be exchanged, and the cluster topology will not be confused when the Redis cluster instances communicate using the Gossip protocol because they cannot connect to the old IP. Operator (an automated management tool) will add the newly created Pod to the cluster, and the Pod to be evicted will be deleted to ensure that the cluster topology returns to normal. The client where the target Pod is located can connect to the correct Pod after the topology is refreshed.

[0057] To implement the above method embodiment, the present disclosure provides a device for allocating IP addresses of Pods, see Figure 5 , the device 300 for allocating IP addresses of Pods includes: a reservation module 310, an acquisition module 320 and an allocation module 330; A reservation module 310 is used to obtain the IP address of the Pod to be evicted as a reserved IP address, and store the reserved IP address in a reservation component; An acquisition module 320 is used to acquire a Pod to which an IP address is to be assigned as a target Pod, wherein the Pod to be evicted and the target Pod belong to different Redis clusters; The allocation module 330 is used to obtain an IP address different from the reserved IP address in the reserved component from a storage component storing multiple IP addresses as a target IP address, and allocate the target IP address to the target Pod.

[0058] Optionally, the storage component includes a first storage area and a second storage area, the first storage area stores the reserved IP addresses, and the second storage area stores the assignable IP addresses, and the assigning module 330 includes: a first target IP address assigning module; The first target IP address allocation module is used to obtain an allocatable IP address from the second storage area of ​​the storage component as the target IP address.

[0059] Optionally, the device 300 for allocating the IP address of the Pod further includes: a release module; A release module is used to delete the reserved IP address from the reserved component when the reserved IP address in the reserved component meets a preset condition, and store the reserved IP in the first storage area of ​​the storage component into the second storage area.

[0060] Optionally, the device 300 for allocating an IP address of a Pod further includes: a first storage module; A first storage module, used for storing the storage time of the reserved IP address into the reserved component into the configuration mapping component; The release module includes: a second storage module, a first duration calculation module and a first release module; A second storage module, used for obtaining the storage time corresponding to the reserved IP address from the configuration mapping component; A first duration calculation module, used for calculating the storage duration of the reserved IP address stored in the reserved component according to the storage time and the current time; The first releasing module is used to delete the reserved IP address from the reserved component when the storage duration corresponding to the reserved IP address in the reserved component is greater than a preset duration.

[0061] Optionally, the device 300 for allocating the IP address of the Pod further includes: a third storage module; A third storage module, used for storing the storage time of the reserved IP address into the reservation component into the configuration mapping component, wherein the configuration mapping component stores N reserved IP addresses, and N is a positive integer; The release module includes: a storage time acquisition module, a second duration calculation module, a determination module and a second release module; A storage time acquisition module, used for acquiring N storage times from the configuration mapping component when the number N of the reserved IP addresses in the reservation component is greater than a preset number M, where M is a positive integer; A second duration calculation module, configured to calculate a storage duration of each of the N reserved IP addresses stored in the reserved component according to the N storage times and the current time; A determination module, used to determine (NM) target durations and M reserved durations from the N stored durations, wherein any one of the (NM) target durations is greater than any one of the M reserved durations; The second releasing module is used to delete the (NM) reserved IP addresses corresponding to the (NM) target durations from the reserved component.

[0062] Optionally, the storage component further includes a third storage area, and the third storage area is used to store the allocated IP addresses. The device 300 for allocating IP addresses of the Pod further includes: a fourth storage module; The fourth storing module is used to store the target IP address from the second storage area into the third storage area.

[0063] Optionally, the allocation module 330 includes: a second target IP address allocation module; The second target IP address allocation module is used to allocate the target IP address to the target Pod by controlling the address management component.

[0064] Regarding the device in the above embodiment, the specific manner in which each module performs operations has been described in detail in the embodiment of the method, and will not be elaborated here.

[0065] Figure 6 FIG. 1 is a block diagram of an electronic device according to an exemplary embodiment. Figure 6 As shown, the electronic device 700 may include: a processor 701 , a memory 702 . The electronic device 700 may also include one or more of a multimedia component 703 , an input / output (I / O) interface 704 , and a communication component 705 .

[0066] The processor 701 is used to control the overall operation of the electronic device 700 to complete all or part of the steps in the above-mentioned method for allocating the IP address of the Pod. The memory 702 is used to store various types of data to support the operation of the electronic device 700. For example, these data may include instructions for any application or method used to operate on the electronic device 700, and application-related data, such as contact data, messages sent and received, pictures, audio, video, etc. The memory 702 can be implemented by any type of volatile or non-volatile storage device or a combination thereof, such as static random access memory (Static Random Access Memory, referred to as SRAM), electrically erasable programmable read-only memory (Electrically Erasable Programmable Read-Only Memory, referred to as EEPROM), erasable programmable read-only memory (Erasable Programmable Read-Only Memory, referred to as EPROM), programmable read-only memory (Programmable Read-Only Memory, referred to as PROM), read-only memory (Read-Only Memory, referred to as ROM), magnetic memory, flash memory, disk or optical disk. The multimedia component 703 may include a screen and an audio component. The screen may be, for example, a touch screen, and the audio component is used to output and / or input audio signals. For example, the audio component may include a microphone for receiving external audio signals. The received audio signal may be further stored in the memory 702 or sent through the communication component 705. The audio component also includes at least one speaker for outputting audio signals. The I / O interface 704 provides an interface between the processor 701 and other interface modules, and the other interface modules may be keyboards, mice, buttons, etc. These buttons may be virtual buttons or physical buttons. The communication component 705 is used for wired or wireless communication between the electronic device 700 and other devices. Wireless communication, such as Wi-Fi, Bluetooth, Near Field Communication (NFC), 2G, 3G, 4G, NB-IOT, eMTC, or other 5G, etc., or a combination of one or more of them, is not limited here. Therefore, the corresponding communication component 705 may include: Wi-Fi module, Bluetooth module, NFC module, etc.

[0067] In an exemplary embodiment, the electronic device 700 may be implemented by one or more application specific integrated circuits (ASIC), digital signal processors (DSP), digital signal processing devices (DSPD), programmable logic devices (PLD), field programmable gate arrays (FPGA), controllers, microcontrollers, microprocessors or other electronic components to perform the above-mentioned method for allocating IP addresses to Pods.

[0068] In another exemplary embodiment, a computer-readable storage medium including program instructions is also provided, and when the program instructions are executed by a processor, the steps of the above-mentioned method for allocating IP addresses to Pods are implemented. For example, the computer-readable storage medium may be the above-mentioned memory 702 including program instructions, and the above-mentioned program instructions may be executed by the processor 701 of the electronic device 700 to complete the above-mentioned method for allocating IP addresses to Pods.

[0069] Figure 7 1 is a block diagram of an electronic device according to an exemplary embodiment. For example, the electronic device 1900 may be provided as a server. Figure 7 The electronic device 1900 includes a processor 1922, which may be one or more, and a memory 1932 for storing a computer program executable by the processor 1922. The computer program stored in the memory 1932 may include one or more modules each corresponding to a set of instructions. In addition, the processor 1922 may be configured to execute the computer program to perform the above-mentioned method for allocating IP addresses to Pods.

[0070] In addition, the electronic device 1900 may further include a power supply component 1926 and a communication component 1950, wherein the power supply component 1926 may be configured to perform power management of the electronic device 1900, and the communication component 1950 may be configured to implement communication of the electronic device 1900, for example, wired or wireless communication. In addition, the electronic device 1900 may further include an input / output (I / O) interface 1958. The electronic device 1900 may operate based on an operating system stored in the memory 1932.

[0071] In another exemplary embodiment, a computer-readable storage medium including program instructions is also provided, and when the program instructions are executed by a processor, the steps of the above-mentioned method for allocating IP addresses to Pods are implemented. For example, the non-transitory computer-readable storage medium may be the above-mentioned memory 1932 including program instructions, and the above-mentioned program instructions may be executed by the processor 1922 of the electronic device 1900 to complete the above-mentioned method for allocating IP addresses to Pods.

[0072] In another exemplary embodiment, a computer program product is also provided. The computer program product includes a computer program executable by a programmable device, and the computer program has a code portion for executing the above-mentioned method for allocating IP addresses of Pods when executed by the programmable device.

[0073] In summary, the method, device, medium and electronic device for allocating IP addresses of Pods provided by the present disclosure obtain the IP address of the Pod to be evicted as the reserved IP address, and store the reserved IP address in the reserved component; obtain the Pod to which the IP address is to be allocated as the target Pod, wherein the Pod to be evicted and the target Pod belong to different Redis clusters; then obtain an IP address different from the reserved IP address in the reserved component from a storage component storing multiple IP addresses as the target IP address, and allocate the target IP address to the target Pod, wherein the target IP address allocated to the target Pod is different from the reserved IP address used by the Pod to be evicted, thereby avoiding the exchange of IP addresses between different Redis clusters, thereby enabling normal communication within different clusters and between different clusters.

[0074] The preferred embodiments of the present disclosure are described in detail above in conjunction with the accompanying drawings; however, the present disclosure is not limited to the specific details in the above embodiments. Within the technical concept of the present disclosure, a variety of simple modifications can be made to the technical solution of the present disclosure, and these simple modifications all fall within the protection scope of the present disclosure.

[0075] It should also be noted that the various specific technical features described in the above specific embodiments can be combined in any suitable manner without contradiction. In order to avoid unnecessary repetition, the present disclosure will not further describe various possible combinations.

[0076] In addition, various embodiments of the present disclosure may be arbitrarily combined, and as long as they do not violate the concept of the present disclosure, they should also be regarded as the contents disclosed by the present disclosure.

Claims

1. A method for allocating IP addresses of Pods, characterized in that: The method comprises: Obtain the IP address of the Pod to be evicted as a reserved IP address, and store the reserved IP address in a reserved component; Obtain a Pod to which an IP address is to be assigned as a target Pod, wherein the Pod to be evicted and the target Pod belong to different Redis clusters; An IP address different from the reserved IP address in the reserved component is obtained from a storage component storing multiple IP addresses as a target IP address, and the target IP address is allocated to the target Pod.

2. The method according to claim 1, characterized in that The storage component includes a first storage area and a second storage area, the reserved IP address is stored in the first storage area, and the assignable IP address is stored in the second storage area, and the acquiring an IP address different from the reserved IP address in the reserved component as the target IP address from the storage component storing a plurality of IP addresses includes: An allocatable IP address is acquired from the second storage area of ​​the storage component as the target IP address.

3. The method according to claim 2, characterized in that Also includes: When the reserved IP address in the reserved component meets a preset condition, the reserved IP address is deleted from the reserved component, and the reserved IP in the first storage area of ​​the storage component is stored in the second storage area.

4. The method according to claim 3, characterized in that After obtaining the IP address of the Pod to be evicted as the reserved IP address, the following steps are further included: Storing the storage time of the reserved IP address in the reservation component into the configuration mapping component; When the reserved IP address in the reserved component meets a preset condition, deleting the reserved IP address from the reserved component includes: Obtaining the storage time corresponding to the reserved IP address from the configuration mapping component; Calculate the storage duration of the reserved IP address in the reserved component according to the storage time and the current time; When the storage duration corresponding to the reserved IP address in the reserved component is greater than the preset duration, the reserved IP address is deleted from the reserved component.

5. The method according to claim 3, characterized in that: After obtaining the IP address of the Pod to be evicted as the reserved IP address, the following steps are also included: Storing the reserved IP address in the reservation component at a storage time in the configuration mapping component, wherein the configuration mapping component stores N reserved IP addresses, where N is a positive integer; When the reserved IP address in the reserved component meets a preset condition, deleting the reserved IP address from the reserved component includes: When the number N of the reserved IP addresses in the reservation component is greater than a preset number M, obtaining N storage moments from the configuration mapping component, where M is a positive integer; Calculate the storage duration of each reserved IP address in the reserved component according to the N storage times and the current time; Determine (NM) target durations and M reserved durations from the N stored durations, wherein any one of the (NM) target durations is greater than any one of the M reserved durations; The (NM) reserved IP addresses corresponding to the (NM) target durations are deleted from the reserved component.

6. The method according to any one of claims 2 to 5, characterized in that: The storage component further includes a third storage area, the third storage area being used to store the allocated IP address, and after the target IP address is allocated to the target Pod, further including: The target IP address is stored from the second storage area into the third storage area.

7. The method according to any one of claims 1 to 5, characterized in that: The allocating the target IP address to the target Pod includes: The target IP address is allocated to the target Pod by controlling the address management component.

8. A device for allocating IP addresses to Pods, characterized in that: The device comprises: A reservation module is used to obtain the IP address of the Pod to be evicted as a reserved IP address, and store the reserved IP address in a reservation component; An acquisition module, used to acquire a Pod to which an IP address is to be assigned as a target Pod, wherein the Pod to be evicted and the target Pod belong to different Redis clusters; The allocation module is used to obtain an IP address different from the reserved IP address in the reserved component from a storage component storing multiple IP addresses as a target IP address, and allocate the target IP address to the target Pod.

9. A non-transitory computer-readable storage medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, the steps of the method described in any one of claims 1 to 7 are implemented.

10. An electronic device, characterized in that: include: a memory having a computer program stored thereon; A processor, configured to execute the computer program in the memory to implement the steps of the method according to any one of claims 1 to 7.

Citation Information

Cited By

  • Pod removal method in K8s cluster, medium and equipment

    CN120523557A