Multi Node Kubernetes Cluster with Vagrant, VirtualBox and Kubeadm

Raj Rajaratnam
Sep 5, 2018 · 4 min read

Step-1: Pick a base box for Kubernetes nodes = "ubuntu/xenial64"
config.vm.box_version = "20180831.0.0"

Step-2: Setup a network :private_network, ip: ""

Step-3: Setup memory and CPUs

v.customize ["modifyvm", :id, "--memory", "2048"]
v.customize ["modifyvm", :id, "--cpus", "2"]

Step-4: Install Docker

apt-get update
apt-get install -y apt-transport-https ca-certificates curl software-properties-common
curl -fsSL | apt-key add -
add-apt-repository "deb$(. /etc/os-release; echo "$ID") $(lsb_release -cs) stable"
apt-get update && apt-get install -y docker-ce=$(apt-cache madison docker-ce | grep 17.03 | head -1 | awk '{print $3}')

Step-5: Allow regular user to run docker commands

usermod -aG docker vagrant

Step-6: Install Kubeadm, Kubelet and Kubctl

    apt-get install -y apt-transport-https curl
curl -s | apt-key add -
cat <<EOF >/etc/apt/sources.list.d/kubernetes.list
deb kubernetes-xenial main
apt-get update
apt-get install -y kubelet kubeadm kubectl
apt-mark hold kubelet kubeadm kubectl

Step-7: Kubelet requires swap to be disabled

swapoff -a

Step-8: Disable swap permanently

sudo sed -i '/ swap / s/^\(.*\)$/#\1/g' /etc/fstab

Step-9: Initialize Kubernetes master

# ip of this box
IP_ADDR=`ifconfig enp0s8 | grep Mask | awk '{print $2}'| cut -f2 -d:`

# install k8s master
HOST_NAME=$(hostname -s)
kubeadm init --apiserver-advertise-address=$IP_ADDR --apiserver-cert-extra-sans=$IP_ADDR --node-name $HOST_NAME --pod-network-cidr=

Step-10: Allow regular user to run Kubectl commands

#copying credentials to regular user - vagrant
sudo --user=vagrant mkdir -p /home/vagrant/.kube
cp -i /etc/kubernetes/admin.conf /home/vagrant/.kube/config
chown $(id -u vagrant):$(id -g vagrant) /home/vagrant/.kube/config

Step-11: Install a Pod Network

# install Calico pod network addon
export KUBECONFIG=/etc/kubernetes/admin.conf
kubectl apply -f
kubectl apply -f

Step-12: Save the Kubeadm join commands

kubeadm token create --print-join-command >> /etc/
chmod +x /etc/

Step-13: Execute Kubeadm join command in Kubernetes nodes

apt-get install -y sshpass
sshpass -p "vagrant" scp -o StrictHostKeyChecking=no vagrant@ .
sh ./

Putting it all together

Raj Rajaratnam

Written by

My writings are not official docs

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade