Running a High-Availability K3s Cluster on VPS for Pakistani SaaS Startups

Learn how to deploy a scalable, high-availability Lightweight Kubernetes (K3s) cluster on NVMe VPS nodes tailored for SaaS startups in Pakistan.

Running a High-Availability K3s Cluster on VPS for Pakistani SaaS Startups

As the Pakistani startup ecosystem flourishes, particularly in the SaaS domain, the need for resilient, highly available, and scalable infrastructure is paramount. For early-stage and growing SaaS companies, traditional heavyweight Kubernetes distributions can be overkill, consuming significant resources and adding unnecessary operational complexity.

Enter K3s—a lightweight, fully compliant Kubernetes distribution designed by Rancher, built perfectly for resource-constrained environments like VPS nodes, IoT devices, and edge computing.

In this comprehensive guide, we’ll walk through deploying a High-Availability (HA) K3s Cluster using multiple NVMe Virtual Private Servers (VPS). This architecture ensures that your Pakistani SaaS application remains highly available without breaking the bank.

Why K3s for Pakistani SaaS Startups?

Operating a SaaS product requires 99.9% uptime, but scaling infrastructure effectively in emerging markets demands cost-efficiency. Using NVMe-based VPS instances offers a sweet spot between performance and price.

K3s provides:

  • Low Memory Footprint: Requires significantly less RAM and CPU overhead compared to standard K8s.
  • Embedded Datastore: By default, it supports embedded SQLite, but for HA, we’ll use an embedded etcd datastore.
  • Simplified Operations: Single binary installation handles the control plane and worker components.

When you transition from early-stage to a large-scale enterprise SaaS handling millions of API requests daily, you might outgrow standard VPS resources. At that scale, deploying robust Enterprise K8s clusters requires the underlying network architecture and bare-metal performance of Dedicated Servers, and specifically leveraging low-latency Dedicated Servers in Pakistan for optimal local data routing and compliance.

Architecture Overview

For a true High-Availability setup, you need at least three control-plane nodes to maintain etcd quorum. If one node fails, the other two continue to operate, ensuring zero downtime for your control plane.

Infrastructure Requirements:

  • 3x Control Plane Nodes: Minimum 2 vCPU, 4GB RAM (NVMe VPS)
  • 2+ Worker Nodes (Optional but recommended): Minimum 2 vCPU, 4GB RAM
  • 1x Load Balancer: To distribute traffic to the API Server (can use a managed LB or HAProxy on a small VPS).
  • OS: Ubuntu 22.04 or 24.04 LTS

Step 1: Preparing the VPS Nodes

Ensure all your VPS nodes are updated and can communicate with each other over a private network interface (or secure Tailscale/WireGuard mesh if spanning across distinct datacenters).

Run the following on all nodes:

sudo apt update && sudo apt upgrade -y
sudo apt install curl fail2ban ufw iptables -y

Set up UFW to allow K3s traffic:

sudo ufw allow 6443/tcp   # Kubernetes API Server
sudo ufw allow 2379:2380/tcp # etcd client & peer
sudo ufw allow 10250/tcp  # Kubelet metrics
sudo ufw allow 8472/udp   # Flannel VXLAN
sudo ufw enable

Step 2: Deploying the First Control Plane Node

K3s provides a convenient installation script. To establish our HA cluster, we’ll initialize the cluster with embedded etcd on the first node (let’s call it k3s-master-1).

curl -sfL https://get.k3s.io | sh -s - server \
  --cluster-init \
  --tls-san <LOAD_BALANCER_IP_OR_DOMAIN> \
  --node-external-ip <MASTER_1_PUBLIC_IP>

Note: Replace <LOAD_BALANCER_IP_OR_DOMAIN> with the IP or DNS of your API server load balancer. This ensures that worker nodes and your local kubectl can connect via the LB instead of a single point of failure.

Once installed, extract the node token, which is required to join other nodes to the cluster:

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

Keep this token secure.

Step 3: Joining Additional Control Plane Nodes

On k3s-master-2 and k3s-master-3, run the installation script pointing to the first master node and passing the token.

curl -sfL https://get.k3s.io | K3S_TOKEN="YOUR_NODE_TOKEN" sh -s - server \
  --server https://<MASTER_1_PRIVATE_IP>:6443 \
  --tls-san <LOAD_BALANCER_IP_OR_DOMAIN> \
  --node-external-ip <MASTER_X_PUBLIC_IP>

Wait a few minutes for etcd to synchronize across all three nodes. Verify the control plane is healthy from any master node:

sudo k3s kubectl get nodes

You should see all three master nodes listed as Ready.

Step 4: Adding Worker Nodes (Optional)

To keep application workloads isolated from the control plane, add worker nodes. On each worker node (k3s-worker-1, k3s-worker-2), execute:

curl -sfL https://get.k3s.io | K3S_TOKEN="YOUR_NODE_TOKEN" K3S_URL=https://<LOAD_BALANCER_IP_OR_DOMAIN>:6443 sh -

This command joins the node merely as an agent (worker), not running the control plane services.

Step 5: Configuring the API Server Load Balancer

If you haven’t already, configure HAProxy on a separate VPS or use a cloud provider Load Balancer. Here is a basic HAProxy config (/etc/haproxy/haproxy.cfg) for routing port 6443:

frontend k3s-frontend
    bind *:6443
    mode tcp
    default_backend k3s-backend

backend k3s-backend
    mode tcp
    balance roundrobin
    server master1 <MASTER_1_IP>:6443 check
    server master2 <MASTER_2_IP>:6443 check
    server master3 <MASTER_3_IP>:6443 check

Restart HAProxy: sudo systemctl restart haproxy.

Best Practices for Pakistani SaaS Deployments

  1. Storage Provisioning: For stateful applications (like PostgreSQL or Redis databases), K3s comes with Local Path Provisioner. For true HA, look into distributed block storage like Longhorn.
  2. Ingress Controllers: K3s defaults to Traefik, which is excellent. Configure Cert-Manager alongside Traefik to automate Let’s Encrypt SSL certificates for your SaaS subdomains.
  3. Monitoring: Deploy the kube-prometheus-stack to get immediate insight into CPU, RAM, and network bottlenecks of your VPS nodes.
  4. Latency Optimization: Ensure your VPS nodes are located in regions that offer the lowest latency to Pakistani users (e.g., Middle East or local Pakistani datacenters when available).

Conclusion

Deploying an HA K3s cluster on NVMe VPS instances provides a formidable infrastructure foundation for Pakistani SaaS startups. It bridges the gap between the chaotic management of standalone Docker containers and the overwhelming complexity of standard Kubernetes.

By distributing the control plane and workloads, you ensure that hardware failures—inevitable in any cloud environment—do not disrupt your users’ experience, fostering trust and enabling seamless growth for your SaaS business.