How to Install Kubernetes Cluster on Debian 12 | 11

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.

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

  1. Introduction
  2. Prerequisites
  3. Environment Preparation
  4. Installing Docker
  5. Installing Kubernetes Components
  6. Configuring the Kubernetes Cluster
  7. Deploying a Test Application
  8. 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:

  1. 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

  2. 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

  3. Install Docker Engine:

    sudo apt update sudo apt install -y docker-ce docker-ce-cli containerd.io

  4. 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.

  1. Add Kubernetes signing key:

    curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -

  2. Add Kubernetes repository:

    sudo apt-add-repository "deb http://apt.kubernetes.io/ kubernetes-xenial main"

  3. 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

  1. Disable swap:

    sudo swapoff -a sudo sed -i '/ swap / s/^/#/' /etc/fstab

  2. 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>

  3. 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

  4. 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.

  1. Create a deployment:

    kubectl create deployment nginx --image=nginx

  2. Expose the deployment as a service:

    kubectl expose deployment nginx --port=80 --type=NodePort

  3. 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!