This is a quick and basic setup for a single-master, duo worker node Kubernetes cluster using VirtualBox to virtualize the nodes. The setup uses vagrant to quickly pull VM images (Ubuntu/Focal64) and bootstraps the nodes, installing docker, kubelet, kubectl, kubeadm and the Calico CNI. This is tested for K8s 1.24.0 and kubectl 1.24.0.
- Windows (
amd64) Host Machine Vagrant(>=2.2.19): To quickly provision and bootstrap the nodesVirtualBox(>=6.1.30): For virtualization of the nodesKubernetes(>=1.24.0): Tested on this version- >= 2 CPUs and >= 2 GB RAM per node (configurable in
Vagrantfile) - Each node must have a unique private IP and hostname on the
VirtualBoxhost network. (configurable inVagrantfileunder the keyconfig.vm.networkandconfig.vm.provisionrespectively) - The K8s cluster uses the Calico as a node networking solution.
- Ensure that the
VirtualBoxUI is running. - Go to
./kube-masterand runvagrant up - Ensure that the
kube-masternode is properly setup by runningkubectl get nodesandkubectl get pods --all-namespaces, all pods should show1/1and the master node should beREADY. - Retrieve the following command using
sudo cat /kubeadm.login thekube-master's directory. Ensure thatsudois present when running it on the worker node VMs (steps 5,7).
sudo kubeadm join <NODE_IP>:6443 --token <TOKEN> \
--discovery-token-ca-cert-hash sha256:<HASH>- Go to
./kube-w1and runvagrant up - Run the command from step
4. - Go to
./kube-w2and runvagrant up - Run the command from step
4. - Go back to
kube-masterand runkubectl get nodes, all 3 nodes should show asREADY
The vagrant default credentials for the vm are vagrant:vagrant. This can be configured in the Vagrantfile. Refer to the Vagrant documentation.
The script will look out for ./id_rsa.pub in the root directory. If present, the SSH key will be uploaded to all of the nodes.
The
id_rsa.pubis git ignored and will need to be defined after cloning.
The kube installation script runs when the VM is provisioned and first started up and is called bootstrap-kube-xx.sh. The bash script takes in 2 positional arguments.
- The hostname to set for the node
- The kubernetes version to install (
1.24.0|x.x.x)