Configuring Multi-NIC Virtual Machine

Use Kube-OVN together with Multus to provide multi-NIC support for virtual machines

Prerequisites

  • Alauda Container Platform version must be v4.1.0 or higher.
  • Kube-OVN is used as the CNI.
  • Alauda Container Platform Networking for Multus is installed

Procedure

Create Secondary Network

  1. Create NetworkAttachmentDefinition

    Execute the following command on the cluster control node:

    Command
    Example
    cat << EOF | kubectl create -f -
    apiVersion: 'k8s.cni.cncf.io/v1'
    kind: NetworkAttachmentDefinition
    metadata:
      name: <name>
      namespace: <namespace>
    spec:
      config: '{
        "cniVersion": "0.3.0",
        "type": "kube-ovn",
        "server_socket": "/run/openvswitch/kube-ovn-daemon.sock",
        "provider": "<provider>"
        }'
    EOF

    Parameters:

    • name: The name of NetworkAttachmentDefinition.
    • namespace: The namespace of NetworkAttachmentDefinition, Must use the same namespace as the virtual machine.
    • provider: The <name>.<namespace>.ovn of the current NetworkAttachmentDefinition. Kube-OVN will use this information to find the corresponding Subnet resource. Note that the suffix must be set to ovn.
  2. Create a Kube-OVN Subnet

    If using Kube-OVN as a secondary network interface, the provider should be set to the corresponding NetworkAttachmentDefinition's <name>.<namespace>.ovn, and must end with the ovn suffix.

    Execute the following command on the cluster control node:

    Command
    Example
    cat << EOF | kubectl create -f -
    apiVersion: kubeovn.io/v1
    kind: Subnet
    metadata:
      name: <name>
    spec:
      protocol: IPv4
      enableDHCP: true
      provider: <provider>
      cidrBlock: <cidrBlock>
      gateway: <gateway>
      excludeIps:
      - <excludeIps>
    EOF

    Parameters:

    • name: The name of subnet.
    • provider: The provider of NetworkAttachmentDefinition.
    • cidrBlock: The subnet cidr.
    • gateway: The gateway address.
    • excludeIps: The set reserved IP will not be automatically allocated. For example, it can be used as the IP address for computing components' fixed IP.

Create a Multi-NIC Virtual Machine

  1. Create Virtual Machine via UI

  2. Switch to YAML view and add another nic to virtual machine

    Add new interface under spec.template.spec.domain.devices.interfaces

    Add new network under spec.template.spec.networks

    spec:
      template:
        spec:
          domain:
            devices:
              interfaces:
              - bridge: {}
                name: default
              # new interface
              - bridge: {}
                name: dyniface1
          networks:
          - name: default
            pod: {}
          # new network
          - multus:
              networkName: <networkName>
            name: dyniface1

    The networkName is the name of NetworkAttachmentDefinition.

Configure Network For New NIC

After the virtual machine starts, you need to enter the virtual machine and manually configure the network for the newly added nic.

Hotplug Network Interfaces

Hotplugging and unplugging network interfaces into a running Virtual Machine is supported

Hotplug is supported for interfaces using the virtio model connected through bridge binding or SR-IOV binding.

Hot-unplug is supported only for interfaces connected through bridge binding.

  1. Adding an interface to a running VM

    Use kubectl edit to modify the virtual machine's YAML configuration

     spec:
       template:
         spec:
           domain:
             devices:
               interfaces:
               - bridge: {}
                 name: default
               # new interface
               - bridge: {}
                 name: dyniface1
           networks:
           - name: default
             pod: {}
           # new network
           - multus:
               networkName: <networkName>
             name: dyniface1   
  2. Removing an interface from a running VM

    Use kubectl edit to modify the virtual machine's YAML configuration

    spec:
      template:
        spec:
          domain:
            devices:
              interfaces:
              - bridge: {}
                name: default
              # set the interface state to absent
              - bridge: {}
                name: dyniface1
                state: absent
          networks:
          - name: default
            pod: {}
          # new network
          - multus:
              networkName: <networkName>
            name: dyniface1