Static IP

Kube-OVN supports allocation a static IP address for a single Pod, or a static IP pool for a Workload with multiple Pods (Deployment/DaemonSet/StatefulSet). To enable this feature, add the following annotations to the Pod spec template.

For a single Pod

Use the following annotations to specify the address

  • ovn.kubernetes.io/ip_address: Specifies IP address
  • ovn.kubernetes.io/mac_address: Specifies MAC address

Example:

  1. apiVersion: v1
  2. kind: Pod
  3. metadata:
  4. name: static-ip
  5. namespace: ls1
  6. annotations:
  7. ovn.kubernetes.io/ip_address: 10.16.0.15
  8. ovn.kubernetes.io/mac_address: 00:00:00:53:6B:B6
  9. spec:
  10. containers:
  11. - name: static-ip
  12. image: nginx:alpine

Note:

  1. The address SHOULD be in the CIDR of related subnet.
  2. The address SHOULD NOT conflict with addresses already allocated.
  3. The static MAC address is optional.

For Workloads

Use the following annotation to allocate addresses for a Workload:

  • ovn.kubernetes.io/ip_pool: For Deployments/DaemonSets, we will randomly choose an available IP address for a Pod. For StatefulSets, the IP allocation will follow the order specified in the list.

Example:

  1. apiVersion: apps/v1
  2. kind: Deployment
  3. metadata:
  4. namespace: ovn-test
  5. name: starter-backend
  6. labels:
  7. app: starter-backend
  8. spec:
  9. replicas: 2
  10. selector:
  11. matchLabels:
  12. app: starter-backend
  13. template:
  14. metadata:
  15. labels:
  16. app: starter-backend
  17. annotations:
  18. ovn.kubernetes.io/ip_pool: 10.16.0.15,10.16.0.16,10.16.0.17
  19. spec:
  20. containers:
  21. - name: backend
  22. image: nginx:alpine

Note:

  1. The address SHOULD be in the CIDR of the related switch.
  2. The address SHOULD NOT conflict with addresses already allocated.
  3. If the address size is larger than replica count, the unused address might be acquired by other Pods.
  4. If the ip_pool size is smaller than the replica count, some Pods will not start.
  5. Care should be taken for scaling and updates to ensure there are addresses available for new Pods.