India English
Kenya English
United Kingdom English
South Africa English
Nigeria English
United States English
United States Español
Indonesia English
Bangladesh English
Egypt العربية
Tanzania English
Ethiopia English
Uganda English
Congo - Kinshasa English
Ghana English
Côte d’Ivoire English
Zambia English
Cameroon English
Rwanda English
Germany Deutsch
France Français
Spain Català
Spain Español
Italy Italiano
Russia Русский
Japan English
Brazil Português
Brazil Português
Mexico Español
Philippines English
Pakistan English
Türkiye Türkçe
Vietnam English
Thailand English
South Korea English
Australia English
China 中文
Somalia English
Netherlands Nederlands

How to Deploy a Kubernetes Cluster on a VPS (Step by Step)

Buy domains, business emails, hosting, VPS and more: Get Started

Cheapest Domains in South Africa

Get your .Co.Za or .Com domain now for just R 45.00

.CO.ZA for R 45.00 | .COM for R 155.00

A 2 GB VPS can host a Kubernetes control plane. However, it cannot host the wrong one.

Two early choices decide whether your cluster survives its first week. The first is the distribution, either k3s or kubeadm. The second is the VPS size. Most tutorials skip both and jump straight to commands. Then the node runs out of memory, and the reader blames Kubernetes.

This guide fixes that gap. You will pick a method with a clear rule, prepare the server, and build the cluster. Next, you will connect from your laptop and deploy an app over HTTPS. Finally, you will secure and back up the result.

The commands target Ubuntu 22.04 and 24.04 LTS. You need sudo access and a domain name. A self-hosted cluster is unmanaged, so patching, backups, and upgrades are your job. In return, you get full control and a predictable bill.

Table of Contents

What You Need Before You Deploy Kubernetes on a VPS

Can Your VPS Run Kubernetes?

Yes, as long as it is a true virtual machine with root access. KVM plans work well. However, some container-based plans, such as certain OpenVZ or LXC offerings, block the kernel features Kubernetes needs.

Run this command on the server to check:

systemd-detect-virt

A result of kvm is a good sign. A result of lxc or openvz means you should pick another plan.

Kubernetes VPS Requirements by Method

The official kubeadm docs set the floor at 2 GB of RAM per machine. They also require 2 CPUs on the control plane. k3s needs far less.

Provider guides put its control plane near 512 MB of RAM. Still, your workloads need headroom on top of that.

k3skubeadm
Control plane RAMRoughly 512 MB, plus workloads2 GB minimum
CPU1 to 2 vCPUs2 CPUs on the control plane
Install effortOne commandSeveral steps
Included extrasTraefik, CoreDNS, metrics server, local storageNone, so you add a network plugin and ingress
UpgradesRerun the installer or use an upgrade controllerkubeadm upgrade, one minor version at a time

Treat these numbers as a floor, not a plan. For a single node that also runs apps, start with 2 GB for k3s and 4 GB for kubeadm.

Every node also needs the following:

  • Operating system: Ubuntu 22.04 or 24.04 LTS. Debian 11 and 12 also work.
  • Access: SSH with a sudo user.
  • Domain: A name with an A record that points to the server IP.
  • Unique identity: Each node needs its own hostname, MAC address, and product UUID.

Cloned VPS images sometimes share those identity values, causing the install to fail. Compare them across nodes with these commands:

ip link

sudo cat /sys/class/dmi/id/product_uuid

Next, plan your ports. Open only what each node needs.

PortProtocolPurposeAllow from
22TCPSSHYour admin IP
6443TCPKubernetes API serverYour admin IP and all nodes
10250TCPKubelet APICluster nodes
2379-2380TCPetcdControl-plane nodes only
8472UDPFlannel VXLANCluster nodes
80, 443TCPIngress trafficPublic

k3s or kubeadm: Which Should You Install on a VPS?

Both tools build a conformant Kubernetes cluster. However, they suit different servers and different goals.

k3s ships as a single binary. It bundles Traefik for ingress, CoreDNS, a metrics server, and local storage. Therefore, a working cluster takes about a minute.

