Technology Based Blogs

Setting Up Kubernetes: A Step-by-Step Guide

Setting Up Kubernetes: A Step-by-Step Guide

In the previous blog we saw the basic definition of kubernetes. In this blog, we’ll explore the steps involved in setting up a Kubernetes environment, installing it, and configuring cluster networking.

Preparing the Environment

To run kubernetes we need below hardware and software prerequisites.

Hardware Prerequisites:

– A minimum of two machines. One will act as the master (control plane node), and the others will act as workers (worker nodes).

– 2 GB or more of RAM for the master and 1 GB or more for the workers.

– 2 CPUs or more on the master.

Software Prerequisites:

– A compatible Linux OS (e.g., Ubuntu 18.04 or later).

– SSH access to all machines.

– User with sudo privileges.

Steps:

1. Update the System

   On all nodes, update your system packages:  

sudo apt-get update
sudo apt-get upgrade -y
view raw gistfile1.txt hosted with ❤ by GitHub

 

2. Install Docker

   Kubernetes requires Docker to run containers:  

sudo apt-get install docker.io -y
sudo systemctl start docker
sudo systemctl enable docker
view raw gistfile1.txt hosted with ❤ by GitHub

 

3. Disable Swap

   Kubernetes does not support swap memory, so it needs to be disabled:

sudo swapoff -a
view raw gistfile1.txt hosted with ❤ by GitHub

 

 

Installing Kubernetes

1. Install Kubernetes Tools

   On all nodes, install `kubelet`, `kubeadm`, and `kubectl`:

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 -
echo "deb https://apt.kubernetes.io/ kubernetes-xenial main" | sudo tee -a /etc/apt/sources.list.d/kubernetes.list
sudo apt-get update
sudo apt-get install -y kubelet kubeadm kubectl
view raw gistfile1.txt hosted with ❤ by GitHub

 

2. Initialize the Master Node

   On the master node:

sudo kubeadm init --pod-network-cidr=10.244.0.0/16
view raw gistfile1.txt hosted with ❤ by GitHub

This command initializes the master node and provides a command to join worker nodes to the cluster. Take note of this command.

 

3. Set Up Local kubeconfig

   To use `kubectl` as a non-root user:

mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
view raw gistfile1.txt hosted with ❤ by GitHub

 

4. Join Worker Nodes

On each worker node, run the command provided after the master initialization (it’ll look something like `kubeadm join …`). This will join them to the master.

 

Configuring Cluster Networking

Kubernetes requires a Pod Network to allow pods to communicate with each other. One popular solution is Flannel.

1. Install Flannel Networking

   On the master node:

kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
view raw gistfile1.txt hosted with ❤ by GitHub

 

2. Verify Installation

   After a few moments, all nodes should be in the `READY` state when you run:

kubectl get nodes
view raw gistfile1.txt hosted with ❤ by GitHub

 

And you should see the flannel pods running when you execute:

kubectl get pods –all-namespaces

 Conclusion:

Setting up Kubernetes may seem complex, but with the right guidance, it becomes manageable. In this guide, we’ve covered the essential steps, from environment preparation to cluster networking configuration. Kubernetes empowers you to manage containerized applications at scale, and with your cluster up and running, you’re ready to start deploying and orchestrating your container workloads.