Set up Kubeadm on MacOS with Vagrant and VirtualBox
Based on kubeadm installation instructions, we can’t directly install it on MacOS. But with the help of Vagrant and VirtualBox, we can quickly create a local kubenetes cluster.
- Install VirtualBox and Vagrant(https://www.vagrantup.com)
- Create three virtualbox instances, one as a master node and the other two as workder nodes. You can use this Vagrantfile. Basically we will:
a. Use ubuntu/bionic64 as the OS
b. Set up a private network and use IP subnet “192.168.5.X” (master nodes will use 192.168.5.1X, worker nodes will use 192.168.5.2X)
c. Update /etc/hosts to set up the host record to all nodes
d. Add Google’s open dns to /etc/resolver.conf file
e. Once you finish the above process, you can runvagrant status
, you will get something like below1
2
3kubemaster running (virtualbox)
kubenode01 running (virtualbox)
kubenode02 running (virtualbox) - Install Docker runtime on all three instances by following https://docs.docker.com/engine/install/ubuntu/
- Follow https://kubernetes.io/docs/setup/production-environment/tools/kubeadm/install-kubeadm/ to install the kubeadm.
a. Letting iptables see bridged traffic
b. Installing kubeadm/kubelet and kubectl - Follow https://kubernetes.io/docs/setup/production-environment/tools/kubeadm/create-cluster-kubeadm/ to create a cluster.
a. Initializing a control-plane nodekubeadm init --pod-network-cid=10.244.0.0/16 --apiserver-advertise-address=192.1168.5.11
. Here10.244.0.0/16
specifies the subnet for pods on worker nodes. You can give a different one. Once it’s installed successfully, you can runkubectl get nodes
and the master nodes will be displayed asNotReady
as expected
b. Installing a Pod network add-on by following https://kubernetes.io/docs/concepts/cluster-administration/networking/#how-to-implement-the-kubernetes-networking-model. Here we choose WeaveNet which doesn’t need any additional configuration.
c. Join the worker nodes to the cluster. If you forget the tokens, you can runkubeadm token create --print-join-command
and run thekubeadm join
command in all worker nodes. - Now if you run
kubectl get nodes
, you can get a result as below.1
2
3
4NAME STATUS ROLES AGE VERSION
kubemaster Ready control-plane,master 9h v1.22.3
kubenode01 Ready <none> 9h v1.22.3
kubenode02 Ready <none> 9h v1.22.3