Kubernetes with Flannel — Understanding the Networking — Part 1 (Setup the demo).

Anil Reddy
2 min readApr 10, 2018

--

Setting up the demo.

This blog talks about the k8s networking with flannel CNI. This is a learning curve for me as well, so if there’re any errors please educate me as well. :-)

The following demo is done with the a master, 2 worker node cluster brought up using vagrant. Docker-ce is the container runtime engine used with Flannel as the CNI for this demo.

You can try it on your own with the steps below.

  1. Install virtualbox & vagrant on your laptop.
https://www.virtualbox.org/wiki/Downloads
https://www.vagrantup.com/docs/installation/

2. Add ubuntu to the vagrant box list.

vagrant box add https://app.vagrantup.com/ubuntu/boxes/bionic64

3. Do git clone https://github.com/anilcumulus/vagrant-k8s-flannel.git.

4. Do cd vagrant-k8s-flannel

5. Do vagrant up

That’s it. Now you should have the cluster setup, configured and ready for testing with a couple of deployments spun up. (If everything went well with the above steps of course).

You can login to the master and verify the cluster state.

Kubernetes cluster information.

And, the following deployments should be up and running.

deployment/pods created after running vagrant.

Lesson learned:

When running with vagrant, the VM’s will have 2 interfaces created. And, when running flannel, you would need to mention the interface name properly. Without that, you may see that the pods will come up and get the IP address, but can’t talk to each other.

vagrant@master:~$ ip -4 addr show
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
2: enp0s3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
inet 10.0.2.15/24 brd 10.0.2.255 scope global enp0s3
valid_lft forever preferred_lft forever
3: enp0s8: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
inet 172.16.1.100/24 brd 172.16.1.255 scope global enp0s8
valid_lft forever preferred_lft forever

You need to specify the interface name enp0s8 in the flannel manifest file.

vagrant@master:~$ grep -A8 containers kube-flannel.yml
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 ####Add the iface name here.

If you happen to have different interfaces to be matched, you can match it on a regex pattern. Let’s say the worker nodes could’ve enp0s8 or enp0s9 configured, then the flannel args would be — --iface-regex=[enp0s8|enp0s9]

In the next post, we’ll see how networking happens.

--

--