Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Baremetal Kubernetes Cluster Setup On Windows: Prerequisites

Download as pdf or txt
Download as pdf or txt
You are on page 1of 11

github.

com/kunchalavikram1427 1

BareMetal Kubernetes cluster Setup on Windows

Prerequisites
• Hyper-V disabled on Windows Pro machines
• Admin rights
• VirtualBox installed
https://www.virtualbox.org/wiki/Downloads
• Host network adapter in VirtualBox
➢ Go to file -> Host Network Manager

➢ By default, at least one host-only adapter should be available. If not create


one using the create button
➢ Turn off DCHP server and note down gateway IPv4 address that is assigned
to the adapter. We are going to use this subnet IPs to assign static IPs to VMs.
In my case, the gateway IP is 192.168.56.1
➢ Click close once done

BABU-KUNCHALA VIKRAM 1
github.com/kunchalavikram1427 2

Preparing Master node VM


1. Download Ubuntu 18.04.3 Bionic Beaver(preferred) VirtualBox image
https://www.osboxes.org/ubuntu/#ubuntu-1804-vbox
Password for this VM will be in the info section as shown below. Password is usually
osboxes.org

2. Once downloaded, extract the image


3. Create a new VM in VirtualBox
Go to Machine -> New

Give a name to your VM and select options as in screenshot and click Next
I have chosen name as k8s-master as this node will be acting as Kubernetes master

4. Select RAM size as 2048

BABU-KUNCHALA VIKRAM 2
github.com/kunchalavikram1427 3

5. Choose the image that is downloaded and extracted from osboxes.org website and
click create

6. Once VM is created, we need to do some additional changes in the settings before


running it. Go to settings after selecting the image

7. Make changes as shown in the screenshots below and click close/ok.


(We will have 2 network adapters connected to the VM and hence the following
changes)

BABU-KUNCHALA VIKRAM 3
github.com/kunchalavikram1427 4

8. Now start the VM in normal mode(GUI mode)

9. Once GUI is available, login using password(osboxes.org in most cases)


10. Open terminal in the Ubuntu VM and become root user

BABU-KUNCHALA VIKRAM 4
github.com/kunchalavikram1427 5

11. Change hostname and hosts file


➢ nano /etc/hostname -> change hostname to k8s-master (because this VM
will be used as master, choose your own name of choice)
➢ Update hosts file with new hostname: nano /etc/hosts

12. Update and add related packages


➢ apt update -y
➢ apt install net-tools
➢ apt install openssh-server -y

13. Adding static IP to interface


This is required as VMs change their IP after every reboot(most of the time). We
cannot use these dynamic IPs to start the cluster as worker node fails to find master
every time master node changes its IP. In order to avoid starting the cluster every time
with a new IP it’s better to have a fixed IP set to an Interface and have the cluster
running forever. In this case we will use enp0s8 as the interface with fixed IP.
Also, we will choose static IPs from host-adapter subnet range created before.
➢ ifconfig enp0s8 192.168.56.2
➢ nano /etc/network/interfaces and append these lines
auto enp0s8
iface enp0s8 inet static
address 192.168.56.2
netmask 255.255.255.0
Note the IP 192.168.56.2 is used for master. Going forward we will use 192.168.56.3
for worker node 01(k8s-slave01) and 192.168.56.4 for worker node 02(k8s-slave02)
and so on…

BABU-KUNCHALA VIKRAM 5
github.com/kunchalavikram1427 6

14. Installing Docker. Run these commands individually as root user


➢ sudo apt update
➢ sudo apt install apt-transport-https ca-certificates curl software-properties-
common
➢ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
➢ sudo add-apt-repository "deb [arch=amd64]
https://download.docker.com/linux/ubuntu bionic stable"
➢ sudo apt update
➢ apt-cache policy docker-ce
➢ sudo apt install docker-ce
➢ sudo systemctl status docker
15. Check if docker is installed properly by running docker version
16. Shut down the VM by doing init 0 in the terminal or from VirtualBox itself by

Preparing Worker node 01 VM


We will clone the master node for slave nodes as this will save significant amount of disk
space on the host.
1. Cloning the master node
Make sure master node is powered off. Right click on master VM and select clone

2. Rename the VM to k8s-slave01, select the appropriate options as shown in


screenshots and click Next

BABU-KUNCHALA VIKRAM 6
github.com/kunchalavikram1427 7