kubeadm installs the upstream components and leaves the choices to you. You pick the container runtime, the network plugin, and the ingress controller. As a result, you learn more, but you also type more. It also mirrors what many managed clusters run.

Use this table to decide:

Your situationPick
VPS with 1 to 2 GB of RAMk3s
VPS with 4 GB of RAM or more and a wish for upstream paritykubeadm
Preparing for a Kubernetes certification examkubeadm
Small production site with minimal upkeepk3s
Three control-plane nodes for high availabilityEither, though k3s needs less setup

If you are unsure, pick k3s. You can rebuild on kubeadm later without losing much time.

Follow either the k3s or kubeadm section, not both. Then rejoin the guide at the remote access step.

Prepare Your VPS for a Kubernetes Install

Run these steps on every node. Skip none of them, since a missed step is the most common reason an install fails.

1) Update the System and Set a Hostname

sudo apt update && sudo apt install ufw -y Next, check the current status: sudo ufw status verbose
sudo apt update && sudo apt upgrade -y

sudo hostnamectl set-hostname k8s-cp-1

Use a different hostname on each node, such as k8s-worker-1.

2) Disable Swap

Kubernetes expects swap to be off. So turn it off now and keep it off after reboots.

sudo swapoff -a

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

3) Load Kernel Modules and Set Network Rules

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

overlay

br_netfilter

EOF

sudo modprobe overlay

sudo modprobe br_netfilter

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

4) Create a Sudo User and Lock Down SSH

Working as root is risky on a server that faces the internet. Create a regular user instead.

sudo adduser deploy

sudo usermod -aG sudo deploy

From your laptop, copy your SSH key to the new user:

ssh-copy-id deploy@YOUR_SERVER_IP

Then edit /etc/ssh/sshd_config and set these two lines:

PasswordAuthentication no

PermitRootLogin no

Restart SSH with sudo systemctl restart ssh. Before you close your current session, open a second terminal and confirm the new login works.

5) Open the Firewall

Set the SSH rule first. Otherwise, you may lock yourself out.

sudo ufw default deny incoming

sudo ufw allow OpenSSH

sudo ufw allow 80,443/tcp

sudo ufw allow from YOUR_HOME_IP to any port 6443 proto tcp

sudo ufw enable

For a single node, that is enough for now. However, ufw can block traffic between pods. So allow the pod and service ranges your method uses:

# k3s defaults

sudo ufw allow from 10.42.0.0/16 to any

sudo ufw allow from 10.43.0.0/16 to any

# kubeadm with Flannel defaults

sudo ufw allow from 10.244.0.0/16 to any

sudo ufw allow from 10.96.0.0/12 to any

Most providers also offer a firewall in their control panel. Mirror the same rules there for a second layer of defense.

How to Deploy a Single-Node Kubernetes Cluster with k3s

curl -sfL https://get.k3s.io | sh -s - server \

  --cluster-init \

  --tls-san YOUR_SERVER_IP

The install is one command:

curl -sfL https://get.k3s.io | sh -s - server \

  --cluster-init \

  --tls-san YOUR_SERVER_IP

Two flags deserve a closer look:

  • --cluster-init uses embedded etcd instead of SQLite. That choice gives you built-in snapshots and a clean path to high availability later.
  • --tls-san adds your public IP to the API certificate. Without it, remote kubectl fails with a certificate error.

To pin a version, set INSTALL_K3S_VERSION before the command. Pinning keeps new nodes identical to old ones.

Next, verify the node:

sudo kubectl get nodes

Expect one node with the status Ready. The roles column may differ slightly between versions.

k8s-cp-1   Ready    control-plane,etcd   45s   v1.xx.x+k3s1

Then list the system pods with sudo kubectl get pods -A. You should see Traefik, CoreDNS, the metrics server, and the local-path storage provisioner. All of them ship with k3s, so you don’t need to install anything extra.

The kubeconfig file lives at /etc/rancher/k3s/k3s.yaml. You will copy it to your laptop in the remote access step.

