kubernetes cluster in easy way using k3s.

kubernetes cluster in easy way using k3s.

Kubernetes is the industry-grade tool for container orchestration. Setting up a Kubernetes cluster from scratch can be quite challenging because it requires many configurations. However, there are multiple ways to set up a Kubernetes cluster quickly and easily, and it can also be production-grade.

To make this possible, Rancher Labs developed K3s. K3s is a lightweight Kubernetes distribution under 100 MB that allows the installation of a Kubernetes cluster using a small binary within a few minutes.

💡
Rancher removes over a million lines of code from the full Kubernetes.

Requirements to Install a K3s Cluster

1) One or more Linux servers (if you want a cluster). These servers can run any Linux distribution (e.g., Ubuntu, CentOS, Alpine, etc.) and can be on cloud or on-premises.

2) At least 1 GB of RAM.

Installing k3s

login to your server using ssh or webshell and past the following command.

curl -sfL https://get.k3s.io | sh

Curl to install k3s

This command uses curl to download the script from https://get.k3s.io and executes the script by piping it to sh -. This will install K3s.

Check the installation by using

systemctl status k3s

Also verify Kubernetes configuration by running.

sudo kubectl get all -A

k3s by default install several containers and components to ensure a fully functional Kubernetes environment and they are:

Kubernetes API Server - The API server is a component of the Kubernetes control plane that exposes the Kubernetes API, this is the Kubernetes control plane and is responsible for processing and validating REST API requests.

Kube-controller-manager - This component runs controllers that are responsible for managing Kubernetes cluster state, such as the node controller, replication controller, and others.

Kube-scheduler - The scheduler watches for newly created pods that have no assigned node and selects a node for them to run on.

Kubelet - The kubelet is an agent that runs on each node in the cluster. It ensures that containers are running in a pod, monitors the status of the containers, and reports back to the Kubernetes control plane.

Containerd - This is the container runtime used by K3s to manage container lifecycle and execute containers. Containerd is an industry-standard container runtime.

💡
Docker use containerd as a container runtime.

coredns - a built-in DNS server in Kubernetes that's also known as kube-dns

Traefik – An ingress controller that acts as a reverse proxy (it handles routing and load balancing of web traffic).

Metrics-server – It is like the task manager, is shows resource information

Servicelb – A built-in load balancer, primarily used to provide IP addresses to the cluster (pods and nodes).

Local-path-provisioner - Allows the use of local storage on each node.

💡
k3s expose port 80 and 443 fror traefik and 6443 for kubernetes api.

Till now you have a k3s running on a single node.

If you want to join more nodes then, Copy the verification token from /var/lib/rancher/k3s/server/node-token

sudo cat /var/lib/rancher/k3s/server/node-token

Then go to another node and past.

curl -sfL https://get.k3s.io | K3S_URL=https://(your server ip):6443 K3S_TOKEN=(your token) sh -

To run this type.

systemctl enable --now k3s-agent

After that use kubeclt get nodes in the previous node to verify that it has join the cluster.

Here the first node become the master and the second node become the worker node.

Read more