3. Select Linked clone and click clone

BABU-KUNCHALA VIKRAM 7
github.com/kunchalavikram1427 8

4. Select the slave VM and start it in GUI mode

5. Repeat Steps 11 & 13 used in setting up master VM. But this time use
K8s-slave01 instead of k8s-master
192.168.56.3 instead of 192.168.56.2
Basically, we must change the hostname and hosts file with name of the slave
chosen and giving static IP to VM which is different from static IP assigned to master
6. Shutdown this VM

Preparing Worker node 02 VM


Same steps as in Preparing Worker node 01 VM but use hostname as k8s-slave02 and static
IP as 192.168.56.4

What is done so far…


• We have configured 3 VMs with names k8s-master, k8s-slave01 and k8s-slave02
• We have given them static IPs 192.168.56.2, 192.168.56.3 and 192.168.56.4
• Since docker is installed on master and slaves are nothing but clones of master, docker
should be available on all VMs

Bootstrapping the cluster


1. Start all 3 VMs
2. Start terminal on all VMs and become root

BABU-KUNCHALA VIKRAM 8
github.com/kunchalavikram1427 9

3. Run below commands on all 3 VMs(prefer opening multiple putty sessions and running
these commands on all nodes at once).
These commands include turning off swap memory and installing Kubernetes
components
➢ swapoff -a
➢ nano /etc/fstab (comment out swap line)

➢ sudo apt-get update && sudo apt-get install -y apt-transport-https curl


➢ curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -
➢ cat <<EOF | sudo tee /etc/apt/sources.list.d/kubernetes.list
deb https://apt.kubernetes.io/ kubernetes-xenial main
EOF
➢ sudo apt-get update
➢ sudo apt-get install -y kubelet kubeadm kubectl
➢ sudo apt-mark hold kubelet kubeadm kubectl

4. Run these commands ONLY ON MASTER NODE(k8s-master) as root user


➢ kubeadm config images pull
➢ kubeadm init --pod-network-cidr=10.244.0.0/16 --apiserver-advertise-
address=192.168.56.2
Please note 192.168.56.2 is the static IP assigned to master while master VM is
being setup. If you have assigned any other IP, replace it in the command
Once above command is executed, a token of the form (kubeadm join
192.168.56.2:6443 --token oqp357.wexmezpiszo5zeeg \
--discovery-token-ca-cert-hash
sha256:67577a18d7abcd1815cf5086e2196dadf5ac39ab3b18fb705694fdafac84580b)
will be generated. save this token for later use
➢ mkdir -p $HOME/.kube
➢ sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
➢ sudo chown $(id -u):$(id -g) $HOME/.kube/config
The above 3 commands will also be shown in the terminal once kubeadm init …. command is run
5. Choose a CNI plugin for the cluster. For VirtualBox ‘flannel’ CNI is advised. You can also
choose other CNIs(refer References section of this document for more info)

BABU-KUNCHALA VIKRAM 9
github.com/kunchalavikram1427 10

6. Run this ONLY ON MASTER as root(basically applying cluster networking interface


plugin)
kubectl apply -f
https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
7. Paste the token, that is saved earlier from step 4 in this section, on all worker nodes(k8s-
slave 01 & k8s-slave02). This should join them to the cluster
8. Run kubectl get nodes on MASTER to see the list of nodes in the cluster and their status

References
➢ https://kubernetes.io/docs/setup/production-environment/tools/kubeadm/install-
kubeadm/
➢ https://kubernetes.io/docs/setup/production-environment/tools/kubeadm/create-
cluster-kubeadm/

BABU-KUNCHALA VIKRAM 10
If you like my work, Kindly consider supporting me.
This will help me come up with more tutorials on DevOps tools and help me in
launching my own YouTube Channel.
Direct all your support to the below mentioned payment channels.
Your support is highly appreciated.

Check my Github for other tutorials on Docker, Kubernetes, K3s, Helm, Git, Ansible,
Jenkins, Terraform, AWS etc.,

Subscribe to my Facebook page: https://www.facebook.com/vikram.devops


and join my group: https://www.facebook.com/groups/171043094400359
for all latest updates on DevOps

Need original presentation PPTs? Send an email to below address +91-9885683322


kunchalavikram1427@gmail.com
paypal.me/kunchalavikram

You might also like