DebianDebian Based

How To Install Kubernetes on Debian 12

Install Kubernetes on Debian 12

In this tutorial, we will show you how to install Kubernetes on Debian 12. For those of you who didn’t know, Kubernetes, an open-source container orchestration platform, has revolutionized the management and scalability of containerized applications. Installing Kubernetes on Debian 12 “Bookworm” allows you to harness the power and flexibility of this cutting-edge technology.

This article assumes you have at least basic knowledge of Linux, know how to use the shell, and most importantly, you host your site on your own VPS. The installation is quite simple and assumes you are running in the root account, if not you may need to add ‘sudo‘ to the commands to get root privileges. I will show you step-by-step install Kubernetes on a Debian 12 (Bookworm).

Prerequisites

  • A server running one of the following operating systems: Debian 12 (Bookworm).
  • It’s recommended that you use a fresh OS install to prevent any potential issues.
  • SSH access to the server (or just open Terminal if you’re on a desktop).
  • An active internet connection. You’ll need an internet connection to download the necessary packages and dependencies for Kubernetes.
  • A non-root sudo user or access to the root user. We recommend acting as a non-root sudo user, however, as you can harm your system if you’re not careful when acting as the root.

Install Kubernetes on Debian 12 Bookworm

Step 1. Before we install any software, it’s important to make sure your system is up to date by running the following apt commands in the terminal:

sudo apt update
sudo apt install curl gpg gnupg2 software-properties-common apt-transport-https lsb-release ca-certificates

This command will refresh the repository, allowing you to install the latest versions of software packages.

Step 2. Installing Docker.

Kubernetes relies on Docker as the container runtime. Let’s install Docker by executing the following commands:

sudo apt install docker.io
sudo systemctl enable --now docker

Step 3. Installing Kubernetes on Debian 12.

Now that our environment is prepared, let’s move on to installing Kubernetes on Debian 12 “Bookworm.” we need to add the official Kubernetes repository. Execute the following commands:

curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -
echo "deb https://apt.kubernetes.io/ kubernetes-xenial main" | sudo tee /etc/apt/sources.list.d/kubernetes.list
sudo apt update

Next, install the Kubernetes packages using the following commands:

sudo apt install kubelet kubeadm kubectl
sudo apt-mark hold kubelet kubeadm kubectl

Step 4. Configuring the Cluster.

Now, let’s configure the Kubernetes cluster by setting up both the master and worker nodes.

  • A. Master Node Setup

On the desired master node, initialize the cluster by executing the following command:

sudo kubeadm init

Make note of the join command that is displayed upon successful initialization, as we will need it later to join worker nodes to the cluster.

  • B. Worker Node Setup

To add worker nodes to the cluster, execute the join command obtained from the master node initialization on each worker node:

sudo kubeadm join <master-node-ip>:<master-node-port> --token <token> --discovery-token-ca-cert-hash <hash>

Step 5. Verifying the Installation.

After completing the installation process, it’s essential to verify that Kubernetes is installed correctly.

  1. Cluster Verification

On the master node, run the following command to check the status of the cluster components:

kubectl cluster-info
  1. Node Verification

To ensure that all nodes in the cluster are functioning properly, execute:

kubectl get nodes

Step 6. Setting Up a Kubernetes Cluster

Now that we have installed Kubernetes, let’s set up a cluster by initializing the master node and joining worker nodes.

  1. Initializing the Kubernetes Master Node

On the master node, initialize the cluster using the following command:

sudo kubeadm init --apiserver-advertise-address=<master-node-ip>
  1. Joining Worker Nodes to the Cluster

On each worker node, use the join command obtained during the master node initialization to join them to the cluster:

sudo kubeadm join <master-node-ip>:<master-node-port> --token <token> --discovery-token-ca-cert-hash <hash>

To ensure that the cluster is set up correctly, run the following command on the master node:

kubectl get nodes

Step 7. Deploying a Sample Application

To validate the successful installation and functionality of Kubernetes, let’s deploy a sample application on our cluster.

  1. Choosing a Sample Application

Select a sample application that suits your needs. For example, we will deploy a basic Nginx web server.

  1. Writing a Deployment YAML File

Create a YAML file named nginx-deployment.yaml and define the deployment specifications as follows:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
spec:
  replicas: 1
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx:latest
        ports:
        - containerPort: 80
  1. Deploying the Application

Deploy the application by executing the following command:

kubectl apply -f nginx-deployment.yaml

Check the status of the deployed application using the following command:

kubectl get pods

Congratulations! You have successfully installed Kubernetes. Thanks for using this tutorial to install Kubernetes on Debian 12 Bookworm. For additional help or useful information, we recommend you check the official Kubernetes website.

VPS Manage Service Offer
If you don’t have time to do all of this stuff, or if this is not your area of expertise, we offer a service to do “VPS Manage Service Offer”, starting from $10 (Paypal payment). Please contact us to get the best deal!

r00t

r00t is an experienced Linux enthusiast and technical writer with a passion for open-source software. With years of hands-on experience in various Linux distributions, r00t has developed a deep understanding of the Linux ecosystem and its powerful tools. He holds certifications in SCE and has contributed to several open-source projects. r00t is dedicated to sharing her knowledge and expertise through well-researched and informative articles, helping others navigate the world of Linux with confidence.
Back to top button