Skip to main content
This guide covers deploying your Kit application to a VPS (Virtual Private Server) using Hetzner Cloud. The same principles apply to other VPS providers like DigitalOcean Droplets, Linode, Vultr, or AWS EC2.

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

  1. Go to Hetzner Cloud Console
  2. Create a new project and add a server
  3. Choose Ubuntu 22.04 as the image
  4. Select your server size (CX11 is fine for small apps)
  5. Add your SSH key for secure access

2. Initial Server Configuration

SSH into your server and run initial setup:

3. Configure PostgreSQL

For production, consider using a managed database service like Hetzner’s upcoming managed PostgreSQL, or services like Neon, Supabase, or AWS RDS for better reliability and backups.

Deploy Options

Choose one of the following deployment methods:
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:
Replace myapp.com with your actual domain.

Start Caddy

Caddy will automatically obtain and renew SSL certificates.

Health Checks

Kit includes a built-in /_kit/health endpoint that returns:

Check Database Connectivity

Add ?db=true to also verify database connectivity:
Returns:

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:
Make it executable:

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:
Never expose port 8080 directly. Always use Caddy as a reverse proxy to handle SSL and security headers.

Scaling

Vertical Scaling

Upgrade your VPS to a larger instance for more CPU/memory.

Horizontal Scaling

For multiple instances:
  1. Set up a load balancer (Hetzner Load Balancer or HAProxy)
  2. Use a managed database (external PostgreSQL)
  3. Use Redis for session storage
  4. 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:
Common issues:
  • 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

Database Connection Issues

Test connection manually:

Health Check Failing