Installing Kubernetes on Debian 13

Installing Kubernetes on Debian 13

Installing Kubernetes on Debian 13: A Step-by-Step Guide

Introduction

Kubernetes has become the de facto standard for container orchestration, enabling organizations to deploy, scale, and manage containerized applications efficiently. Installing Kubernetes on Debian 13 provides a solid foundation for building production-ready container orchestration clusters.

This guide will walk you through installing Kubernetes (kubeadm, kubelet, and kubectl) on Debian 13, covering both single-node and multi-node cluster setups.

Prerequisites

Before installing Kubernetes, ensure you have:

  • One or more Debian 13 systems with at least 2 CPU cores and 2GB RAM (4GB+ recommended)
  • Root or sudo access on all nodes
  • A container runtime installed (CRI-O, containerd, or Docker)
  • Network connectivity between nodes (for multi-node clusters)
  • Unique hostnames for each node
  • Swap disabled (Kubernetes requirement)

Pre-Installation Steps

Step 1: Disable Swap

Kubernetes requires swap to be disabled. Check current swap status:

bash
sudo swapon --show

If swap is enabled, disable it temporarily:

bash
sudo swapoff -a

To make this permanent, comment out swap entries in /etc/fstab:

bash
sudo sed -i '/ swap / s/^\(.*\)$/#\1/g' /etc/fstab

Step 2: Configure Kernel Parameters

Load required kernel modules:

bash
cat <<EOF | sudo tee /etc/modules-load.d/k8s.conf
overlay
br_netfilter
EOF

sudo modprobe overlay
sudo modprobe br_netfilter

Configure sysctl parameters:

bash
cat <<EOF | sudo tee /etc/sysctl.d/k8s.conf
net.bridge.bridge-nf-call-iptables  = 1
net.bridge.bridge-nf-call-ip6tables = 1
net.ipv4.ip_forward                 = 1
EOF

sudo sysctl --system

Step 3: Set Hostname (for multi-node clusters)

On each node, set a unique hostname:

bash
# On master node
sudo hostnamectl set-hostname k8s-master

# On worker nodes
sudo hostnamectl set-hostname k8s-worker-1
sudo hostnamectl set-hostname k8s-worker-2

Add entries to /etc/hosts on all nodes:

bash
sudo nano /etc/hosts

Add entries like:

code
192.168.1.10 k8s-master
192.168.1.11 k8s-worker-1
192.168.1.12 k8s-worker-2

Installation Steps

Step 1: Update System Packages

bash
sudo apt update
sudo apt upgrade -y

Step 2: Install Required Dependencies

bash
sudo apt install -y \
    apt-transport-https \
    ca-certificates \
    curl \
    gnupg \
    lsb-release

Step 3: Add Kubernetes Repository

Set the Kubernetes version:

bash
export KUBERNETES_VERSION=v1.35

Add the Google Cloud GPG key:

bash
curl -fsSL https://pkgs.k8s.io/core:/stable:/$KUBERNETES_VERSION/deb/Release.key | \
    sudo gpg --dearmor -o /etc/apt/keyrings/kubernetes-apt-keyring.gpg

Add the Kubernetes repository:

bash
echo "deb [signed-by=/etc/apt/keyrings/kubernetes-apt-keyring.gpg] https://pkgs.k8s.io/core:/stable:/$KUBERNETES_VERSION/deb/ /" | \
    sudo tee /etc/apt/sources.list.d/kubernetes.list

Step 4: Install Kubernetes Components

Update package list and install kubeadm, kubelet, and kubectl:

bash
sudo apt update
sudo apt install -y kubelet kubeadm kubectl
sudo systemctl enable --now kubelet

Hold these packages to prevent automatic updates:

bash
sudo apt-mark hold kubelet kubeadm kubectl

Step 5: Verify Container Runtime

Ensure your container runtime is properly configured. If using CRI-O:

bash
sudo systemctl status crio

If using containerd:

bash
sudo systemctl status containerd

Step 6: Initialize the Control Plane (Master Node)

On the master node, set the pod CIDR and initialize the cluster:

bash
export POD_CIDR=10.96.0.0/12
sudo kubeadm init --pod-network-cidr=$POD_CIDR

Note: The --pod-network-cidr flag is for Calico CNI. Adjust if using a different CNI plugin. Make sure to use the same POD_CIDR value when configuring your CNI plugin.

The initialization process will:
- Generate certificates
- Set up the etcd database
- Create kubeconfig files
- Start control plane components

Important: Save the kubeadm join command that's displayed at the end. You'll need it to join worker nodes.

Example output:

code
kubeadm join 192.168.1.10:6443 --token <token> \
    --discovery-token-ca-cert-hash sha256:<hash>

Step 7: Configure kubectl

Set up kubectl for your regular user (not root):

bash
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config

Verify access:

bash
kubectl get nodes

You should see the master node in NotReady state (it will be ready after installing a CNI plugin).

Step 8: Install a CNI Plugin

