Architecture of Kubernetes?
The first and foremost thing you should understand about Kubernetes is, it is a distributed system. Meaning, it has multiple components spread across different servers over a network. These servers could be Virtual machines or bare metal servers. We call it a Kubernetes cluster.
Cluster Consists of Control Panel(Master) and Worker Node.
kube-apiserver
etcd
kube-scheduler
kube-controller-manager
cloud-controller-manager
kube-apiserver:
The kube-api server is the central hub of the Kubernetes cluster that exposes the Kubernetes API.
So when you use kubectl to manage the cluster, at the backend you are actually communicating with the API server through HTTP REST APIs. However, the internal cluster components like the scheduler, controller, etc talk to the API server using gRPC.
e.g.Interface between we as a user and IRCTC app as we are accesing through browser,requesting something and we are getting response from server this is what API interface is.
etcd:
In simple words we can say, when you use kubectl to get kubernetes object details, you are getting it from etcd. Also, when you deploy an object like a pod, an entry gets created in etcd.
kube-scheduler
The kube-scheduler is responsible for scheduling pods on worker nodes.
When you deploy a pod, you specify the pod requirements such as CPU, memory, affinity, taints or tolerations, priority, persistent volumes (PV), etc. The scheduler’s primary task is to identify the create request and choose the best node for a pod that satisfies the requirements.
Kube control manager:
It is a component that manages all the Kubernetes controllers. Kubernetes resources/objects like pods, namespaces, jobs, replicaset are managed by respective controllers. Also, the kube scheduler is also a controller managed by Kube controller manager.
Cloud-controller-manager:
When kubernetes is deployed in cloud environments, the cloud controller manager acts as a bridge between Cloud Platform APIs and the Kubernetes cluster.
This way the core kubernetes core components can work independently and allow the cloud providers to integrate with kubernetes using plugins. (For example, an interface between kubernetes cluster and AWS cloud API)
Cloud controller integration allows Kubernetes cluster to provision cloud resources like instances (for nodes), Load Balancers (for services), and Storage Volumes (for persistent volumes).
Kube proxy talks to the API server to get the details about the Service (ClusterIP) and respective pod IPs & ports (endpoints). It also monitors for changes in service and endpoints.
Control plane: The collection of processes that control Kubernetes nodes. This is where all task assignments originate.
The control plane is responsible for container orchestration and maintaining the desired state of the cluster. It has the following components.
Nodes: These machines perform the requested tasks assigned by the control plane.This controller updates node-related information by talking to the cloud provider API. For example, node labeling & annotation, getting hostname, CPU & memory availability, nodes health, etc
Pod: A group of one or more containers deployed to a single node. All containers in a pod share an IP address, IPC, hostname, and other resources. Pods abstract network and storage from the underlying container. This lets you move containers around the cluster more easily.
Replication controller: This controls how many identical copies of a pod should be running somewhere on the cluster.
Service: This decouples work definitions from the pods. Kubernetes service proxies automatically get service requests to the right pod—no matter where it moves in the cluster or even if it’s been replaced.
Kubelet: This service runs on nodes, reads the container manifests, and ensures the defined containers are started and running.Kubelet is an agent component that runs on every node in the cluster. it does not run as a container instead runs as a daemon, managed by systemd.
kubectl: The command line configuration tool for Kubernetes.
Kubernetes Installations and Configurations:
Steps:
Create two EC2 servers
1.Master(t2 medium as it has everything to manage like API/control Managers/etcd/scheduler)
2.Worker(t2 micro)
Master and Worker Node:(Below commands has to be issued on both Master/worker node)
containerd will get installed automatically once we install docker.
Below commands to start docker & enable docker to starts services start when the system boots.
sudo curl -fsSLo /usr/share/keyrings/kubernetes-archive-keyring.gpg https://packages.cloud.google.com/apt/doc/apt-key.gpg
echo "deb [signed-by=/usr/share/keyrings/kubernetes-archive-keyring.gpg] https://apt.kubernetes.io/ kubernetes-xenial main" | sudo tee /etc/apt/sources.list.d/kubernetes.list
sudo apt update -y
sudo apt install kubeadm=1.20.0-00 kubectl=1.20.0-00 kubelet=1.20.0-00 -y
Lets make a Master server:
Be a root user----sudo su
kubeadm init ----kubeadm to set up a cluster
Your Kubernetes control-plane has initialized successfully!
To start using your cluster, you need to run the following as a regular user:
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
Alternatively, if you are the root user, you can run:
export KUBECONFIG=/etc/kubernetes/admin.conf
cat /etc/kubernetes/admin.conf---This path we can see Cluster name,version,
Ip,Client key etc.
Create token to connect with worker
Worker Node:
sudo su
kubeadm reset pre-flight checks
kubeadm reset
Performs a best effort revert of changes made by kubeadm init
or kubeadm join
.
Performs a best effort revert of changes made to this host by 'kubeadm init' or 'kubeadm join
This token is to connect with worker.
kubeadm join 172.31.92.240:6443 --token waqwo3.x57hmkg1tiq2capy --discovery-token-ca-cert-hash sha256:d8fcd0ce60a2e756cf0a4c14fbfa23246313f5f36e40fc5668695652d6030081 --v=5
kubectl get nodes---Kubectl get nodes” is a command to retrieve information about nodes in a Kubernetes cluster. This information includes the node’s name, role, and status. The command can also get the list of nodes in a cluster and specific information about a node.
run nginx --image=nginx --restart=Never
kubectl get pod
A pod is the smallest execution unit in Kubernetes. A pod encapsulates one or more applications. Pods are ephemeral by nature, if a pod (or the node it executes on) fails, Kubernetes can automatically create a new replica of that pod to continue operations. Pods include one or more containers (such as Docker containers).
After connecting with worker node: kubectl get nodes
As we ran NGINX image on Master node.
docker ps in worker node to check status of running container.
Thank you for reading!! Hope you find this helpful.
#KubeWeekchallenge# withtrainwithshubham#90daysofdevops#devopscommunity#trainwithshubham
Always open for suggestions..!!
Thankyou Shubham Londhe !!