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/subnets
andipam.spidernet.io/subnet
will 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/ippool
could be used to specify an ippool. See Pod Annotation for details. - Namespace annotation.
ipam.spidernet.io/defaultv4ippool
andipam.spidernet.io/defaultv6ippool
could be used to specify an ippool. See namespace annotation for details. - CNI configuration file. It can be set to
default_ipv4_ippool
anddefault_ipv6_ippool
in the CNI configuration file. See configuration for details. - Cluster default IPPool. We can set SpiderIPPool CR object with
default
property, 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
disable
field of the IPPool isfalse
. This property means the IPPool is not available to be used. - Check
IPPool.Spec.NodeName
andIPPool.Spec.NodeAffinity
properties whether match the scheduled node of the pod or not. If not match, this IPPool would be filtered. (NodeName
has higher priority thanNodeAffinity
) - Check
IPPool.Spec.NamespaceName
andIPPool.Spec.NamespaceAffinity
properties whether match the namespace of the pod or not. If not match, this IPPool would be filtered. (NamespaceName
has higher priority thanNamespaceAffinity
) - The
IPPool.Spec.PodAffinity
field of the IPPool must meet the pod - Check
IPPool.Spec.MultusName
properties 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.PodAffinity
property has the highest priority. - The IPPool resource with
IPPool.Spec.NodeName
orIPPool.Spec.NodeAffinity
property has the second-highest priority. - The IPPool resource with
IPPool.Spec.NamespaceName
orIPPool.Spec.NamespaceAffinity
property has the second-highest priority. - The IPPool resource with
IPPool.Spec.MultusName
property has the lowest priority.
Notice: here are some simple instance to describe this rule.
- IPPoolA with properties
IPPool.Spec.PodAffinity
andIPPool.Spec.NodeName
has higher priority than IPPoolB with single affinity propertyIPPool.Spec.PodAffinity
. - IPPoolA with single property
IPPool.Spec.PodAffinity
has higher priority than IPPoolB with propertiesIPPool.Spec.NodeName
andIPPool.Spec.NamespaceName
. - IPPoolA with properties
IPPool.Spec.PodAffinity
andIPPool.Spec.NodeName
has higher priority than IPPoolB with propertiesIPPool.Spec.PodAffinity
,IPPool.Spec.NamespaceName
andIPPool.Spec.MultusName
.
- The IPPool resource with
-
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'.