3 Using Multus
This section contains a basic test to verify you can create a Kubernetes application that uses Multus. This example verifies you can use Multus to create a second network interface on a pod, which uses a network created with a NetworkAttachmentDefinitions CRD.
To create a second network interface:
-
On a control plane node, create a YAML file named
nad-bridge.yaml
that contains a NetworkAttachmentDefinition CRD for a bridged connection. Create a YAML file with the following contents:apiVersion: "k8s.cni.cncf.io/v1" kind: NetworkAttachmentDefinition metadata: name: bridge-conf spec: config: '{ "cniVersion": "0.3.1", "type": "bridge", "bridge": "mybr0", "ipam": { "type": "host-local", "subnet": "192.168.12.0/24", "rangeStart": "192.168.12.10", "rangeEnd": "192.168.12.200" } }'
-
Use the
kubectl apply
command to create the NetworkAttachmentDefinition with the file:kubectl apply -f nad-bridge.yaml
The NetworkAttachmentDefinition is created.
-
You can verify the NetworkAttachmentDefinition is created using:
kubectl get network-attachment-definitions
The output looks similar to:
NAME AGE bridge-conf 2m
To display more information about the NetworkAttachmentDefinition, use the
kubectl describe
command, for example:kubectl describe network-attachment-definitions bridge-conf
- Create a YAML file named
multus-pod.yaml
to create a pod running Oracle Linux 9 that uses thebridge-conf
network, with the following contents:apiVersion: v1 kind: Pod metadata: name: samplepod annotations: k8s.v1.cni.cncf.io/networks: bridge-conf spec: containers: - name: samplepod command: ["/bin/sh", "-c", "trap : TERM INT; sleep infinity & wait"] image: container-registry.oracle.com/os/oraclelinux:9-slim
-
Start the pod using the
kubectl
command:kubectl apply -f multus-pod.yaml
- You can see the pod is created and running
using:
kubectl get pods
The output looks similar to:
NAME READY STATUS RESTARTS AGE samplepod 1/1 Running 0 1m
- Use the
kubectl describe
command to show the IP address assigned to the network interfaces of themultus-nginx-pod
:kubectl describe pod samplepod
The output looks similar to:
Name: samplepod Namespace: default ... Annotations: k8s.v1.cni.cncf.io/network-status: [{ "name": "cbr0", "interface": "eth0", "ips": [ "10.244.3.4" ], "mac": "86:e7:82:28:58:59", "default": true, "dns": {}, "gateway": [ "10.244.3.1" ] },{ "name": "default/bridge-conf", "interface": "net1", "ips": [ "192.168.12.10" ], "mac": "ca:bb:74:ca:9c:10", "dns": {} }] k8s.v1.cni.cncf.io/networks: bridge-conf ...
In this example, you can see the
net1
network interface is using thebridge-conf
network, and has the IP address of192.168.12.10
. - You can delete the resources creating in this example
using:
kubectl delete pod samplepod kubectl delete network-attachment-definitions bridge-conf