What is Kubernetes?
Kubernetes, often abbreviated as K8s, is an open-source container orchestration platform designed to automate the deployment, scaling, and management of containerized applications. It provides a robust and scalable framework for managing containerized workloads and services.
Kubernetes Architecture
Control Plane Components:
etcd: A distributed key-value store that stores the configuration data of the cluster, representing the overall state of the system.
API Server: Acts as the front-end for the Kubernetes control plane. It exposes the Kubernetes API, which is used to manage the cluster.
Controller Manager: Watches for changes in the cluster state and makes updates to bring the actual state closer to the desired state.
Scheduler: Assigns a node to newly created pods based on resource requirements, policies, and other constraints.
Certainly! Let's provide an introduction to Kubernetes, including its architecture, components, and prerequisites, before delving into the installation commands.Node Components:
Kubelet: Ensures that containers are running in a Pod on the node. It communicates with the API server and manages the containers on the node.
Kube Proxy: Maintains network rules on nodes, allowing communication to and from containerized applications within a pod.
Container Runtime: The software responsible for running containers, such as Docker or containerd.
Prerequisites for Setting up a Kubernetes Cluster
Before setting up a Kubernetes cluster, ensure you have the following prerequisites:
Linux Nodes: The machines where Kubernetes will be installed should be running a compatible Linux distribution.
Container Runtime: Choose a container runtime such as Docker or containerd to run and manage containers.
Network Connectivity: Ensure network connectivity between cluster nodes for communication.
Kernel Modules: Load necessary kernel modules like
overlay
andbr_netfilter
for container networking.Package Manager: A package manager (e.g., apt for Ubuntu) to install required dependencies.
Now, let's proceed with the step-by-step commands to set up a Kubernetes cluster.
Commands on Master Node:
Kernel Modules and System Configuration:
cat <<EOF | sudo tee /etc/modules-load.d/k8s.conf overlay br_netfilter EOF sudo modprobe overlay sudo modprobe br_netfilter sudo sysctl --system
Docker Installation and Configuration:
curl -fsSL https://get.docker.com -o get-docker.sh sudo sh get-docker.sh sudo systemctl restart docker sudo systemctl enable docker sudo docker ps
Containerd Configuration:
sudo vi /etc/containerd/config.toml ### enable_plugins[containerd] sudo systemctl restart docker sudo systemctl restart containerd
Kubernetes Components Installation:
sudo apt-get update sudo apt-get install -y apt-transport-https ca-certificates curl curl -fsSL https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo gpg --dearmor -o /etc/apt/keyrings/kubernetes-archive-keyring.gpg echo "deb [signed-by=/etc/apt/keyrings/kubernetes-archive-keyring.gpg] https://apt.kubernetes.io/ kubernetes-xenial main" | sudo tee /etc/apt/sources.list.d/kubernetes.list sudo apt-get update sudo apt-get install -y kubelet kubeadm kubectl
Kubernetes Initialization:
sudo kubeadm init # this will print
kubectl Configuration:
mkdir -p $HOME/.kube sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config sudo chown $(id -u):$(id -g) $HOME/.kube/config
To Print Join Cammand for Worker Node
sudo kubeadm token create --print-join-command
Commands on Worker Node:
On the worker node, execute all master node commands up to the 4th step of Kubernetes Components Installation. After that, there is no need to run 'kubeadm init.' Proceed directly to the next step by running the join command provided by the following command:
sudo kubeadm token create --print-join-command.
Join the Worker Node to the Cluster:
Use the
kubeadm join
command you obtained from the master node:sudo kubeadm join <MASTER_IP>:<MASTER_PORT> --token <TOKEN> --discovery-token-ca-cert-hash <HASH> # cammand lookslike this
On the Master Node (After Worker Node Join):
After the worker node has successfully joined the cluster, you may need to apply a network overlay for pod communication. Common choices include Calico, Flannel, or Weave.
After running 'kubectl get nodes,' if the nodes in the cluster are not ready, you need to apply a network overlay. Execute the following command to add the WeaveNet overlay
kubectl apply -f https://github.com/weaveworks/weave/releases/download/v2.8.1/weave-daemonset-k8s.yaml
After applying the network overlay, check the status of the nodes again using 'kubectl get nodes.' The status should now be 'Ready.'"
Remember to follow these steps sequentially, and your Kubernetes cluster should be up and running with the master and worker nodes properly configured.
You did it! Your Kubernetes cluster is up and running. From configuring the master to adding worker nodes, you've nailed the basics Cheers to smooth orchestrations and thriving clusters. Happy container orchestrating!
Thank you for reading the Blog here.