How to Install Kubernetes Cluster on Debian 12 | 11
Kubernetes, an open-source container orchestration platform, simplifies the deployment, management, and scaling of containerized applications. Setting up a Kubernetes cluster on Debian 12 or 11 involves several steps, including preparing the environment, installing necessary tools, and configuring the cluster. This guide will walk you through the process, ensuring a smooth and efficient installation.
Table of Contents
- Introduction
- Prerequisites
- Environment Preparation
- Installing Docker
- Installing Kubernetes Components
- Configuring the Kubernetes Cluster
- Deploying a Test Application
- Conclusion
1. Introduction
Kubernetes automates the deployment, scaling, and management of containerized applications. It is essential for modern DevOps practices, enabling seamless application development and operational efficiency. This guide is tailored for users with basic Linux command-line knowledge and aims to provide a comprehensive, step-by-step approach to installing a Kubernetes cluster on Debian 12 or 11.
2. Prerequisites
Before starting the installation process, ensure you have:
- A minimum of two Debian 12 or 11 machines (one master and one worker node).
- Root or sudo access on all machines.
- At least 2 GB of RAM and 2 CPUs per machine.
- A stable internet connection for downloading packages.
3. Environment Preparation
First, update your system and install essential tools:
sudo apt update && sudo apt upgrade -y
sudo apt install -y apt-transport-https ca-certificates curl gnupg lsb-release
4. Installing Docker
Kubernetes uses Docker as the container runtime. Install Docker on all nodes:
Add Docker's official GPG key:
curl -fsSL https://download.docker.com/linux/debian/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
Set up the Docker repository:
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/debian $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
Install Docker Engine:
sudo apt update sudo apt install -y docker-ce docker-ce-cli containerd.io
Enable and start Docker:
sudo systemctl enable docker sudo systemctl start docker
Verify Docker installation:
sudo docker run hello-world
5. Installing Kubernetes Components
Kubernetes requires three main components: kubeadm, kubelet, and kubectl.
Add Kubernetes signing key:
curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -
Add Kubernetes repository:
sudo apt-add-repository "deb http://apt.kubernetes.io/ kubernetes-xenial main"
Install Kubernetes components:
sudo apt update sudo apt install -y kubelet kubeadm kubectl sudo apt-mark hold kubelet kubeadm kubectl
6. Configuring the Kubernetes Cluster
Initialize the Master Node
Disable swap:
sudo swapoff -a sudo sed -i '/ swap / s/^/#/' /etc/fstab
Initialize the Kubernetes control plane:
sudo kubeadm init --pod-network-cidr=10.244.0.0/16
After the initialization, you will see a command that looks like this:
kubeadm join <master-node-ip>:6443 --token <token> --discovery-token-ca-cert-hash sha256:<hash>
Set up the local kubeconfig file:
mkdir -p $HOME/.kube sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config sudo chown $(id -u):$(id -g) $HOME/.kube/config
Deploy a pod network (using Flannel in this example):
kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
Join Worker Nodes
On each worker node, run the kubeadm join
command provided during the master node initialization:
sudo kubeadm join <master-node-ip>:6443 --token <token> --discovery-token-ca-cert-hash sha256:<hash>
Verify nodes have joined the cluster:
kubectl get nodes
7. Deploying a Test Application
To ensure everything is working correctly, deploy a simple application.
Create a deployment:
kubectl create deployment nginx --image=nginx
Expose the deployment as a service:
kubectl expose deployment nginx --port=80 --type=NodePort
Get the service details to access the application:
kubectl get svc
Access the application by navigating to http://<node-ip>:<node-port>
in your web browser.
8. Conclusion
Installing a Kubernetes cluster on Debian 12 or 11 involves several crucial steps, from preparing the environment and installing Docker to configuring the Kubernetes components and deploying applications. Following this guide ensures a seamless setup, allowing you to harness the full power of Kubernetes for managing your containerized applications. Enjoy the robustness and scalability of your new Kubernetes cluster!