master node: This is responsible for managing the cluster
node (minions): These execute workloads(your application)
Architecture
Overview
Master node components
Api Server:
This component is responsible for all communications external as well internal in k8s cluster
For client it looks as if API server itself is k8s.
Exposes Rest API for k8s clients (kubectl, libraries) to interact
etcd:
This is memory of k8s cluster
This is a distribute key value store
Scheduler:
Scheduler is responsible for scheduling new workloads (pods) on a suitable node
Controller Manager:
This is reponsible for maintaining the desired state
Cloud Controller Manager (Optional, used only for Managed k8s): This component is part of managed k8s (AKS, EKS, GKE …) which can help to establish connection with cloud natively
Node:
Kubelet:
This is an agent of control plane (master nodes)
This recieves instructions from control plane and executes them.
Container Runtime:
To create containers we need container runtime.
k8s allows us to use any continer runtime which is CRI (Container runtime interface) compliant
Kube-proxy
This is responsible for networking services
Managed k8s clusters – an intro
All the cloud providers offer k8s and they manage master nodes i.e. they give options to
backup
restore
upgrades
HA
Interacting with k8s
To interact with k8s we can use plain https requests as k8s uses api server to expose functionality over REST APIs
To make the interaction convient we have
kubectl
client libraries
Kubectl
Kubectl has two ways of interactions
imperative:
we construct a command
declarative:
We write a specification in YAML format describing what we want
then we give this as input to kubectl which creates the necessary workloads
cd /tmp
wget https://github.com/Mirantis/cri-dockerd/releases/download/v0.3.16/cri-dockerd_0.3.16.3-0.ubuntu-jammy_amd64.deb
sudo dpkg -i cri-dockerd_0.3.16.3-0.ubuntu-jammy_amd64.deb
Our docker engine will be running on CRI-Socket unix:///var/run/cri-dockerd.sock
Now install kubeadm, kubelet and kubectl on all three nodes
sudo apt-get update
# apt-transport-https may be a dummy package; if so, you can skip that package
sudo apt-get install -y apt-transport-https ca-certificates curl gpg
# If the directory `/etc/apt/keyrings` does not exist, it should be created before the curl command, read the note below.
# sudo mkdir -p -m 755 /etc/apt/keyrings
curl -fsSL https://pkgs.k8s.io/core:/stable:/v1.32/deb/Release.key | sudo gpg --dearmor -o /etc/apt/keyrings/kubernetes-apt-keyring.gpg
# This overwrites any existing configuration in /etc/apt/sources.list.d/kubernetes.list
echo 'deb [signed-by=/etc/apt/keyrings/kubernetes-apt-keyring.gpg] https://pkgs.k8s.io/core:/stable:/v1.32/deb/ /' | sudo tee /etc/apt/sources.list.d/kubernetes.list
sudo apt-get update
sudo apt-get install -y kubelet kubeadm kubectl
sudo apt-mark hold kubelet kubeadm kubectl
sudo systemctl enable --now kubelet
Now we need to create a k8s cluster based on the installations done above Refer Here
To run kubectl as a not root user execute the following highlighted section
To join nodes to the k8s cluster which we intialized above login into nodes as root users and execute the below command which is highlighted. note we need to add --cri-socket "unix:///var/run/cri-dockerd.sock" to the join command
After join commands when we execute kubectl get nodes on master, the status of nodes will be not ready
Reason for this is CNI is not installed, lets install flannel-cni on the master node