keepcalculator

06 Numbers and Powers

Multi-Node Rancher Kubernetes on VPS: Setup Guide

Card No. 06·68934 · Updated · Standard formula, shown below

This guide walks you through setting up a multi-node Rancher-managed Kubernetes cluster on VPS servers. You’ll provision three or more Ubuntu 22.04 VPS instances, install Rancher on one, and then add the others as worker nodes. By the end, you’ll have a production-ready Kubernetes cluster with a web UI for management, scaling, and deployments.

What You’ll Need

  • At least 3 VPS servers with Ubuntu 22.04 (or 20.04) — 2 vCPU / 4GB RAM each is a good starting point for small workloads.
  • Root SSH access to each server.
  • A domain name pointing to the Rancher server IP (optional but recommended for HTTPS).
  • Open ports: 6443 (Kubernetes API), 443 (Rancher UI), 2379-2380 (etcd), 10250 (kubelet), 10259 (kube-scheduler), 10257 (kube-controller-manager), and 30000-32767 (NodePort services).
  • Basic familiarity with Linux command line and SSH.

Step-by-Step

  1. Prepare each VPS — SSH into each server and run:
    sudo apt update && sudo apt upgrade -y
    sudo hostnamectl set-hostname k8s-node1  # change per node
    sudo timedatectl set-timezone UTC

    Add the hostname to /etc/hosts on all nodes so they can resolve each other.

  2. Install container runtime (containerd) on all nodes:
    sudo apt install -y containerd
    sudo mkdir -p /etc/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
  3. Disable swap on all nodes (Kubernetes requires it):
    sudo swapoff -a
    sudo sed -i '/ swap / s/^\(.*\)$/#\1/' /etc/fstab
  4. Load kernel modules on all nodes:
    sudo tee /etc/modules-load.d/containerd.conf <<EOF
    overlay
    br_netfilter
    EOF
    sudo modprobe overlay
    sudo modprobe br_netfilter
  5. Set sysctl parameters on all nodes:
    sudo tee /etc/sysctl.d/99-kubernetes.conf <<EOF
    net.bridge.bridge-nf-call-iptables = 1
    net.ipv4.ip_forward = 1
    net.bridge.bridge-nf-call-ip6tables = 1
    EOF
    sudo sysctl --system
  6. Install Docker (optional) — Rancher can use containerd directly, but Docker is often easier for debugging. Install on all nodes if you prefer:
    curl -fsSL https://get.docker.com | sudo sh
    sudo usermod -aG docker $USER
  7. Install Rancher on the first server (the management node). Use Docker to run Rancher:
    sudo docker run -d --restart=unless-stopped \
      -p 80:80 -p 443:443 \
      --privileged \
      --name rancher \
      rancher/rancher:latest

    Wait a few minutes for the container to start, then access https://<server-ip>. You’ll be prompted to set an admin password and a server URL (use your domain or IP).

  8. Create a Kubernetes cluster in Rancher — From the Rancher UI, click Create → Custom. Give the cluster a name (e.g., “prod”). Choose a Kubernetes version (the default is fine).
  9. Get the registration command — Rancher will display a command like curl -fL https://<rancher-server>/system-agent-install.sh | sudo sh -s - --server .... This command is unique to your cluster.
  10. Add the first node — Run the registration command on the Rancher server itself, but select the “etcd” and “control plane” roles in the UI before copying. This makes it the control plane node.
  11. Add worker nodes — On each additional VPS, run the same registration command but select only the “worker” role. Repeat for all worker nodes.
  12. Wait for nodes to become Active — In Rancher UI, go to the cluster’s Nodes tab. It may take a few minutes for each node to register and show as “Active”.
  13. Verify the cluster — Once all nodes are active, click Kubectl in the UI and run kubectl get nodes to see the list. You can also deploy a test workload from the UI.

Common Mistakes

  • Forgetting to disable swap — Kubernetes will fail to start kubelet if swap is on.
  • Using different container runtimes — Mixing Docker and containerd across nodes can cause issues. Stick to one.
  • Not opening firewall ports — Nodes won’t communicate if ports 6443, 10250, etc. are blocked.
  • Running the registration command with wrong roles — Ensure you select the correct role (etcd/control plane vs worker) before copying the command.
  • Using a weak admin password — Rancher UI is exposed on the internet; use a strong password and consider restricting access by IP.
  • Ignoring system requirements — 1GB RAM nodes will struggle; use at least 2GB for workers.

Tips

  • Use a domain name and Let’s Encrypt for Rancher’s HTTPS certificate — Rancher can auto-request one during setup if you provide your domain.
  • For production, use at least 3 control plane nodes (etcd) to avoid a single point of failure.
  • Keep all nodes on the same timezone and ensure NTP is running — time skew breaks certificates.
  • Use the Rancher UI to upgrade Kubernetes versions — it handles the process safely.
  • Back up the Rancher server’s Docker volume periodically (e.g., docker cp rancher:/var/lib/rancher /backup).
  • Test the cluster with a simple deployment (e.g., nginx) before moving real workloads.

Troubleshooting

  • Node never becomes Active — Check the Rancher logs: docker logs rancher. Also check the node’s kubelet logs: journalctl -u kubelet -f. Common causes: wrong registration command, firewall, or swap not disabled.
  • “Failed to connect to the server” when using kubectl — Verify the server URL in Rancher settings matches the actual IP/domain. Also ensure port 6443 is open.
  • etcd errors — If etcd pods crash-loop, check disk space (df -h) and ensure the data directory is writable.
  • Pods stuck in Pending — Usually means insufficient resources. Check node capacity with kubectl describe node.
  • Rancher UI not loading — Check that ports 80/443 are open and the container is running. Try restarting: docker restart rancher.
  • Certificate errors — If using a self-signed cert, add it to your browser’s trust store or configure a proper domain with Let’s Encrypt.

Frequently Asked Questions

Can I use the same VPS for both Rancher and a Kubernetes node?

Yes, you can run Rancher on the control plane node, but it adds overhead. For production, use a separate VPS for Rancher.

How many VPS servers do I need?

At minimum, 3: one for Rancher, one control plane, one worker. For high availability, use 5: Rancher, 3 control planes, and 1 worker.

What’s the difference between Rancher and Kubernetes?

Kubernetes is the container orchestration engine. Rancher is a management platform that provides a UI, RBAC, and tools for deploying and managing Kubernetes clusters.

Do I need to install Kubernetes separately?

No, Rancher’s registration command installs Kubernetes components (kubelet, kubeadm, etc.) automatically on each node.

Can I use a different OS like CentOS or Debian?

Yes, Rancher supports various Linux distributions, but the commands in this guide are for Ubuntu. Adjust package manager commands accordingly.

How do I upgrade Rancher?

Pull the new image and recreate the container: docker stop rancher && docker rm rancher, then run the same docker run command with the new image tag.

Related

Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.

More cards in this drawer

The whole Numbers and Powers drawer →