我要评分
获取效率
正确性
完整性
易理解

Static IP Addresses for StatefulSets

Same as other workloads, you can specify the IP address used by a pod by setting the ovn.kubernetes.io/ip_pool field. StatefulSets are mainly used for stateful services and have higher requirements on network fixation. Therefore, Kube-OVN provides the following enhancements:

  1. IP addresses specified in the ovn.kubernetes.io/ip_pool field are allocated to pods in sequence.
  2. During the update or deletion of a StatefulSet, Logical_switch_port stored in the OVN is not deleted. The newly generated pod directly reuses the old interface information. Therefore, this pod can reuse IP addresses, MAC addresses, and other network information to achieve the state retention function similar to that of StatefulSet Volume.
  3. If ovn.kubernetes.io/ip_pool is not specified for a StatefulSet during the update or deletion of this StatefulSet, an IP address and a MAC address are randomly allocated to a pod when the pod is created for the first time. After that, the network information remains fixed throughout the lifecycle of the StatefulSet.

Example:

vim StatefulSet.yaml
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
apiVersion: apps/v1beta1
kind: StatefulSet
metadata:
  name: web
  namespace: product
spec:
  serviceName: "nginx"
  replicas: 2
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx:alpine
kubectl create -f StatefulSet.yaml

When specifying IP addresses for a StatefulSet, note that:

  • The specified IP addresses must be within the CIDR of the subnet to which the namespace where the pod resides belongs.
  • The specified IP addresses cannot conflict with used IP addresses.
  • If the number of specified IP addresses is less than the value of replicas, extra pods cannot be created. In this case, adjust the number of IP addresses specified in the ovn.kubernetes.io/ip_pool field based on the StatefulSet update policy and capacity expansion plan.