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
What ?
Why ?
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
Master (control plane)
Worker
Think it like an MNC where lots of people are working
Master
Its consist of 5 components
etcd : Database to store information.
scheduler : It like an HR which do the job given by team lead (here lead is api-server).
controller manager: Its like a manager who will see if everyone is working properly in an organization.
api-server: Its like a team lead who assign the task to scheduler (HR)
Worker
Its consist of 2 components
Kubelet
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
- 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"
- 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"
- Validate the kubectl binary against the checksum file:
echo "$(cat kubectl.sha256) kubectl" | sha256sum --check
# If valid, the output is:
# kubectl: OK
- Install kubectl
sudo install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl
- 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 ๐๐ป โค๏ธ