Kamal Deployment
Deploy Wraft using Kamal for production hosting
Kamal Deployment
Kamal is a deployment tool that makes it easy to deploy web applications to servers. This guide covers how to deploy Wraft using Kamal for production hosting.
Prerequisites
- A server with SSH access
- Docker installed on the server
- Kamal CLI installed locally
- Docker registry access (Docker Hub, GitHub Container Registry, etc.)
Server Setup
-
Prepare your server
- Ensure Docker is installed and running
- Create a user with sudo privileges for deployment
- Configure SSH key-based authentication
-
Install Kamal on your local machine
Configuration
Create a deploy.yml
file in your kamal config file with the following configuration:
Environment Variables
Set up the required environment variables for your deployment:
Deployment Steps
- Initialize Kamal
- Create the Kamal config directory
- Move the Kamal deployment config into the custom folder
-
Add your secrets to the .kamal/secrets file in the project root
-
Setup the deployment
This command will:
- Install Docker on the server if not present
- Configure the server for deployment
- Set up the required directories and permissions
- Deploy the application
- Add MinIO host entry
This will:
- Build and push the Docker image
- Deploy the application to the server
- Start all services and accessories
- Check deployment status
Configuration Details
Service Configuration
- service: The name of your application service
- image: Docker image name for your application
- servers: List of server IPs where the application will be deployed
- ssh: SSH connection details for the deployment server
Builder Configuration
- arch: Target architecture (amd64, arm64)
- context: Docker build context
- dockerfile: Path to the Dockerfile
Environment Variables
- clear: Environment variables that are not sensitive
- secret: Sensitive environment variables (set via export)
Proxy Configuration
- app_port: Port where your application runs
- response_timeout: Maximum response time in seconds
- path_prefix: URL path prefix
- healthcheck: Health check configuration
Accessories
Accessories are additional services that run alongside your main application:
- db: PostgreSQL database
- minio: Object storage service
- typesense: Search engine
- backend: Backend API service
Monitoring and Maintenance
View logs
Restart services
Update deployment
Troubleshooting
Common Issues
-
SSH Connection Issues
- Verify SSH key authentication
- Check server firewall settings
- Ensure the user has sudo privileges
-
Docker Registry Issues
- Verify registry credentials
- Check image name and tags
- Ensure registry is accessible from the server
-
Port Conflicts
- Check if required ports are available
- Verify firewall rules
- Ensure no other services are using the same ports
Health Checks
Monitor the health of your deployment:
Security Considerations
-
Environment Variables
- Never commit sensitive environment variables to version control
- Use Kamal's secret management for sensitive data
- Rotate secrets regularly
-
Network Security
- Configure firewall rules appropriately
- Use HTTPS in production
- Implement proper access controls
-
Database Security
- Use strong passwords for database access
- Configure SSL connections
- Regular backups
Accessing a Running Container
Backup and Recovery
Database Backups
Volume Backups
Scaling
To scale your deployment across multiple servers, add additional server IPs to the servers
section:
Performance Optimization
-
Resource Limits
- Configure appropriate memory and CPU limits
- Monitor resource usage
- Scale based on demand
-
Caching
- Implement application-level caching
- Use CDN for static assets
- Configure database query caching
-
Monitoring
- Set up application monitoring
- Monitor server resources
- Configure alerting for critical issues
- Set up application monitoring
References and Resources
Official Documentation
- Kamal Official Documentation - Complete guide and reference
- Kamal GitHub Repository - Source code and issues
- Kamal Installation Guide - Installation instructions
- Kamal Configuration Reference - Configuration options
Related Resources
- Docker Documentation - Docker containerization
- PostgreSQL Documentation - Database setup and management
- MinIO Documentation - Object storage configuration
- Typesense Documentation - Search engine setup