Complete Guide to Deploying Docker Swarm and Kubernetes on VPS from Basic Setup to Production Environment
A detailed guide on deploying Docker Swarm and Kubernetes on VPS, from basic installation to configuring a secure, stable, and scalable production environment.
Introduction
Deploying container orchestration systems like Docker Swarm and Kubernetes on VPS is essential for building modern, scalable, and automated application environments. This guide walks you through the process from basic setup to establishing a stable, secure, and high-performance production environment.
Prerequisites
- One or more VPS servers (minimum 2 for Swarm, 3+ for Kubernetes)
- Linux operating system (Ubuntu 20.04/22.04 or CentOS 8)
- SSH access with root or sudo privileges
- Static IP addresses for each server
- Firewall configured (ufw or iptables)
- Docker installed on all VPS instances
1. Install and Configure Docker Swarm
First, install Docker if not already installed:
sudo apt update
sudo apt install -y docker.io
sudo systemctl enable docker
sudo systemctl start docker
Initialize the Swarm on the manager node:
docker swarm init --advertise-addr <IP_MANAGER>
Join worker nodes to the Swarm:
docker swarm join --token <SWARM_TOKEN> <IP_MANAGER>:2377
Verify the Swarm status:
docker node ls
2. Deploy Kubernetes on VPS
Install kubeadm, kubelet, and kubectl:
sudo apt update
sudo apt install -y apt-transport-https ca-certificates curl
curl -fsSL https://pkgs.k8s.io/core:/stable:/v1.28/deb/Release.key | sudo gpg --dearmor -o /usr/share/keyrings/kubernetes-archive-keyring.gpg
echo "deb [signed-by=/usr/share/keyrings/kubernetes-archive-keyring.gpg] https://pkgs.k8s.io/core:/stable:/v1.28/deb/ /" | sudo tee /etc/apt/sources.list.d/kubernetes.list
sudo apt update
sudo apt install -y kubelet kubeadm kubectl
sudo apt-mark hold kubelet kubeadm kubectl
Initialize the Kubernetes cluster:
kubeadm init --pod-network-cidr=10.244.0.0/16
Join worker nodes to the cluster:
kubeadm join <MASTER_IP>:6443 --token <TOKEN> --discovery-token-ca-cert-hash sha256:<HASH>
3. Test and Optimize the Environment
After deployment, verify the cluster status:
docker node ls (Swarm)
kubectl get nodes (Kubernetes)
Optimize performance:
- Set resource limits (CPU, RAM) for services
- Apply security policies (Pod Security Policies)
- Set up monitoring with Prometheus and Grafana
- Integrate logs with ELK Stack or Loki
4. Security and Backup
Secure the production environment with:
- Enable TLS for internal communication
- Configure firewall (ufw) and only open necessary ports
- Perform regular backups of configurations and data
- Apply security updates regularly
5. Testing and Validation
Conduct tests to ensure reliability:
- Run test pods to verify scalability
- Simulate node failure to test failover
- Assess performance using tools like k6 or JMeter
6. Troubleshooting
Address common issues:
- Node fails to join Swarm/Kubernetes: Check network connectivity and token validity
- Pods fail to start: Check logs using
kubectl logs <pod-name> - Network issues: Install and configure pod network (Flannel, Calico)
References
- Complete Guide to Configuring Load Balancing for Web Server Clusters Using HAProxy on VPS 1
- Transform VPS into an AI Privacy Proxy Engine: Protecting Business Data from Public Cloud AI
Related infrastructure & engineering guides: High-RAM Cloud VPS for Self-Hosted LLMs & API Gateways
High-RAM Cloud VPS Plans Optimized for AI, Databases & Cache
Enterprise RAID 10 NVMe SSDs, CMC & FPT District 9 uplinks with Anycast Anti-DDoS and 99.99% SLA.
VPS-4E
10% VAT included
- CPU: 4 vCPU
- RAM: 8 GB
- SSD: 50 GB NVMe
