A few days ago I tried running minikube on Windows and it didn’t work at all. After about 45 minutes of troubleshooting I gave up and decided to put together a bit more manual process using Vagrant and kubeadm. This post will walk you through standing up a small functional Kubernetes cluster in just a few minutes. This Vagrant config starts two VMs with each with 2vCPUs and 3 GB of RAM. They also have 3 networks attached, a public network (host machine’s connected network), static private network (used for Kubernetes internal communications), and a bridge network which is the default network added by Virtual Box.
Before You Begin
- Install Virtual Box https://www.virtualbox.org/wiki/Downloads
- Install Vagrant https://www.vagrantup.com/downloads.html
- Clone this git repo which contains the files necessary to stand up the cluster.
- From the root of the git repo cloned above. Run
vagrant up. Note: Sometimes Vagrant will fail when trying to inject ssl keys. If this happens run
vagrant reload && vagrant upMost of the time this will fix the issue.
- Once the machines boot and the vagrant command returns you should now have two VMs running. SSH into the master by typing
vagrant ssh master
- Once you get logged into the VM run
sudo kubeadm init --apiserver-advertise-address 10.0.3.15if all goes well this will give you a functional kubernetes master listening on 10.0.3.15 which is the internal network between the master and node. After this returns you’ll see a command that looks something like this
kubeadm join --token <tokenstring> 10.0.3.15:6443copy it for use later on the node.
- You now need to setup the kubectl configs with this command
mkdir -p .kube && sudo cp -i /etc/kubernetes/admin.conf ~/.kube/config && sudo chown $(id -u):$(id -g) ~/.kube/config
exitto leave the master ssh session for now.
vagrant ssh node
- Switch to root
- Paste the kubeadm join command you copied earlier and execute it. It should display Node join complete with some info about certificates and security. Now type
- Now that you have a node we need to enable networking to get things started. Log into the master again with
vagrant ssh master
- Run the following to setup the flannel network required utilize the cluster
kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.ymlNote: You can also run several other pod networks by changing this step. I have not tested any of the others, but you can look at this page for more info on setting them up.
- Now run
kubectl get nodes. You should see both the master and node listed. They may show NotReady at first, but should eventually report as Ready once the networking components have come online.
That’s it! If all completed successfully your should now have a functional Kubernetes cluster. The default resource allocation is 2 vCPUs and 3GB of RAM. Feel free to adjust these in the vagrant file before creating. It’s also worth noting that this should also work on Mac or Windows.
Updated 7/21/18: Corrected a github URL that had changed.