How to build a full kubernetes cluster in your home lab using an automated, easy and fancy way!
Do you know that you can easily install a kubernetes cluster in your home lab without the need to provisioning cloud resources? The only thing that you need to have is a computer capable to run 3 or more virtual machines.
Update Notice — 10/28/2021
This lab was recently updated to run Kubernetes 1.22.3 over Ubuntu 18.04.06 and the container runtime chosen was Docker 18.9.1. All links and references where updated to reflect the actual changes.
For whom is this lab meant for?
Use it if:
- you want a very, very, very easy way to bring a cluster up and running in a couple of minutes;
- you have studied a lot the steps involved in the k8s cluster configuration using the kubeadm method and just wanna "jump to the action";
- you´re curious and wish to put your hands on a cluster without being involved in the configuration steps but wants to play with kubectl;
- you´re tired to install and configure all the components necessary to bring a cluster up;
- you wish to get a coffe while the hard work is done automatically for you;
If you prefer, check-out the video!
In december 03, 2018 the kubernetes release team published the Kubernetes 1.13 Announcement Blog Post, where they informed the community about the inclusion of kubeadm as part of kubernetes official GA. This means that k8s now have a unified and simplified method to deploy clusters without the need to go manually over the steps of configuring individually each component. The scope of kubeadm is to be a toolbox for both admins and automated, higher-level system.
In this tutorial I share with you the method that I have created to easily give birth to a fully functional k8s cluster using any capable computer running Virtualbox and Vagrant.
The end result of this lab is a cluster with the following configurations:
- Kubernetes cluster configured with kubeadm tool;
- 1 virtual machine, called kv-master-0, acting as the kubernetes control plane server;
- 2 virtual machines, called kv-worker-0 and kv-worker-1, acting as the kubernetes "nodes" server;
- Calico networking fully funcional configured with the POD_CIDR 172.18.0.0/16
The gold rule is: more is better. As we will create clusters using virtual machines running on your desk computer or notebook, resources will be needed in the proportion of your use. If you wish to use this lab for study, any computer equiped with an Intel Core i5 and 8Gb of memory should be sufficient. If you have a more capable computer, great! Actually I have an old Macbook Pro Late 2012 Retina, equiped with an Intel Core i5 processor and 8Gb of memory.
The lab that we will run comprises a k8s cluster with 1 master (2Gb of memory) and 2 workers (1Gb each). This configuration fits almost all of the 6 scenarios of the CKA and the 4 scenarios of CKAD certification exams.
As my old Macbook is the only computer that I have actually, all the lab was tested on it. This laptop is running the latest version of macOS Mojave (10.14.3). The lab should work with Linux without any changes.
To run the labs you will need to have pre-installed on your computer the latest version of the following softwares:
- Vagrant by Hashicorp — is a tool for building and managing virtual machine environments in a single workflow
- Virtualbox by Oracle — is a powerful x86 and AMD64/Intel64 virtualization product for enterprise as well as home use.
If you have a Windows computer, you should get the same results but with a few tweaks. I strongly recommend the installation of the following extra-packages on Windows:
- Chocolatey — is the package manager for Windows
- GNU Wget 1.20 — is a free software package for retrieving files using HTTP, HTTPS and FTP, the most widely-used Internet protocols. To install it you need to install Chocolatey
To run this lab you will need the Vagrantfile that I have created. This file is used to automate the creation of the cluster. The file can be downloaded from my kuberverse GitHub repo or using the url address described bellow:
The kuberverse GitHub for this lab
You can find the files used on this lab on my kuberverse GitHub repo.
Please, feel free to use and modify the files to fit your own needs. If you wish to change the “size” of your cluster, just edit the Vagrantfile and play with the following CONSTANTS:
# Is not recommended, but you can change the base box.
# This means that all the VMs will use the same image.
BOX_IMAGE = "bento/ubuntu-18.04"# Change these values if you wish to play with the
# cluster size. Do this before starting your cluster
MASTER_COUNT = 1
WORKER_COUNT = 2# Change these values if you wish to play with the
# VMs memory resources.
SCALER_MEMORY = 512
MASTER_MEMORY = 2048
WORKER_MEMORY = 1024# Change these values if you wish to play with the
# networking settings of your cluster
KV_LAB_NETWORK = "10.8.8.0"# This value changes the intra-pod network
POD_CIDR = "172.18.0.0/16"
Steps To Run
- Open you preferred Terminal application and go to the place/directory, on your workstation, where you wish to create your cluster's work directory:
MacOS and Linux:
mkdir -p kuberverse/kv-cluster-s
cd kuberverse/kv-cluster-sWindows:md kuberverse\kv-cluster-s
- Import the Vagrantfile file to this directory
wget -q https://raw.githubusercontent.com/arturscheiner/kuberverse/master/labs/kv-k8s-cluster-ha/Vagrantfile -O Vagrantfile
- Edit the Vagrantfile with the editor of your choice and change the MASTER_COUNT constant to match the following example
# Change these values if you wish to play with the
# cluster size. Do this before starting your cluster
MASTER_COUNT = 1
WORKER_COUNT = 2
- Execute the vagrant command to provision and run the multi-machine environment
- You will see the system starting the Single master cluster creation
"********** Kuberverse Kubernetes Cluster Lab **********"
"This is a Single Master Cluster with:"
"---- 1 Master Node"
"---- 2 Worker(s) Node(s)"
"The Master 0 Ip is 10.8.8.10"
"The Worker 0 Ip is 10.8.8.20"
"The Worker 1 Ip is 10.8.8.21"
- Couple minutes latter (this depends on your workstation resources and internet speed), your lab environment will be automatically provisioned and you would be able to get the list of the machines using the command
- Now that you lab is up and running you would be able to access the shell of your new kubernetes cluster "master" using the command
vagrant ssh kv-master-0PS: Windows users should see the a prompt for the vagrant user password. The default password for the vagrant user, inside the box is vagrant
- After connecting over SSH, you should get the kv-master-0 linux command prompt. Inside your "1st master" virtual machine, your can run the commands to check the k8s cluster nodes
kubectl get nodes -o wide
You have bootstraped automagically a fully functional kubernetes cluster without the need to provision cloud resources, using only your desktop.
With this cluster you can start your journey to study for the kubernetes official certification CKA or CKAD.
Now you need to configure the kubectl to work outside the cluster in the same workstation where you provisioned your kubernetes home lab cluster. Let’s move on to the next post:
Follow our publications here and our youtube channel to be notified about our new contents!