Creating a new DigitalOcean droplet to deploy n8n self-hosted

How to Deploy n8n Self-Hosted: A Step-by-Step Guide on DigitalOcean / AWS / Kubernetes

by
in
Uncategorized

Tags :

Automation is no longer a luxury—it’s a necessity for modern businesses and developers. From automating repetitive workflows to integrating multiple applications seamlessly, tools like n8n have become invaluable. While n8n offers a cloud-hosted version, many teams prefer to self-host it for greater control, flexibility, and cost efficiency.

In this guide, we’ll walk you step by step through how to deploy n8n in a self-hosted environment, focusing on three popular setups: DigitalOcean, AWS, and Kubernetes. Whether you’re a solo developer, a startup, or a growing enterprise, by the end of this post, you’ll have a clear path to running n8n securely and reliably.

What is n8n?

n8n (short for “nodemation”) is an open-source workflow automation tool that lets you connect APIs, services, and applications to automate processes. Think of it as a self-hosted alternative to Zapier or Integromat, but with more flexibility and control.

Key features of n8n include:

  • 150+ integrations with popular tools and services
  • Visual workflow editor for drag-and-drop automation
  • Custom code execution with JavaScript functions
  • Open-source and extensible for developers who want to build their own nodes
  • Self-hosted option for full data ownership

Self-hosting n8n ensures that sensitive data stays on your infrastructure and gives you freedom from SaaS pricing limitations.

Why Self-Host n8n?

Before diving into deployment, let’s quickly look at the benefits of running n8n on your own infrastructure:

  1. Data Ownership – Keep all your automation data within your servers.
  2. Flexibility – Customize workflows and integrations as needed.
  3. Scalability – Deploy on a single VPS or scale with Kubernetes for enterprise needs.
  4. Cost Control – Run n8n for free (other than hosting costs) instead of paying per workflow execution.
  5. Security – Apply your own security rules, firewalls, and access policies.

Prerequisites for Deployment

Regardless of whether you’re deploying on DigitalOcean, AWS, or Kubernetes, you’ll need a few prerequisites in place:

  • A server with at least 2GB RAM (recommended 4GB for production)
  • Docker and Docker Compose installed
  • Node.js (if you plan to run without Docker)
  • Domain name (optional but recommended for SSL setup)
  • Basic knowledge of Linux command line

Now, let’s go step by step.

Part 1: Deploying n8n on DigitalOcean

DigitalOcean is one of the easiest platforms for developers to get started with. Their droplets (virtual machines) can be set up within minutes.

Step 1: Create a DigitalOcean Droplet

  1. Sign in to your DigitalOcean account.
  2. Click Create Droplet.
  3. Choose an image – Ubuntu 22.04 LTS is a good choice.
  4. Select a plan – at least a $10/month droplet (2GB RAM) is recommended.
  5. Add your SSH key for secure login.
  6. Click Create Droplet.

Once created, you’ll get the server’s public IP address.

Step 2: Install Docker and Docker Compose

SSH into your droplet:

ssh root@your_server_ip

Update and install dependencies:

sudo apt update && sudo apt upgrade -y
sudo apt install docker.io docker-compose -y

Enable Docker:

sudo systemctl enable docker
sudo systemctl start docker

Step 3: Set Up n8n with Docker Compose

Create a new directory for n8n:

mkdir n8n && cd n8n

Create a docker-compose.yml file:

version: '3'
services:
  n8n:
    image: n8nio/n8n
    restart: always
    ports:
      - "5678:5678"
    volumes:
      - ./n8n_data:/home/node/.n8n
    environment:
      - GENERIC_TIMEZONE=UTC
      - GENERIC_TIMEZONE_OFFSET=+00:00

Start n8n:

docker-compose up -d

Now n8n should be available at http://your_server_ip:5678.

Step 4: Add a Reverse Proxy with SSL (Optional but Recommended)

To make n8n accessible via a domain with HTTPS:

  1. Install Nginx and Certbot:
sudo apt install nginx certbot python3-certbot-nginx -y
  1. Point your domain DNS to the droplet’s IP.
  2. Configure Nginx reverse proxy.
  3. Secure with Let’s Encrypt SSL:
sudo certbot --nginx -d yourdomain.com

Now you can access n8n securely at https://yourdomain.com.

Part 2: Deploying n8n on AWS (EC2)

