Kube-OVN为KubeVirt虚拟机分配固定IP
KubeVirt虚拟机使用固定IP是生产中比较普遍的一个需求,今天我们一起看一下如何通过Kube-OVN为虚拟机提供固定IP。 配置kube-ovn-controller启动参数 Containers: kube-ovn-controller: Container ID: containerd://0f8d53403c9821c7b535c64d2c98e1ca130a15e1b2b878270cd9388c36d0e48a Image: kubeovn/kube-ovn:v1.11.0 Image ID: docker.io/kubeovn/kube-ovn@sha256:fea623e68a2a81ef78102c6cfe95b96c16c054c57f4c8b9d168bd3ff620b6779 Port: <none> Host Port: <none> Args: /kube-ovn/start-controller.sh --default-cidr=10.244.0.0/16 --default-gateway=10.244.0.1 --default-gateway-check=true --default-logical-gateway=false --default-exclude-ips= --node-switch-cidr=100.64.0.0/16 --service-cluster-ip-range=10.211.0.0/16 --network-type=geneve --default-interface-name= --default-vlan-id=100 --pod-nic-type=veth-pair --enable-lb=true --enable-np=true --enable-eip-snat=true --enable-external-vpc=true --keep-vm-ip=true 创建虚拟机 spec.template.spec.interfaces.macAddress指定虚拟机网卡MAC,每次删除重建这台虚拟机时使用同一个MAC地址,与系统的网卡配置文件/etc/netplan/50-cloud-init.yaml中MAC地址一致,不需要重新进行配置。 spec.template.metadata.annotations中添加两条记录,ovn.kubernetes.io/ip_address指定kube-ovn使用IP,ovn.kubernetes.io/mac_address告诉kube-ovn网卡的MAC地址。 --- apiVersion: kubevirt.io/v1alpha3 kind: VirtualMachine metadata: labels: kubevirt.io/vm: ubuntu-c name: ubuntu-c namespace: mail263 spec: running: true template: metadata: labels: kubevirt.io/vm: ubuntu-c annotations: ovn.kubernetes.io/ip_address: 172.16.3.203 ovn.kubernetes.io/mac_address: 00:00:00:1F:C5:8F spec: domain: cpu: cores: 4 model: host-passthrough memory: guest: 1Gi devices: disks: - name: bootdisk disk: bus: virtio - disk: bus: virtio name: cloudinitdisk interfaces: - name: default bridge: {} macAddress: 00:00:00:1f:c5:8f resources: overcommitGuestOverhead: true networks: - name: default pod: {} terminationGracePeriodSeconds: 0 volumes: - name: bootdisk dataVolume: name: ubuntuboot-c - name: cloudinitdisk cloudInitNoCloud: userData: |- #cloud-config ssh_pwauth: True chpasswd: list: | ubuntu:ubuntu expire: False 固定MAC