Recipe to Install n-nodes Kubernetes cluster on your windows local machine (production-like environment)
The scripts used here have been adapted from this blog with some necessary modifications to fix some bugs and facilitate the process of cluster creation. The installation process is done via:
- Vagrant as a virtual machines manager
- Ansible (IT automation platform)
Before you begin, you should check if virtualization is supported on your windows. See this link to do that.
Use this link to download Oracle VirtualBox if it is not already installed on your machine.
Note: To ensure compatibility with the rest of the prerequisites, make sure that the version is 6.0.x or older.
Use this link to download Vagrant if it is not already installed.
Note: You should restart the computer after downloading Vagrant.
Performe the following steps with powershell :
- Download or clone this repository
git clone https://github.com/Abdelrahman1993/Kubernetes-1master_2worker_vagrant_ansible-.git
- Navigate to Kubernetes-nkube directory
cd Kubernetes-1master_2worker_vagrant_ansible-
- Run this command
vagrant up --provider virtualbox
Note: this command will create 3-nodes cluster (1 maser and 2 workers). If you want more or less worker nodes you can just change the value of the variable WORKERS_NUMBER inside the file Vagrantfile.
-
To work with the cluster, you have two ways:
4.1. Download Kubectl from this link. Then, bring the kubeconfig to your local machine
$Env:KUBECONFIG=($Env:KUBECONFIG + ";"+$PWD.Path+"/kubernetes-setup/kubectl-config")
. Finally, set current contextkubectl config use-context nkube-cluster
. by this way, you can interact with cluster from terminal of your local machine using kubectl commands.4.2 Or you can login the master node (
vagrant ssh master
) and work with the cluster from there.
After you have done all the above steps, you should now be able to work with kubernetes cluster from your local terminal. To confirm this, the output from kubectl get nodes
should be similar to:
NAME STATUS ROLES AGE VERSION
master Ready master 45m v1.17.2
worker-1 Ready <none> 42m v1.17.2
worker-2 Ready <none> 40m v1.17.2
Notes: - After you create the cluster, you can only perform steps 2 and 3 whenever you want to run it. - To login any node you can run this command:
vagrant ssh [NODE_NAME]
.
After creating the cluster apply the Weave network kubectl apply -f "https://cloud.weave.works/k8s/net?k8s-version=$(kubectl version | base64 | tr -d '\n')"