Prerequisites
- A VPS running Ubuntu 22.04 or Debian 12
- SSH access to your server
- A domain name pointed to your server’s IP address
- Your Kit project with a Dockerfile (run
kit docker:init)
Server Setup
1. Create a VPS
- Go to Hetzner Cloud Console
- Create a new project and add a server
- Choose Ubuntu 22.04 as the image
- Select your server size (CX11 is fine for small apps)
- Add your SSH key for secure access
2. Initial Server Configuration
SSH into your server and run initial setup:3. Configure PostgreSQL
Deploy Options
Choose one of the following deployment methods:- Option A: Build Locally
- Option B: Build on Server
- Option C: Use Docker
Build on your local machine and upload the binary:
Environment Configuration
Create your production environment file:systemd Services
Web Server Service
Create/etc/systemd/system/myapp.service:
Scheduler Service
If your app has scheduled tasks, create/etc/systemd/system/myapp-scheduler.service:
Enable and Start Services
Caddy Reverse Proxy
Caddy automatically handles HTTPS certificates with Let’s Encrypt.Install Caddy
Configure Caddy
Edit/etc/caddy/Caddyfile:
myapp.com with your actual domain.
Start Caddy
Health Checks
Kit includes a built-in/_kit/health endpoint that returns:
Check Database Connectivity
Add?db=true to also verify database connectivity:
External Monitoring
Use the health endpoint with monitoring services:- UptimeRobot: Add HTTP monitor for
https://myapp.com/_kit/health - Better Uptime: Configure health check endpoint
- Grafana: Scrape health endpoint metrics
Deployment Script
Create a deployment script for easy updates:Logs and Monitoring
View Logs
Log Rotation
systemd’s journald handles log rotation automatically. For long-term storage, consider:- Loki + Grafana: Self-hosted log aggregation
- Papertrail: Cloud-based logging service
- Logtail: Simple log management
Firewall Configuration
Secure your server with UFW:Scaling
Vertical Scaling
Upgrade your VPS to a larger instance for more CPU/memory.Horizontal Scaling
For multiple instances:- Set up a load balancer (Hetzner Load Balancer or HAProxy)
- Use a managed database (external PostgreSQL)
- Use Redis for session storage
- Deploy multiple app instances behind the load balancer
Costs
Hetzner offers competitive pricing:
Plus managed PostgreSQL when available, or use external services.
Troubleshooting
Service Won’t Start
Check logs for errors:- Missing environment variables
- Database connection failed
- Port already in use
Caddy Certificate Errors
Ensure:- Domain DNS points to your server
- Ports 80 and 443 are open
- No other service is using port 80