Kubernetes requires a Container Network Interface (CNI) plugin for pod networking. We'll use Calico (covered in detail in the next blog post), but here's a quick installation:

Note: If you used a custom POD_CIDR (not the default 192.168.0.0/16), you'll need to download and customize the Calico manifest first. See the Calico installation guide for details.

For the default configuration:

bash
kubectl apply -f https://raw.githubusercontent.com/projectcalico/calico/v3.28.0/manifests/calico.yaml

If you used a custom POD_CIDR, download and customize the manifest:

bash
curl https://raw.githubusercontent.com/projectcalico/calico/v3.28.0/manifests/calico.yaml -O
sed -i "s|value: \"192.168.0.0/16\"|value: \"$POD_CIDR\"|g" calico.yaml
kubectl apply -f calico.yaml

Wait for the pods to be ready:

bash
kubectl get pods -n kube-system

After a few minutes, verify the node is ready:

bash
kubectl get nodes

Step 9: Join Worker Nodes

On each worker node, run the kubeadm join command you saved from Step 6:

bash
sudo kubeadm join 192.168.1.10:6443 --token <token> \
    --discovery-token-ca-cert-hash sha256:<hash>

If you've lost the token, generate a new one on the master:

bash
kubeadm token create --print-join-command

Step 10: Verify Cluster Status

On the master node, check all nodes:

bash
kubectl get nodes

All nodes should show Ready status. Check cluster info:

bash
kubectl cluster-info

Allow Scheduling on Control Plane Node (Optional)

If you want to allow scheduling on the control plane node (useful for single-node or 3-node Control/Worker clusters):

bash
kubectl taint nodes --all node-role.kubernetes.io/control-plane-

Post-Installation Configuration

Enable kubectl Autocompletion

For bash:

bash
echo 'source <(kubectl completion bash)' >> ~/.bashrc
source ~/.bashrc

For zsh:

bash
echo 'source <(kubectl completion zsh)' >> ~/.zshrc
source ~/.zshrc

Install a Container Registry (Optional)

For local development, you might want to set up a local registry:

bash
docker run -d -p 5000:5000 --restart=always --name registry registry:2

Configure Resource Limits (Optional)

Edit kubelet configuration if needed:

bash
sudo nano /var/lib/kubelet/config.yaml

Testing Your Cluster

Deploy a test application:

bash
kubectl create deployment nginx --image=nginx
kubectl expose deployment nginx --port=80 --type=NodePort

Check the deployment:

bash
kubectl get pods
kubectl get services

Access the service:

bash
kubectl get svc nginx

Troubleshooting

Issue: kubelet not starting

Check kubelet status:

bash
sudo systemctl status kubelet
sudo journalctl -xeu kubelet

Common fixes:
- Verify container runtime is running
- Check for swap (must be disabled)
- Verify kernel modules are loaded

Issue: Nodes not joining

On the worker node:

bash
sudo kubeadm reset

Then try joining again with a fresh token from the master.

Issue: Pods stuck in Pending

Check if CNI is installed:

bash
kubectl get pods -n kube-system

Verify network plugin pods are running.

Issue: Cannot pull images

Check container runtime:

bash
sudo crictl images
# or
sudo crio images

Verify network connectivity and DNS resolution.

Security Considerations

  1. Firewall Rules: Configure firewall to allow:
  2. 6443 (Kubernetes API server)
  3. 10250 (kubelet API)
  4. 10259 (kube-scheduler)
  5. 10257 (kube-controller-manager)
  6. 2379-2380 (etcd, if using external etcd)
  7. 30000-32767 (NodePort services)

  8. RBAC: Review and configure Role-Based Access Control

  9. Network Policies: Implement network policies for pod-to-pod communication
  10. Secrets Management: Use proper secrets management (e.g., sealed-secrets, external-secrets)

Maintenance

Upgrading Kubernetes

Set the Kubernetes version:

bash
export KUBERNETES_VERSION=v1.35
  1. Upgrade kubeadm on all nodes:
bash
sudo apt update
sudo apt install kubeadm=${KUBERNETES_VERSION#v}.x-00
  1. Upgrade control plane:
bash
sudo kubeadm upgrade plan
sudo kubeadm upgrade apply ${KUBERNETES_VERSION}.x
  1. Upgrade kubelet and kubectl:
bash
sudo apt install kubelet=${KUBERNETES_VERSION#v}.x-00 kubectl=${KUBERNETES_VERSION#v}.x-00
sudo systemctl daemon-reload
sudo systemctl restart kubelet
  1. Upgrade worker nodes (drain, upgrade, uncordon)

Conclusion

You've successfully installed Kubernetes on Debian 13! Your cluster is now ready to run containerized applications. The combination of Debian 13's stability and Kubernetes' powerful orchestration capabilities provides a robust platform for modern applications.

Remember to:
- Install a CNI plugin (like Calico, covered in the next post)
- Configure proper security policies
- Set up monitoring and logging
- Plan for backup and disaster recovery

Additional Resources