Kubernetes Architecture and Components:
Below is the Architecture that shows the components involved in Kubernetes:
The below architecture reference is taken from @devopscube
Introduction to Kubernetes :
Kubernetes is an open-source Tool that is used to deploy, scale and manage containerized applications.
Currently owned by CNCF (cloud native computing foundation)
We can attach many 3rd party add-ons, and integrate them.
WHY K8s is Popular? Because K8s is Cloud friendly tool.
Major distributions of K8s: Google Anthos, Redhat Open-shift, Rancher.
Cloud versions of K8s - EKS, AKS, GKE.
K8s releases a new version every 3 months.
K8s Interfaces and Roles of APIs :
K8s has a client-server architecture. API is the standardized way to communicate between the client and the server. API is the Interface.
If I have to go and talk to products on a cloud the access is provided by API.
Command line Interface CLI is used to communicate to the server . "kubectl" is the utility used to communicate.
CURL is also used to communicate with API.
K8s "Dashboard" is used 1% for communication Where as Open-shift uses more of a dashboard.
kubectl --help
Above commands shows all the options for kubectl utility.
Kubernetes cluster has 2 main components
1) Control Plane/Master Node
The Master Node has 5 components:
Kube API server, ETCD, Kube Scheduler, Kube Controller Manager, CCM (Cloud control manager)
Let's discuss the significance of each of the above components:
Kube API Server:
Its works as a front end of the cluster. If we want to do any REST operations it communicates to API server and stores in ETCD & also gets information from ETCD.
Kube-scheduler:
If I want to schedule a POD, on which node do I need to schedule? Is decided by the Kube scheduler.
Etcd:
The current cluster state is stored in ETCD and stores data as a Key: Value pair.
Kube-controller Manager:
The current state of the cluster is managed and defined by the Kube-controller manager.
2) Worker Node
Kubelet:
Which passes all the requests to the container engineand comes back to API server and stores information in etcd.
Every node has a container engine = container run time like "containerd", "kri-o" and "dockerd".
Kube proxy:
kube Proxy runs on every node. It manages IP tables. It works as a network interface that connects to the components in a cluster.
Cloud controller manager:
The cloud-controller-manager is responsible for managing the cloud provider-specific resources in the Kubernetes cluster. It provides a way to integrate with the cloud provider's APIs to manage the cloud resources.
API Resources:
If we want to connect to k8s we connect via API resources.
K8s has API resources like Deployment, Replica-sets, and Pods...
# shows all the resources
kubectl api-resources
SERVICE is used to connect to the deployment.
API and CLI:
K8s is a collection of APIs. RBAC (Role-based access control) is used to control the access.
KubeConfig has the user information.
Kubectl auth can-i create pods # used to check the access information.
Kubectl auth can-i create pods --as user1 --namespace apps
Kubernetes Objects:
POD - every pod has an IP.
Inside POD we have one container or more but it's recommended to have 1 container. Every pod has a default volume.
If 2 containers are present in POD. The IP address of the POD is used by both containers in the POD.
RS - ReplicaSets is used to create 'n' no.of pods.
How to deploy app - Using Deployment Object
How to access the app - Using Service. It can be a load balancer, node port, Ingress, clusterIP
PVC - Persistent volume claims. Storage classes--->Persistent volume has PVC. PVC present outside of Deployment.
Secrets - Passwords are stored outside of POD.
ConfigMaps - The configuration required for deploying the application is stored in configMaps.
CURL - We never use it as a K8s admin.
CURL is used mostly by developers who want to connect to K8.
API server has TLS certificate by default
KubeProxy has TLS certificate with port 8080 exposed by default.
Ex:
kubectl proxy --port=8001 &
curl localhost:8001/api/v1/namespaces
curl localhost:8001/api/v1/namespaces/default/pods
To Delete a pod using curl:
curl -XDELETE localhost:8001/api/v1/namespaces/default/pods<podname>
K8s Installations:
Environments to install K8s:
Local machine --> VMware-->ubuntu-->container/vm(docker)---> Install minikube
OnPremise --> Kubeadm, play-withk8s.com
Cloud - EKS, KOPS , GKE, AKS
Local Environment - Dev/Test -- Minikube, Kind, DockerDesktop (k8s can be used)
The Masternode of EKS, AKS, and GKE is managed by the cloud.
In Ubuntu which is on VM : Install "kubectl" and "Minikube"
Install kubectl :
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
sudo install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl
kubectl version
This downloads the latest stable release of kubectl for Linux amd64 architecture, installs it, and verifies the installation.
Install Minikube:
curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64
sudo install minikube-linux-amd64 /usr/local/bin/minikube
minikube start --driver=docker
This downloads the latest release of minikube for Linux amd64 architecture, installs it, and starts a single-node Kubernetes cluster using the Docker driver.
SUMMARY:
Kubernetes is an open-source container orchestration platform that is widely used in modern software development. Kubernetes makes it easy to deploy, manage, and scale containerized applications across multiple clusters, and it provides a highly scalable and fault-tolerant architecture that can handle complex workloads.