Launching Kubernetes

Szymon Seget
Tegess
Published in
2 min readApr 22, 2018

Hi! I’ve spent the last few days trying to launch a working K8s cluster as a part of my master thesis project. It’s not my first try with Kubernetes, but this time I get a very nice machine, so I decided to build something bigger than the Minikube instance. The base host has 32 cores and 196GB RAM.

In the first step I assumed that my cluster will contain 10 VMs (2 cores and 16GB RAM each) divided to two groups — master (with one node) and workers (9 nodes). I selected VirtualBox (5.1.32r120294) and Vagrant to create VMs quickly and without any troubles.

Vagrantfile

There are some interesting and important parts here:

  1. I selected bento/debian-9.0 as base image, because there are many issues with Ubuntu version (I tried 16.04, but vagrant just hangs on connection via ssh step).
  2. Important part is naming VMs in correct way. Every node should have unique name, because later they use it as their identifier in K8s cluster.
  3. The last unobvious thing is the line with cableconnected1. There are some issues connected with it and freezing ssh connections, so I decided to add it too. It ensures that our VM is cable connected, which doesn’t matter in my case.

After running above configuration (vagrant up) Vagrant should create and launch 10 VMs. You can check it typing:

In the next step I’ve created an Ansible playbook, which is installing required software and launches K8s cluster. This is probably not the pretties playbook you’ve ever seen, but it works well and I don’t need to configure all ten machines separately via ssh.

First lets create hosts file which contains groups definition and ssh credentials.

Then we need to create vars.yml with required packages and some useful tools.

And in the end, playbook.yml file.

This playbook will download and install required packages, initialise K8s master and copy join token to all workers. Then install network plugin (Flannel) with proper configuration. As you can see in kube-flannel.yml, there is very important line — — iface=enp0s8 which tells Flannel to use enp0s8 interface. With default configuration Flannel uses default interface and when installed on machines created by Vagrant it will select enp0s3 (more info here: StackOverflow). Script also fix the same issue for kubelet by adding special environment variable.

Then you can connect to master via ssh and check if everything works

The last step for today means run Kubernetes Dashboard with Heapster.

Lets connect to master node and type

Then you can type

and use

to tunnel to our Dashboard. Then you can go to

http://localhost:8001/api/v1/namespaces/kube-system/services/https:kubernetes-dashboard:/proxy/#!/overview?namespace=_all

and admire your K8s cluster!

K8s Dashboard :)

All sources are available on my github: https://github.com/Passarinho4/k8s_cluster_init

Have a nice day!

--

--