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:
sudo swapon --show
If swap is enabled, disable it temporarily:
sudo swapoff -a
To make this permanent, comment out swap entries in /etc/fstab:
sudo sed -i '/ swap / s/^\(.*\)$/#\1/g' /etc/fstab
Step 2: Configure Kernel Parameters
Load required kernel modules:
cat <<EOF | sudo tee /etc/modules-load.d/k8s.conf
overlay
br_netfilter
EOF
sudo modprobe overlay
sudo modprobe br_netfilter
Configure sysctl parameters:
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:
# 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:
sudo nano /etc/hosts
Add entries like:
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
sudo apt update
sudo apt upgrade -y
Step 2: Install Required Dependencies
sudo apt install -y \
apt-transport-https \
ca-certificates \
curl \
gnupg \
lsb-release
Step 3: Add Kubernetes Repository
Set the Kubernetes version:
export KUBERNETES_VERSION=v1.35
Add the Google Cloud GPG key:
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:
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:
sudo apt update
sudo apt install -y kubelet kubeadm kubectl
sudo systemctl enable --now kubelet
Hold these packages to prevent automatic updates:
sudo apt-mark hold kubelet kubeadm kubectl
Step 5: Verify Container Runtime
Ensure your container runtime is properly configured. If using CRI-O:
sudo systemctl status crio
If using containerd:
sudo systemctl status containerd
Step 6: Initialize the Control Plane (Master Node)
On the master node, set the pod CIDR and initialize the cluster:
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:
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):
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:
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:
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:
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:
kubectl get pods -n kube-system
After a few minutes, verify the node is ready:
kubectl get nodes
Step 9: Join Worker Nodes
On each worker node, run the kubeadm join command you saved from Step 6:
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:
kubeadm token create --print-join-command
Step 10: Verify Cluster Status
On the master node, check all nodes:
kubectl get nodes
All nodes should show Ready status. Check cluster info:
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):
kubectl taint nodes --all node-role.kubernetes.io/control-plane-
Post-Installation Configuration
Enable kubectl Autocompletion
For bash:
echo 'source <(kubectl completion bash)' >> ~/.bashrc
source ~/.bashrc
For zsh:
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:
docker run -d -p 5000:5000 --restart=always --name registry registry:2
Configure Resource Limits (Optional)
Edit kubelet configuration if needed:
sudo nano /var/lib/kubelet/config.yaml
Testing Your Cluster
Deploy a test application:
kubectl create deployment nginx --image=nginx
kubectl expose deployment nginx --port=80 --type=NodePort
Check the deployment:
kubectl get pods
kubectl get services
Access the service:
kubectl get svc nginx
Troubleshooting
Issue: kubelet not starting
Check kubelet status:
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:
sudo kubeadm reset
Then try joining again with a fresh token from the master.
Issue: Pods stuck in Pending
Check if CNI is installed:
kubectl get pods -n kube-system
Verify network plugin pods are running.
Issue: Cannot pull images
Check container runtime:
sudo crictl images
# or
sudo crio images
Verify network connectivity and DNS resolution.
Security Considerations
- Firewall Rules: Configure firewall to allow:
- 6443 (Kubernetes API server)
- 10250 (kubelet API)
- 10259 (kube-scheduler)
- 10257 (kube-controller-manager)
- 2379-2380 (etcd, if using external etcd)
-
30000-32767 (NodePort services)
-
RBAC: Review and configure Role-Based Access Control
- Network Policies: Implement network policies for pod-to-pod communication
- Secrets Management: Use proper secrets management (e.g., sealed-secrets, external-secrets)
Maintenance
Upgrading Kubernetes
Set the Kubernetes version:
export KUBERNETES_VERSION=v1.35
- Upgrade kubeadm on all nodes:
sudo apt update
sudo apt install kubeadm=${KUBERNETES_VERSION#v}.x-00
- Upgrade control plane:
sudo kubeadm upgrade plan
sudo kubeadm upgrade apply ${KUBERNETES_VERSION}.x
- Upgrade kubelet and kubectl:
sudo apt install kubelet=${KUBERNETES_VERSION#v}.x-00 kubectl=${KUBERNETES_VERSION#v}.x-00
sudo systemctl daemon-reload
sudo systemctl restart kubelet
- 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