Building a Kubernetes Cluster with Kubeadm

Building a Kubernetes Cluster with Kubeadm

Introduction

Hey there! We're about to explore Kubernetes, a powerful tool for managing applications. We'll be using Kubeadm, a beginner-friendly helper tool that makes setting up a Kubernetes cluster a breeze. It takes care of the tricky stuff, so you can focus on learning. Ready to dive in and get your cluster up and running? Let's go! 🚀

What is Kubeadm?

Kubeadm is a user-friendly tool designed to simplify the process of setting up a Kubernetes cluster. It automates many of the manual tasks, making it accessible for beginners. With Kubeadm, you can easily initialize a cluster, join nodes, and manage configurations.

Prerequisites:

Before using Kubeadm to set up a Kubernetes cluster, ensure you have the following prerequisites:

  1. One or more machines: Running a deb/rpm-compatible Linux OS, such as Ubuntu or CentOS.

  2. Memory: Minimum of 2GB RAM for smooth operation.

  3. CPUs: At least 2 CPUs are required.

  4. Internet: Strong internet connection for communication.

Step-by-Step Guide: Setting Up Kubernetes with Kubeadm (Ubuntu)

Creating an Ec2 Instances

  1. Sign in to AWS Console

  2. Navigate to EC2

  3. Launch an Instance

  4. Select an Instance Type: Control-plane node: 2 CPUs, 4 GiB RAM (t2.medium). Worker node: t2.micro***.***

  5. Configure Instance Details

Here's how our instances look in the end.

Need more help setting up? Check out this easy-to-follow video tutorial 👇

Initiating the Kubernetes Cluster

Commands for Both Master and Worker Node:

sudo apt update
sudo apt-get install -y apt-transport-https ca-certificates curl
sudo apt install docker.io -y
  • Enable and start in single command.
sudo systemctl enable --now docker
  • Adding GPG (GNU Privacy Guard) keys
curl -fsSL "https://packages.cloud.google.com/apt/doc/apt-key.gpg" | sudo gpg --dearmor -o /etc/apt/trusted.gpg.d/kubernetes-archive-keyring.gpg
  • Add the repository to the sourcelist.
echo 'deb https://packages.cloud.google.com/apt kubernetes-xenial main' | sudo tee /etc/apt/sources.list.d/kubernetes.list
sudo apt update 
sudo apt install kubeadm=1.20.0-00 kubectl=1.20.0-00 kubelet=1.20.0-00 -y

Commands for Master Node Only:

  • Initialize the Kubernetes master node.
sudo kubeadm init
  • Set up local kubeconfig (both for root user and normal user):
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
  • Apply Weave network:
kubectl apply -f https://github.com/weaveworks/weave/releases/download/v2.8.1/weave-daemonset-k8s.yaml
  • Generate a token for worker nodes to join:
sudo kubeadm token create --print-join-command

  • Expose port 6443 in the Security group for the Worker to connect to Master Node

image

Commands for Worker Node Only:

  • Run the following commands on the worker node.
sudo kubeadm reset pre-flight checks
  • Paste the join command you got from the master node and append --v=5 at the end. Make sure either you are working as sudo user or use sudo before the command

  • After succesful join->

Verify Cluster Connection

  • On Master Node:
kubectl get nodes

Congratulations! 🎉 You've achieved it! Your efforts have paid off, and now you have a fully functional K8s cluster up and running, all thanks to your work with Kubeadm.


Let's Connect ❤️:

| ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄|
------- Let's connect! -------
|_____________|
............... \ (•◡•) / ...................
................. \ ...... / .....................
.................. ——- .......................
.................. | ... | ......................
.................. |_ . |_ ....................

Linkedin

GitHub

Twitter

Hashnode

Thank you for exploring my blog!