StatefulSet Persistent IP Allocation
You can specify an IP address range for a StatefulSet with the annotation
ncp/ip_range
. NCP will allocate persistent IP addresses from the range to
pods in the StatefulSet based on the subnets of the namespace.This feature is only supported in Policy mode. To
enable this feature, set
statefulset_ip_range
to
True
in the [K8s]
section in
ncp.ini
. The default is False
. Once set to
True
, you must not set it back to False
.An example of specifyiing the
ncp/ip_range
annotation:apiVersion: apps/v1 kind: StatefulSet metadata: name: web spec: selector: matchLabels: app: nginx # has to match .spec.template.metadata.labels serviceName: "nginx" replicas: 3 # by default is 1 template: metadata: labels: app: nginx # has to match .spec.selector.matchLabels annotations: ncp/ip_range: 192.168.0.10-192.168.0.50 spec: ...
If an error occurs when NCP checks the IP
range or allocates an address from the range, the StatefulSet will be annotated with
ncp/error.ip_range:<error>
. The possible errors are:- INVALID_IP_RANGE - The IP range is not in any of the namespaces's subnet, or it is in more than one subnets, or an existing pod is already using an IP address in the range.
- IP_RANGE_EXHAUSTED - ncp cannot allocate an IP address from the range because all addresses have been allocated.