How to Install Kubernetes on Ubuntu with kubeadm

Skip Docker here. Kubernetes removed its built-in Docker support in v1.24, so use containerd instead.

Also check the repository in any tutorial you follow. The old apt.kubernetes.io and yum.kubernetes.io repos were frozen in September 2023. The current packages live at pkgs.k8s.io. Replace v1.36 below with the current stable minor version listed on kubernetes.io.

Step 1: Install and Configure containerd

containerd config default | sudo tee /etc/containerd/config.toml

sudo sed -i 's/SystemdCgroup = false/SystemdCgroup = true/' /etc/containerd/config.toml

sudo systemctl restart containerd

sudo systemctl enable containerd
containerd config default | sudo tee /etc/containerd/config.toml

sudo sed -i 's/SystemdCgroup = false/SystemdCgroup = true/' /etc/containerd/config.toml

sudo systemctl restart containerd

sudo systemctl enable containerd

The SystemdCgroup change matches the cgroup driver used by the kubelet. A mismatch causes restart loops.

Step 2: Add the Kubernetes Repository

sudo apt install -y apt-transport-https ca-certificates curl gpg

sudo mkdir -p -m 755 /etc/apt/keyrings

curl -fsSL https://pkgs.k8s.io/core:/stable:/v1.36/deb/Release.key | \

  sudo gpg --dearmor -o /etc/apt/keyrings/kubernetes-apt-keyring.gpg

echo 'deb [signed-by=/etc/apt/keyrings/kubernetes-apt-keyring.gpg] https://pkgs.k8s.io/core:/stable:/v1.36/deb/ /' | \

  sudo tee /etc/apt/sources.list.d/kubernetes.list

Step 3: Install kubeadm, kubelet, and kubectl

sudo apt update

sudo apt install -y kubelet kubeadm kubectl

sudo apt-mark hold kubelet kubeadm kubectl

sudo systemctl enable --now kubelet
sudo apt update

sudo apt install -y kubelet kubeadm kubectl

sudo apt-mark hold kubelet kubeadm kubectl

sudo systemctl enable --now kubelet

The hold command stops routine updates from upgrading Kubernetes by accident. Upgrades need care, so you control them yourself.

Step 4: Initialize the Control Plane

sudo kubeadm init \

  --pod-network-cidr=10.244.0.0/16 \

  --apiserver-cert-extra-sans=YOUR_SERVER_IP

The pod CIDR must match your network plugin. Flannel expects 10.244.0.0/16. Calico defaults to a different range, so check its docs first.

When the command finishes, set up kubectl for your user:

mkdir -p $HOME/.kube

sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config

sudo chown $(id -u):$(id -g) $HOME/.kube/config

Step 5: Install a Pod Network

Nodes stay NotReady until a network plugin runs. Flannel is the simplest choice:

kubectl apply -f https://github.com/flannel-io/flannel/releases/latest/download/kube-flannel.yml

Step 6: Allow Apps on a Single Node

By default, kubeadm keeps regular pods off the control plane. On a one-node cluster, remove that restriction:

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

Finally, confirm the node is ready with kubectl get nodes.

How to Add Worker Nodes and Build a Multi-Node Cluster

How Many VPS Servers Do You Need?

sudo cat /var/lib/rancher/k3s/server/node-token
sudo kubeadm token create --print-join-command

One server is enough for learning and light workloads. However, a single control plane is a single point of failure.

For most small projects, use one control plane and two workers. That layout keeps your apps running if a worker dies. For high availability, run three control-plane nodes. Three is the smallest count that keeps etcd quorum after one failure.

Use your provider’s private network between nodes when available. Otherwise, nodes talk over public IPs, so restrict every cluster port to the other nodes’ addresses. On k3s, you can also encrypt node traffic by adding --flannel-backend=wireguard-native to every server at install.

1) Join a Worker to k3s

First, read the token on the server:

sudo cat /var/lib/rancher/k3s/server/node-token

Then run this on each worker:

curl -sfL https://get.k3s.io | \

  K3S_URL=https://SERVER_IP:6443 K3S_TOKEN=YOUR_TOKEN sh -

