While kubernetes manual installation requires more effort, the knowledge gained and the customized control of your Kubernetes environment provide valuable rewards. Starting from Kubernetes version 1.22, Docker is no longer supported as a container runtime or even a tool to manage containers and images. As alternatives, containerd will be used as container runtime and crictl will be used as CLI for CRI(Container Runtime Interface). Also, podman can be used to manage containers and images.
This new era of containerized orchestration tools will give you greater control and flexibility over your cluster. In this article, you will learn how to manually install kubernetes cluster in seconds using 2 shell scripts, ready to run, one for the master node and another one for the worker node.
Table of Contents
Kubernetes Manual Installation Prerequisites
Before diving in, ensure you have:
- 2 Ubuntu machines up an running (master and worker) with minimum specs of 2 vCPUs, 4 GB memory.
- Root access or ability to use
sudo
. - Basic understanding of containers and Kubernetes concepts.
Key Players in Kubernetes Manual Installation
Kubernetes, the open-source container orchestration platform, has revolutionized how we manage and deploy applications. While Docker has been the de facto container runtime engine for Kubernetes deployments, a new wave of container runtime solutions has emerged, offering enhanced flexibility and control.
containerd – The Core of Container Execution
At the heart of Kubernetes cluster management lies containerd, a lightweight container runtime engine responsible for image storage, image parsing, container creation, and container execution. It manages the lifecycle of containers, ensuring they run smoothly and efficiently.
Crictl – The Command-Line Interface for Container Runtime Interface (CRI)
crictl serves as a command-line interface (CLI) for the Container Runtime Interface (CRI), a standard communication protocol between Kubernetes and the container runtime engine. It enables direct interaction with containerd from the command line, allowing users to manage pods, containers, and images.
Podman – A Versatile Tool for Container Management
Podman goes beyond crictl, providing a comprehensive toolkit for managing pods, containers, and images. It offers a similar command-line interface to Docker, making it familiar to Docker users, while also incorporating advanced features like rootless container execution and image isolation.
Benefits of Using containerd, crictl, and podman
The combination of containerd, crictl, and podman offers several advantages over traditional Docker-based Kubernetes deployments:
- Lightweight and Efficient: containerd is a more lightweight and efficient container runtime, reducing resource consumption and improving overall cluster performance.
- Flexibility and Customization: crictl and podman provide greater control over container management, allowing for fine-grained customization and advanced operations.
- Reduced Dependency on Docker: Shifting away from Docker dependencies simplifies cluster management and reduces the risk of potential compatibility issues.
- Rootless Container Execution: Podman enables rootless container execution, enhancing security and allowing users to manage containers without root privileges.
For more information about containerd, crictl and podman, you can check the below links:
- https://containerd.io/
- https://github.com/kubernetes-sigs/cri-tools/blob/master/docs/crictl.md
- https://docs.podman.io/en/latest/Introduction.html
All the Kubernetes Manual Installation steps are gathered in 2 structured shell scripts. One for the master node and another one for the worker node. In the next section, we will start with configuring the master node.
Configuring the Master Node – Demo
In this section, you will explore various components to be installed in the Kubernetes master node. Let’s proceed with the Kubernetes Manual Installation steps as follows:
- Switching to Root User
login to the machine that will be considered the master node and switch to root
user with the below command, the root user is needed to be able to implement different installation steps and enable services.
$ sudo -i
- Downloading and Applying the Installation Script
Download and apply the master node’s script as below:
# bash <(curl -s https://raw.githubusercontent.com/Badawekoo/devops/main/kubernetes/manual_installation/k8s-master.sh)
The shell script is designed to install and configure Kubernetes on an Ubuntu 20.04 server. It does this by installing the necessary packages, setting up the container runtime, and initializing the Kubernetes cluster.
Here is a breakdown of the script:
- Set up terminal: The script starts by setting up the terminal by installing bash-completion and binutils. These packages are used to enable tab completion and other features in the terminal.
- Disable linux swap: The script disables the swap partition on the server. This is because Kubernetes does not support using swap with its container runtimes.
- Remove packages: The script removes any existing packages that could conflict with Kubernetes. This includes docker.io, containerd, kubelet, kubeadm, kubectl, and kubernetes-cni.
- Install podman: The script installs podman, which is a lightweight container runtime that is compatible with Kubernetes. It also installs cri-tools, which is a set of tools for interacting with container runtimes.
- Install Kubernetes packages: The script installs the necessary packages for Kubernetes, including docker.io, containerd, kubelet, kubeadm, kubectl, and kubernetes-cni. It also marks these packages as hold so that they will not be automatically removed by apt-get update.
- Configure containerd: The script configures containerd by enabling the overlay and br_netfilter modules. It also sets the necessary kernel parameters for containerd.
- Configure containerd config: The script creates a config file for containerd. This file specifies the runtime that containerd should use (runc) and the runtime endpoint that kubelet should use (unix:///run/containerd/containerd.sock).
- Configure crictl: The script configures crictl to use containerd as the default runtime. This allows crictl to be used to manage containers that are running in the Kubernetes cluster.
- Configure kubelet: The script configures kubelet to use containerd as the container runtime. It also sets a few other options, such as the pod network CIDR (192.168.0.0/16).
- Initialize Kubernetes: The script initializes the Kubernetes cluster using kubeadm. This creates the necessary components of the cluster, such as the control plane and the worker nodes.
- Apply CNI: The script applies the Calico CNI plugin to the cluster. This plugin provides networking for the containers in the cluster.
- Install etcdctl: The script installs the etcdctl command-line tool for interacting with etcd, which is the distributed key-value store used by Kubernetes.
- Generate worker node join command: The script generates a command that can be used to join a new worker node to the cluster.
This script should be ended with the command to add worker nodes which will be used later.
Configuring the Worker Node – Demo
In this section, you will explore various components to be installed in kubernetes worker node. Let’s proceed with Kubernetes Manual Installation steps as follows:
- Switching to Root User
login to the machine that will be considered the worker node and switch to root
user with the below command, root user is needed to be able to implement different installation steps and enabling services.
$ sudo -i
- Downloading and Applying the Installation Script
Download and apply the worker node’s script as below:
# bash <(curl -s https://raw.githubusercontent.com/Badawekoo/devops/main/kubernetes/manual_installation/k8s-worker.sh)
Here is a breakdown of the script:
- Install Podman: Installs Podman, a lightweight container runtime compatible with Kubernetes. Also installs cri-tools, a set of tools for interacting with container runtimes.
- Install Kubernetes Packages: Installs the necessary Kubernetes packages, including Docker, containerd, kubelet, kubeadm, kubectl, and kubernetes-cni. Mark these packages as hold to prevent them from being automatically removed by apt-get update.
- Configure Containerd: Enables the overlay and br_netfilter modules, which are required for containerd to work properly. Sets necessary kernel parameters for containerd. Creates a config file for containerd in /etc/containerd/config.toml, specifying the runtime that containerd should use (runc) and the runtime endpoint that kubelet should use (unix:///run/containerd/containerd.sock).
- Configure crictl: Sets crictl to use containerd as the default runtime using /etc/crictl.yaml. This allows crictl to be used to manage containers running in the Kubernetes cluster.
- Configure kubelet: Sets kubelet to use containerd as the container runtime using /etc/default/kubelet. Specifies the pod network CIDR (192.168.0.0/16) to ensure compatibility with the worker nodes.
- Initialize Kubernetes Cluster: Initialize the Kubernetes cluster using kubeadm. This creates the necessary components of the cluster, such as the control plane and the worker nodes.
- Apply CNI: Applies the Calico CNI plugin to the cluster. This plugin provides networking for the containers in the cluster.
- Install etcdctl: Installs the etcdctl command-line tool for interacting with etcd, which is the distributed key-value store used by Kubernetes.
- Generate Worker Node Join Command: Generates a command that can be used to join a new worker node to the cluster.
Then use the kubeadm command generated on the master node to join the worker node to the cluster
Health check
Back to the master node to check the status of nodes:
#kubectl get nodes
You should be able to see both nodes are ready! Happy Kubernetes and have fun!
Tip
You may find the kube-dns pods are not working properly while resolving service names, as a workaround, just run the below command to restart coredns deployment and it will work fine.
# kubectl rollout restart deployment coredns -n kube-system
Useful Podman and Crictl Commands
#podman run —-name c1 -d busybox
#podman pull alpine
#podman images
#podman ps -a
#crictl run —-name c1 -d busybox
#crictl pods
#crictl images
Conclusion
In this article, you have demonstrated Kubernetes Manual Installation command in a very clean way with 2 simple shell scripts. As you can notice, the manual installation requires more effort and more configuration steps but gives you more controllability and understanding. You can always consult the official documentation and online resources for detailed instructions and troubleshooting tips. If you interested in Docker, check out this article.
Pingback: Secure Your Kubernetes Cluster with Powerful Network Policies in 2024 - devblogit.com
Pingback: Kubernetes Pod Process Limit: Best Practices and Solutions - devblogit.com 2024
Pingback: Understand LLMOps: A Comprehensive Guide 2024 - devblogit.com