top of page

Setting up K8s...

  • Writer: Abhishek Shukla
    Abhishek Shukla
  • Jul 10, 2020
  • 4 min read

This article is successor of K8s introduction. In this article I will walk you through the installation part of K8s clusters. Honestly I thought it would be monsterous but trust me it is pretty simple and had fun working on.


So, I checked there are multiple ways to install K8s cluster like

  1. Minikube : need not to have master and worker nodes. It's great for small virtual environments and for practice sessions not for real feel of it.

  2. Kops : K8s on AWS (Pricing involved)

  3. Kubernetes on GCP

  4. Kubeadm (free tier)

I loved Kubeadm not because it is free but it is the most popular and simplest way to install K8s. Basically, Kubeadm is the tool built into K8s used to bootstrap K8s clusters. Unlike other methods, using Kubeadm, you can install K8s cluster in any bare metal i.e. server base could be anything like cloud, on-prem or even VM.

I used Ubuntu OS as platform and installed K8s cluster on VMs. In the introduction article, I talked about the architecture for K8s. K8s clustering is based on client-server or Master-worker model in which one is K8s control plane (master node) and K8s nodes (worker node). My set up is of two nodes, one is master and another is worker.


Basic requirements :

  1. 2x Ubuntu 18.04 VMs of 2vCPUs, 1GB RAM and 16GB Hard disk (Default set up)

  2. Both machines should have"root" access

  3. Able to update the apt package manager

  4. Disable "Swap" space and its must (will explain later why)


Assuming you have VMs ready to install K8s cluster. Let's walk through step by step.

Important to note : Below steps should be installed on both master and worker node


Step1 : Install Docker

K8s will be using docker as this provides the ability to package and run an applications in a loosely isolated environment called container

So make sure you have dockers installed already on your ubuntu machine, if you don’t have it, run the update package first

Command to update

Install docker using command


# apt-get install docker.io


Confirm that the docker is installed


# docker -v



Step 2 : Enable Docker

Once, you have confirmed that the docker is installed, enable docker. This command actually start docker

# systemctl enable docker


you should verify that the docker service is running with below command


# systemctl status docker

Step 3 : Install K8s

Since you are downloading K8s from a non-standard repository, it is important to ensure that the software is authentic. This is done by adding a signing key. This is done by "Curl"command, if you dont have "curl" installed, install it using copmmand

# apt-get install curl


Adding signing key:


# curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add


output is : OK


Step 4: Add Repositories

By default, K8s is not included in the repositories, to add, run below command

Step 5: k8s installation tools

As I mentioned, Kubeadm is a tool that initializes a cluster and thats an important aspect to run on every node and start container plus it will give you access to command-line interface (CLI) to clusters. Below is the command to install and make it as hold


# apt-get install kubeadm kubelet kubectl

# apt-mark hold kubeadm kubelet kubectl


and verify "Kubeadm" with below command

# kubeadm version


till this point, that was preparation for K8s deployment. From now on, actual K8s will get deployed


Step 6: Begin K8s deployment

Decide which ever server should be master node and worker node and assign hostnames to respective nodes using below command


for Master-Node, I used masternode as hostname, hence

# hostnamectl set-hostname masternode


for worker-node , I used workernode1 as hostname, hence

# hostnamectl set-hostname workernode1


Step 7 : Set Up K8s cluster on masternode

At this moment of time, you have both K8s master and worker node ready, now you need to "Bootstrap" the cluster using kubeadm. Below command is used to bootstrap the cluster and there is one flag which needs to be provided as "Pod Network" . The pod network is procedure to allow communication between nodes in the cluster. There are different pod network available for kubernetes but I used "Flannel" virtual nertwork and for that default CIDR is 10.224.0.0/16


# kubeadm init --pod-network-cidr=10.244.0.0/16


Once this command finishes, you will get the output like this

and that's the reason I meantioned to disable "Swap" space and to disable swap space, command is


# swapoff -a


Run kubeadm init command again, it will display Kubeadm join message at the end, make a note of the whole entry, it will be used in next step to make worker node join to master node. Output is something like this

This will be used to join worker nodes to master. Now, enter the following commands to create directory for the cluster


# mkdir -p $HOME/.kube

# sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config

# sudo chown $(id -u):$(id -g) $HOME/.kube/config

Pods are created and you can verify using below command

# kubectl get pods --all-namespaces


you will get below output where the components of master node are shown


Step 8 : Join worker node to master node

In Step 7, you got output from Kubeadm join, switch to worker node and run following command which you copied from step 7


run this command on worker node

You see the worker node has been joined with master node , you can verify this by running below command on master node


# kubectl get nodes





The master and worker node is ready now for the pods.


Well, thats all for now with basic set up for K8s cluster. I will come back with further articles on how Pods work.


Thanks for reading and stay tuned for further stuff.


Happy Reading !







Comments


"An investment in knowledge
always pays the best interest"
                      -             
Benjamin Franklin

Subscribe Form

  • Twitter
  • LinkedIn

©2020 by almostvirtual. Proudly created with Wix.com

bottom of page