IP Allocation
English | 简体中文
When a pod is creating, it will follow steps below to get IP allocations.
- 
Get all IPPool candidates.
For which IPPool is used by a pod, the following rules are listed from high to low priority which means the previous rule would override the latter rule.
- SpiderSubnet annotation. 
ipam.spidernet.io/subnetsandipam.spidernet.io/subnetwill choose to use auto-created ippool if the SpiderSubnet feature is enabled. See SpiderSubnet for details. - Honor pod annotation. 
ipam.spidernet.io/ippools" and "ipam.spidernet.io/ippoolcould be used to specify an ippool. See Pod Annotation for details. - Namespace annotation. 
ipam.spidernet.io/defaultv4ippoolandipam.spidernet.io/defaultv6ippoolcould be used to specify an ippool. See namespace annotation for details. - CNI configuration file. It can be set to 
default_ipv4_ippoolanddefault_ipv6_ippoolin the CNI configuration file. See configuration for details. - Cluster default IPPool. We can set SpiderIPPool CR object with 
defaultproperty, in which we'll regard it as a default pool in cluster. See configuration for details. 
 - SpiderSubnet annotation. 
 - 
Filter valid IPPool candidates.
After getting IPv4 and IPv6 IPPool candidates, it looks into each IPPool and figures out whether it meets following rules, and learns which candidate IPPool is available.
- Filter terminating IPPools.
 - The 
disablefield of the IPPool isfalse. This property means the IPPool is not available to be used. - Check 
IPPool.Spec.NodeNameandIPPool.Spec.NodeAffinityproperties whether match the scheduled node of the pod or not. If not match, this IPPool would be filtered. (NodeNamehas higher priority thanNodeAffinity) - Check 
IPPool.Spec.NamespaceNameandIPPool.Spec.NamespaceAffinityproperties whether match the namespace of the pod or not. If not match, this IPPool would be filtered. (NamespaceNamehas higher priority thanNamespaceAffinity) - The 
IPPool.Spec.PodAffinityfield of the IPPool must meet the pod - Check 
IPPool.Spec.MultusNameproperties whether match the pod current NIC Multus configuration or not. If not match, this IPPool would be filtered. - The available IP resource of the IPPool is not exhausted
 
 - 
Sort IPPool candidates.
 
We'll sort these IPPool candidates with our custom priority rules, then the IPAM prefers allocating IP addresses from the candidates in sequence.
- The IPPool resource with 
IPPool.Spec.PodAffinityproperty has the highest priority. - The IPPool resource with 
IPPool.Spec.NodeNameorIPPool.Spec.NodeAffinityproperty has the second-highest priority. - The IPPool resource with 
IPPool.Spec.NamespaceNameorIPPool.Spec.NamespaceAffinityproperty has the second-highest priority. - The IPPool resource with 
IPPool.Spec.MultusNameproperty has the lowest priority. 
Notice: here are some simple instance to describe this rule.
- IPPoolA with properties
 IPPool.Spec.PodAffinityandIPPool.Spec.NodeNamehas higher priority than IPPoolB with single affinity propertyIPPool.Spec.PodAffinity.- IPPoolA with single property
 IPPool.Spec.PodAffinityhas higher priority than IPPoolB with propertiesIPPool.Spec.NodeNameandIPPool.Spec.NamespaceName.- IPPoolA with properties
 IPPool.Spec.PodAffinityandIPPool.Spec.NodeNamehas higher priority than IPPoolB with propertiesIPPool.Spec.PodAffinity,IPPool.Spec.NamespaceNameandIPPool.Spec.MultusName.
- 
Assign IP from valid IPPool candidates.
When trying to assign IP from the IPPool candidates, it follows rules as below.
- The IP is not reserved by the "exclude_ips" field of the IPPool and all ReservedIP instances
 
 
Notice: If the pod belongs to StatefulSet, it would be assigned IP addresses with the upper rules firstly. And it will try to reuse the last allocated IP addresses once the pod 'restarts'.