用multus模拟k8s pod的多块网卡
用multus给k8s的pod模拟多块网卡。
Table of Contents
Multiple Network Interfaces for a k8s pod
Introduction
In some cases we may need more than one network interface for a single k8s pod. One example is that if we'd like to make an Oracle RAC database into k8s cluster, one pod per instance, then we need at least two network interfaces for its public and private IP. This page describes how we can get this done by leveraging a 3rd party CNI (Container Network Interface) plug-in called "multus".
In short, multus is a CNI plug-in that takes over the k8s network and delegates the work to other existing CNI plug-ins such as flannel, wave-net, macvlan .etc, and thus makes applying multiple network CNIs possible. It is developed by Intel.
Install multus binary on a VM
First let's clone multus-cni repository (change "io" to your UID ):
|
To install multus binary we need to install go, we can download it from google official site, e.g.
|
Now build our multus-cni plug-in:
|
Then copy the output binary to /opt/cni/bin/
|
Configure multus
First create multus cluster role and cluster role binding (change "myhost
" to your host name)
|
Delete any existing CNI config under directory /etc/cni/net.d/, e.g.
|
Then apply the multus DaemonSet:
|
After that there should be a new file generated in /etc/cni/net.d:
|
Now create the CRD (Custom Resource Definition) and the flannel/macvlan instances
|
At this point we probably have two flannel daemon processes running on our k8s node:
|
This is because our k8s installation script had already started a flannel DaemonSet as our default network CNI plugin, and our multus DaemonSet launched a second one. We can delete the original flannel DaemonSet (though I don't see any problem with both of them running):
|
Try it out
Now let's create a simple pod (still under the dir /home/io/intel/multus-cni/examples
):
|
Wait a while for the image to be pulled and the pod to be created.
As in sample-pod.yml we specifies the macvlan as its extra network interface (flannel is the default one), the pod should have two IP addresses:
|
Create a file sample-pod-flannel.yml with following content (the only difference between it and sample-pod.yml is that we commented out the networks annotation) and apply it:
# k8s.v1.cni.cncf.io/networks: macvlan-conf
|
Wait a while for the pod to create, and we will see that it has only the default flannel network address:
|
Form samplepod2 we can ping samplepod by 10.244.0.2, but not 192.168.1.200, because samplepod2 is not in the macvlan network.
If we update samplepod2 adding back the annotation "k8s.v1.cni.cncf.io/networks: macvlan-conf", it will be able to ping samplepod by both of the IP addresses.
Conclusion
With multus CNI plugin (to substitute the default flannel one) and its CRD objects, we can customize our network interfaces for each pod.
Troubleshooting .etc
- Use command "docker inspect dougbtv/centos-network" to inspect the image of samplepod container.
- If see any problem, try to restart kubelet:
[root@myhost
intel]# systemctl restart kubelet
- Use the following command to see pod schedule failures
[root@myhost
intel]# journalctl -u kubelet
References
更多推荐
所有评论(0)