2) Join a Worker to kubeadm

Print a fresh join command on the control plane:

sudo kubeadm token create --print-join-command

Paste the output on each worker with sudo. Tokens expire after 24 hours, so create a new one if a join fails later.

3) Add More k3s Servers for High Availability.

Start the first server with –cluster-init, as shown earlier. Then run this on the second and third servers:

curl -sfL https://get.k3s.io | K3S_TOKEN=YOUR_TOKEN sh -s - server \

  --server https://FIRST_SERVER_IP:6443 \

  --tls-san FIRST_SERVER_IP

Open ports 2379 and 2380 between the servers, since etcd uses them.

4) Confirm the New Nodes

Run kubectl get nodes on a control-plane node. Every node should reach Ready within a few minutes.

How to Connect to Your VPS Cluster Remotely with kubectl

Running kubectl over SSH gets old quickly. Set up access from your laptop instead.

First, install kubectl locally. Then copy the kubeconfig file.

For k3s:

ssh deploy@YOUR_SERVER_IP "sudo cat /etc/rancher/k3s/k3s.yaml" > ~/.kube/vps-config

For kubeadm:

scp deploy@YOUR_SERVER_IP:~/.kube/config ~/.kube/vps-config

Next, open the file and find the server: line. The k3s file points to https://127.0.0.1:6443. Replace 127.0.0.1 with your server IP. For kubeadm, confirm the address is one your laptop can reach.

Then point kubectl at the file and test it:

export KUBECONFIG=~/.kube/vps-config

kubectl get nodes

Now lock the door. Restrict port 6443 to your own IP in both ufw and the provider firewall. An open API server invites constant scanning.

Two errors show up often:

  • Certificate valid for the wrong address: The API certificate lacks your public IP. On k3s, add tls-san to /etc/rancher/k3s/config.yaml and restart the service. On kubeadm, regenerate the API server certificate with --apiserver-cert-extra-sans.
  • Connection timeout: Port 6443 is closed somewhere. Check ufw first, then the provider panel.

Deploy and Expose a Test App with HTTPS

A cluster proves nothing until it serves traffic. Run a test app with a real certificate.

Step 1: Create the Deployment and Service

kubectl create deployment web --image=nginx --replicas=2

kubectl expose deployment web --port=80
kubectl create deployment web --image=nginx --replicas=2

kubectl expose deployment web --port=80

Step 2: Point DNS at the Server

Create an A record for app.example.com that targets your server IP. Wait for it to propagate before you request a certificate.

Step 3: Install an Ingress Controller if Needed

k3s already includes Traefik, so skip this step on k3s. On kubeadm, a VPS has no cloud load balancer. Install ingress-nginx with host ports enabled, or add MetalLB.

Step 4: Install cert-manager

Install Helm from helm.sh first. Then run:

helm repo add jetstack https://charts.jetstack.io

helm repo update

helm install cert-manager jetstack/cert-manager \

  --namespace cert-manager --create-namespace \

  --set crds.enabled=true

Create a file named issuer.yaml with your email address:

apiVersion: cert-manager.io/v1

kind: ClusterIssuer

metadata:

  name: letsencrypt-prod

spec:

  acme:

    server: https://acme-v02.api.letsencrypt.org/directory

    email: [email protected]

    privateKeySecretRef:

      name: letsencrypt-prod-key

    solvers:

      - http01:

          ingress:

            ingressClassName: traefik

Apply it with kubectl apply -f issuer.yaml. Use nginx as the class name on a kubeadm cluster. For first tests, point the server URL at the ACME staging endpoint. That choice avoids rate limits while you debug.

Step 5: Create the Ingress

apiVersion: networking.k8s.io/v1

kind: Ingress

metadata:

  name: web

  annotations:

    cert-manager.io/cluster-issuer: letsencrypt-prod

spec:

  ingressClassName: traefik

  tls:

    - hosts:

        - app.example.com

      secretName: web-tls

  rules:

    - host: app.example.com

      http:

        paths:

          - path: /

            pathType: Prefix

            backend:

              service:

                name: web

                port:

                  number: 80

