Home / Best Practices / Networking / Configure kube-ovn network to support pods with multiple NICs (Alpha)

Configure kube-ovn network to support pods with multiple NICs (Alpha)

Add multiple network interfaces to Pods using Multus CNI. Use Kube-OVN network’s Subnet and IP CRD for advanced IP management, including subnet management, IP reservation, random allocation, and fixed allocation.

Install multus cni

  1. Clone the code:

    git clone https://github.com/k8snetworkplumbingwg/multus-cni.git
  2. Enter the directory:

    cd multus-cni/deployments
  3. Using multus resources:

    kubectl apply -f multus-daemonset.yml

Creating a Subnet

  1. Create a subnet named attachnet using the example provided in network-attachment-definition.yml.

    Caution: The provider format in the configuration should be <NAME>.<NAMESPACE>.ovn, where <NAME> and <NAMESPACE> refer to the name and namespace of the NetworkAttachmentDefinition CR, respectively.

    apiVersion: "k8s.cni.cncf.io/v1"
    kind: NetworkAttachmentDefinition
    metadata:
      name: attachnet
      namespace: default
    spec:
      config: '{
          "cniVersion": "0.3.0",
          "type": "kube-ovn",
          "server_socket": "/run/openvswitch/kube-ovn-daemon.sock",
          "provider": "attachnet.default.ovn"
        }'

    Apply resources after creation.

    kubectl apply -f network-attachment-definition.yml
  2. Use the following example to create a Kube-ovn subnet for the second network card: subnet.yml.

    Caution:

    • spec.provider must be consistent with the provider in NetworkAttachmentDefinition.

    • If an Underlay subnet is needed, set the spec.vlan of the subnet to the name of the VLAN CR that needs to be used. Other subnet parameters can be configured as needed.

    apiVersion: kubeovn.io/v1
    kind: Subnet
    metadata:
      name: subnet1
    spec:
      cidrBlock: 172.170.0.0/16
      provider: attachnet.default.ovn

    Apply resources after creation.

    kubectl apply -f subnet.yml

Create pod configure multiple nics

  1. Create a pod based on the following example.

    Caution:

    • The metadata.annotations field must include a key-value pair of k8s.v1.cni.cncf.io/networks=default/attachnet, where the value is in the format of <NAMESPACE>/<NAME>, where <NAMESPACE> and <NAME> are the namespace and name of the NetworkAttachmentDefinition CR.

    • If the pod requires three network interfaces, configure the value of k8s.v1.cni.cncf.io/networks as default/attachnet,default/attachnet2.

    apiVersion: v1
    kind: Pod
    metadata:
      name: pod1
      annotations:
        k8s.v1.cni.cncf.io/networks: default/attachnet
    spec:
      containers:
      - name: web
        image: nginx:latest
        ports:
        - containerPort: 80
  2. After the Pod is successfully created, use the command kubectl exec pod1 -- ip a to view the IP address of the Pod.

Other features