configuring flannel to use a non default interface in kubernetes configuring flannel to use a non default interface in kubernetes kubernetes kubernetes

configuring flannel to use a non default interface in kubernetes


I've the same problem, trying to use k8s and Vagrant.I've found this note in the documentation of flannel:

Vagrant typically assigns two interfaces to all VMs. The first, for which all hosts are assigned the IP address 10.0.2.15, is for external traffic that gets NATed.

This may lead to problems with flannel. By default, flannel selects the first interface on a host. This leads to all hosts thinking they have the same public IP address. To prevent this issue, pass the --iface eth1 flag to flannel so that the second interface is chosen.

So I look for it in the flannel's pod configuration.If you download the kube-flannel.yml file, you should look at DaemonSet spec, specifically at the "kube-flannel" container. There, you should add the required "--iface=enp0s8" argument (Don't forget the "="). Part of the code I've used.

  containers:  - name: kube-flannel    image: quay.io/coreos/flannel:v0.10.0-amd64    command:    - /opt/bin/flanneld    args:    - --ip-masq    - --kube-subnet-mgr    - --iface=enp0s8

Then run kubectl apply -f kube-flannel.yml

Hope helps.


don't know directly running "kubectl apply -f kube-flannel.yml" does not work at my side, it still show using interface with name eth0.

after running kubectl delete -f kube-flannel.yml then kubectl apply -f kube-flannel.yml, it shows using the interface with eth1:

I1122 11:31:44.405982       1 main.go:488] Using interface with name eth1 and address 192.168.0.24I1122 11:31:44.406153       1 main.go:505] Defaulting external address to interface address (192.168.0.24)I1122 11:31:44.428414       1 kube.go:131] Waiting 10m0s for node controller to syncI1122 11:31:44.428552       1 kube.go:294] Starting kube subnet managerI1122 11:31:45.429349       1 kube.go:138] Node controller sync successful


Foremost, nothing on the documentation page you linked says /etc/sysconfig; that is a very old directory that isn't suitable for systemd nor the kubernetes DaemonSet you are actually using. In addition, unless you are volume mounting something as /etc/sysconfig, then even putting that content into a file on the host filesystem won't help you when you run flannel in a container.

I think the shortest path to success is to add the command-line flag into the flanneld argument list which you can easily do via kubectl --namespace=kube-system edit daemonset kube-flannel-ds, update the container: declaration, then kubectl --namespace=kube-system delete pod -l app=flannel