Namaste Kubernetes ๐Ÿ™๐Ÿป (Part 1)

ยท

4 min read

In this series of Namaste Kubernetes(k8s) we are going to learn bredth & width of k8s.

Pre-requisite:

Linux , Docker

Before even learning Kubernetres or any topic in this entire world we must be clear with these 3 questions

  1. What ?

  2. Why ?

  3. How ?

Q. What is Kubernetes ?

Ans. Kubernetes or K8s is an orchestration tool to manage containers , In simple words it manages containers if they are died or if any abnormality happens to them. like heal , auto-repair or auto-scale.

Q. Why we have to learn Kubernetes ?

Ans. To manage our applications , customers more effectively so that they dont face any downtime.

Q. How ?

Ans: For this we have to see its architecture.

Letโ€™s learn k8s Architecture

In k8s cluster we bascially have 2 parts

  1. Master (control plane)

  2. Worker

Think it like an MNC where lots of people are working

Master

Its consist of 5 components

  1. etcd : Database to store information.

  2. scheduler : It like an HR which do the job given by team lead (here lead is api-server).

  3. controller manager: Its like a manager who will see if everyone is working properly in an organization.

  4. api-server: Its like a team lead who assign the task to scheduler (HR)

Worker

Its consist of 2 components

  1. Kubelet

  2. Server-Proxy

Kubelet

It continously sees if the pods are working properly or not , if not it will report it to api-server.

Server-Proxy

It helps user to interact with cluster

How can we forget CEO ? ๐Ÿ˜›

Kubectl

This person is the CEO of company and instruct api-server directly.

Letโ€™s install k8s via kind

What is kind ?

kind is a tool for running local Kubernetes clusters using Docker container โ€œnodesโ€.
kind was primarily designed for testing Kubernetes itself, but may be used for local development or CI.

Install docker in ubuntu

sudo apt update
sudo apt-get install docker.io

Install kind

# For AMD64 / x86_64
[ $(uname -m) = x86_64 ] && curl -Lo ./kind https://kind.sigs.k8s.io/dl/v0.25.0/kind-linux-amd64
# For ARM64
[ $(uname -m) = aarch64 ] && curl -Lo ./kind https://kind.sigs.k8s.io/dl/v0.25.0/kind-linux-arm64
chmod +x ./kind
sudo mv ./kind /usr/local/bin/kind

Install kubectl

Follow documentation : link

  1. Download the latest release with the command:
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
  1. Validate the binary (optional)
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl.sha256"
  1. Validate the kubectl binary against the checksum file:
echo "$(cat kubectl.sha256)  kubectl" | sha256sum --check
# If valid, the output is:
# kubectl: OK
  1. Install kubectl
sudo install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl
  1. Test to ensure the version you installed is up-to-date:
kubectl version --client

Remember : Everything in k8s is a manifest file

config.yaml

kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
name: umang-cluster

nodes:
- role: control-plane
  image: kindest/node:v1.31.2
- role: worker
  image: kindest/node:v1.31.2
- role: worker
  image: kindest/node:v1.31.2

Lets see the above yml file

Kind : Type of File

apiVersion: Its the api version

name : cluster name

nodes : give information regarding how many nodes are running

The above manifest file will create 1 master and 2 worker nodes

Command to create cluster

$ kind create cluster --config=config.yaml
Creating cluster "umang-cluster" ...
 โœ“ Ensuring node image (kindest/node:v1.31.2) ๐Ÿ–ผ
 โœ“ Preparing nodes ๐Ÿ“ฆ ๐Ÿ“ฆ ๐Ÿ“ฆ  
 โœ“ Writing configuration ๐Ÿ“œ 
 โœ“ Starting control-plane ๐Ÿ•น๏ธ 
 โœ“ Installing CNI ๐Ÿ”Œ 
 โœ“ Installing StorageClass ๐Ÿ’พ 
 โœ“ Joining worker nodes ๐Ÿšœ 
Set kubectl context to "kind-umang-cluster"
You can now use your cluster with:

kubectl cluster-info --context kind-umang-cluster

Have a question, bug, or feature request? Let us know! https://kind.sigs.k8s.io/#community ๐Ÿ™‚
$ kind get clusters
umang-cluster

$ kubectl get nodes
NAME                          STATUS   ROLES           AGE    VERSION
umang-cluster-control-plane   Ready    control-plane   116s   v1.31.2
umang-cluster-worker          Ready    <none>          103s   v1.31.2
umang-cluster-worker2         Ready    <none>          103s   v1.31.2

$ docker ps
CONTAINER ID   IMAGE                  COMMAND                  CREATED         STATUS         PORTS                       NAMES
1a6aeb41b8ad   kindest/node:v1.31.2   "/usr/local/bin/entrโ€ฆ"   6 minutes ago   Up 5 minutes                               umang-cluster-worker2
d0d4330e4e87   kindest/node:v1.31.2   "/usr/local/bin/entrโ€ฆ"   6 minutes ago   Up 5 minutes                               umang-cluster-worker
0ca905d82421   kindest/node:v1.31.2   "/usr/local/bin/entrโ€ฆ"   6 minutes ago   Up 5 minutes   127.0.0.1:39241->6443/tcp   umang-cluster-control-plane

So by following the above things you will be able to create the cluster

Thank You ๐Ÿ™๐Ÿป โค๏ธ

ย