Static IP Addresses for Workloads
Kube-OVN allows you to specify static IP addresses for workloads (Deployment, StatefulSet, DaemonSet, Job, and CronJob) by setting the ovn.kubernetes.io/ip_pool field in the annotations section in the YAML configuration file. A pod under a workload automatically selects the IP addresses specified by the ovn.kubernetes.io/ip_pool field. In addition, Kube-OVN can ensure that the IP addresses do not conflict with other IP addresses.
Example:
vim Deployment.yaml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | apiVersion: apps/v1 kind: Deployment metadata: namespace: product name: starter-backend labels: app: starter-backend spec: replicas: 2 selector: matchLabels: app: starter-backend template: metadata: labels: app: starter-backend annotations: ovn.kubernetes.io/ip_pool: 10.16.0.15,10.16.0.16,10.16.0.17 spec: containers: - name: backend image: nginx:alpine |
kubectl create -f Deployment.yaml
When specifying IP addresses for a workload, 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 workload update policy and capacity expansion plan.
Parent topic: Service Deployment