AWS offers more flexibility and scalability than DigitalOcean but requires more setup. We’ll use an EC2 instance for deployment.

Step 1: Launch an EC2 Instance

  1. Log in to AWS Management Console.
  2. Go to EC2 → Launch Instance.
  3. Choose Ubuntu 22.04 LTS as the AMI.
  4. Select an instance type – t3.small (2GB RAM) is suitable.
  5. Configure security groups to allow ports 22 (SSH), 80 (HTTP), and 443 (HTTPS).
  6. Launch with your key pair.

Step 2: Install Docker

SSH into the EC2 instance:

ssh -i yourkey.pem ubuntu@your_ec2_ip

Install Docker and Docker Compose as we did with DigitalOcean.

Step 3: Deploy n8n

Use the same Docker Compose setup from the DigitalOcean section.

Step 4: Configure Domain and SSL

  • Use Route 53 to manage your domain.
  • Create an A record pointing to your EC2 instance IP.
  • Set up Nginx reverse proxy with SSL as shown earlier.

AWS users may also leverage Elastic IPs to ensure the server IP doesn’t change.

Part 3: Deploying n8n on Kubernetes

If you’re running workloads at scale, Kubernetes (K8s) is the best way to manage n8n with high availability and scalability.

Step 1: Prepare Your Kubernetes Cluster

You can use:

  • Amazon EKS (AWS-managed Kubernetes)
  • DigitalOcean Kubernetes
  • Self-managed K8s (kubeadm, Minikube, etc.)

Ensure kubectl and helm are installed locally.

Step 2: Create a Namespace for n8n

kubectl create namespace n8n

Step 3: Deploy PostgreSQL or MySQL (Optional but Recommended)

While n8n can use SQLite, for production we recommend PostgreSQL.

You can deploy it via Helm:

helm repo add bitnami https://charts.bitnami.com/bitnami
helm install postgres bitnami/postgresql --namespace n8n

Step 4: Deploy n8n with Helm or YAML

Create a deployment file n8n-deployment.yaml:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: n8n
  namespace: n8n
spec:
  replicas: 2
  selector:
    matchLabels:
      app: n8n
  template:
    metadata:
      labels:
        app: n8n
    spec:
      containers:
      - name: n8n
        image: n8nio/n8n
        ports:
        - containerPort: 5678
        env:
        - name: DB_TYPE
          value: postgresdb
        - name: DB_POSTGRESDB_HOST
          value: postgres

Apply it:

kubectl apply -f n8n-deployment.yaml

Step 5: Expose n8n Service

apiVersion: v1
kind: Service
metadata:
  name: n8n-service
  namespace: n8n
spec:
  type: LoadBalancer
  selector:
    app: n8n
  ports:
    - protocol: TCP
      port: 80
      targetPort: 5678

Apply it:

kubectl apply -f n8n-service.yaml

This will create a LoadBalancer service (AWS ELB or DigitalOcean LoadBalancer) to expose n8n publicly.

Step 6: Configure Ingress with SSL

For production, use an Ingress Controller (like NGINX Ingress) and configure SSL with Cert-Manager.

Best Practices for Production

Regardless of your hosting environment, follow these best practices:

  1. Use HTTPS only – Always secure your n8n instance with SSL.
  2. Enable authentication – n8n supports basic auth with environment variables.
  3. Set up regular backups – Especially for database storage.
  4. Use environment variables for credentials, not hardcoded values.
  5. Monitor resources – Use tools like Prometheus, Grafana, or AWS CloudWatch.

Troubleshooting Common Issues

  • Port 5678 not accessible? Check firewall or security group rules.
  • SSL certificate errors? Ensure DNS points correctly to your server.
  • n8n not persisting workflows? Verify volume mounts in Docker or Persistent Volumes in Kubernetes.
  • High memory usage? Increase server RAM or scale replicas in Kubernetes.

Conclusion

Deploying n8n self-hosted gives you the freedom, control, and scalability that SaaS automation tools can’t always provide. Whether you choose a simple VPS on DigitalOcean, a more scalable setup on AWS, or a robust deployment with Kubernetes, you now have the step-by-step guidance to get started.

By self-hosting n8n, you can automate workflows while maintaining data ownership, security, and cost efficiency.

If you found this guide useful, share it with your team or community—and don’t forget to bookmark this page for future reference.

Related Post