Add on: Multus

Multus is a CNI manager which enables attaching multiple network interfaces to pods in Kubernetes (details here).

The install is transparent and the current CNI plugin is carried forward as the default in Multus. With Multus enabled, users can easily add multiple interfaces to pods using varying CNI plugins (like bridge, macvlan, ipvlan, ptp, etc.).

This is handy for small local cases where you want to attach to local networks/vlans or in much more complex setups where multiple more fully featured CNI plugins can be used simultaneously.

Enable the Multus add-on by running the command:

  1. microk8s enable multus

You can confirm it’s installed by verifying the daemonset is running:

  1. microk8s kubectl get pods -n kube-system --selector=app=multus

Which should return output similar to the following:

  1. NAME READY STATUS RESTARTS AGE
  2. kube-multus-ds-amd64-gtxq2 1/1 Running 0 2m36s

Once enabled you can create network attachment definitions for various networks you want your pods to connect to. Here is an example that creates two networks that attach to Linux bridges (br100 & br200) on the host machine:

  1. ---
  2. apiVersion: "k8s.cni.cncf.io/v1"
  3. kind: NetworkAttachmentDefinition
  4. metadata:
  5. name: home-network
  6. spec:
  7. config: '{
  8. "cniVersion": "0.3.1",
  9. "name": "home-network",
  10. "type": "bridge",
  11. "bridge": "br100",
  12. "isDefaultGateway": false,
  13. "forceAddress": false,
  14. "ipMasq": false,
  15. "hairpinMode": false,
  16. "ipam": {
  17. "type": "host-local",
  18. "subnet": "192.168.1.0/24",
  19. "rangeStart": "192.168.1.201",
  20. "rangeEnd": "192.168.1.250",
  21. "routes": [
  22. { "dst": "0.0.0.0/0" }
  23. ],
  24. "gateway": "192.168.1.1"
  25. }
  26. }'
  27. ---
  28. apiVersion: "k8s.cni.cncf.io/v1"
  29. kind: NetworkAttachmentDefinition
  30. metadata:
  31. name: work-network
  32. spec:
  33. config: '{
  34. "cniVersion": "0.3.1",
  35. "name": "work-network",
  36. "type": "bridge",
  37. "bridge": "br200",
  38. "isDefaultGateway": false,
  39. "forceAddress": false,
  40. "ipMasq": false,
  41. "hairpinMode": false,
  42. "ipam": {
  43. "type": "host-local",
  44. "subnet": "192.168.2.0/24",
  45. "rangeStart": "192.168.2.201",
  46. "rangeEnd": "192.168.2.250",
  47. "routes": [
  48. { "dst": "0.0.0.0/0" }
  49. ],
  50. "gateway": "192.168.2.1"
  51. }
  52. }'

Then you can create pods that attach to those networks using annotations. Here is an example of an alpine image that connects to the two above networks:

  1. ---
  2. apiVersion: v1
  3. kind: Pod
  4. metadata:
  5. labels:
  6. app: multus-alpine
  7. name: multus-alpine
  8. namespace: default
  9. annotations:
  10. k8s.v1.cni.cncf.io/networks: '[
  11. {
  12. "name" : "home-network",
  13. "interface": "eth1",
  14. "ips": ["192.168.1.205"]
  15. },
  16. {
  17. "name" : "work-network",
  18. "interface": "eth2",
  19. "ips": ["192.168.2.210"]
  20. }
  21. ]'
  22. spec:
  23. containers:
  24. - name: multus-alpine
  25. image: alpine:latest
  26. command: ["sh"]
  27. args: ["-c", "while [ true ]; do ifconfig; sleep 3; done"]
  28. restartPolicy: Always

This example uses an assigned IP but if you leave it out one will be assigned from the network range.

Should you need to disable the plugin you can do so by running:

  1. microk8s disable multus

More details can be found at the Multus page. In particular in the how-to-use section of the repository docs:
k8snetworkplumbing multus-cni repository

Last updated 3 months ago. Help improve this document in the forum.