Apply the file, then check the certificate:

kubectl get certificate

curl -I https://app.example.com

The certificate should show READY: True within a minute or two. If it stays pending, read the pod logs with kubectl logs -n cert-manager deploy/cert-manager.

How to Secure and Back Up a Self-Hosted Kubernetes Cluster

Lock Down Access

Start with the API port, which you already restricted. Then cover three more habits:

  • Keep the admin kubeconfig on your laptop only. Never hand it to an app.
  • Give each app its own ServiceAccount and a namespace-level Role instead of cluster-admin.
  • Keep SSH keys only, as you set earlier.

Back up etcd

sudo k3s etcd-snapshot save --name manual-backup

Your cluster state lives in etcd. Losing it means rebuilding everything by hand.

On k3s with --cluster-init, take a snapshot with one command:

sudo k3s etcd-snapshot save --name manual-backup

On kubeadm, install etcd-client and run:

sudo ETCDCTL_API=3 etcdctl snapshot save /backup/etcd.db \

  --endpoints=https://127.0.0.1:2379 \

  --cacert=/etc/kubernetes/pki/etcd/ca.crt \

  --cert=/etc/kubernetes/pki/etcd/server.crt \

  --key=/etc/kubernetes/pki/etcd/server.key

Copy snapshots off the server. A backup stored on the failed disk helps nobody.

Provider VPS snapshots complement etcd backups. They do not replace them. A disk snapshot can capture etcd mid-write, so it may restore in a broken state.

Upgrade Safely

Take an etcd snapshot before every upgrade. On kubeadm, upgrade one minor version at a time with kubeadm upgrade plan and kubeadm upgrade apply. Never skip a minor version. Also keep each kubelet at or below the API server version.

On k3s, rerun the installer with INSTALL_K3S_VERSION pinned. Upgrade servers first, then workers.

Watch Memory

Small VPS plans fail by running out of memory. Check usage with kubectl top nodes. The metrics server ships with k3s, and kubeadm users can install it separately. Set resource requests and limits on your apps so one pod cannot starve the rest.

Troubleshooting a Kubernetes Cluster on a VPS

A Node Stays NotReady

The network plugin is usually missing or broken. Run kubectl describe node NODE_NAME and read the conditions. Then check kubectl get pods -n kube-system. Also confirm that swap is off.

kubeadm init fails

Read the preflight errors closely. The usual causes are swap, a busy port 6443, a missing runtime socket, or too few CPUs. A single-CPU VPS fails the check outright, so upgrade the plan.

Pods Die with OOMKilled

The node ran out of memory. Run kubectl describe pod POD_NAME and look for OOMKilled. Then add RAM, lower the replica count, or set tighter memory limits.

A Worker Cannot Join.

Test the API port from the worker with nc -zv SERVER_IP 6443. A failure points to a firewall rule on either server or in the provider panel. If the port is open, the join token has probably expired. Create a new one.

kubectl Times Out From Your Laptop

Port 6443 is closed to your IP. Fix ufw first. Then check the provider firewall. Finally, confirm your home IP has not changed.

FAQs

Is Kubernetes on a VPS Cheaper Than Managed Kubernetes?

Is a VPS Kubernetes Cluster Ready for Production?

Can You Still Use Docker With Kubernetes?

Your Next Step After the First Cluster

You now have a working cluster, remote kubectl access, and an app served over HTTPS. The choice of distribution and the VPS size determined most of the outcome, and you made both choices on purpose.

Your next step is a real application. Package it with Helm, add resource limits, and schedule an etcd backup with cron. That sequence turns a test cluster into one you can trust.

You also need the right server underneath it. Pick a Truehost VPS plan with full root access and a KVM virtual machine. Choose 2 GB of RAM or more for k3s, or 4 GB for kubeadm. Then spin up your first node today.

Elias N
Author

Elias N

SEO Expert Nairobi, KEN

SEO nerd by trade. Obsessing over keywords, content, and why Google does what it does.

View All Posts