What is n8n?
n8n is an open source workflow automation platform that is self-hostable. It is used to automate custom processes, integrate tools and even improve DevOps workflows all in one platform. It offers a visual interface to design processes without serious programming skills, making it perfect for automating various processes in DevOps.
Why Use n8n for DevOps?
Automates repetitive tasks (e.g., deployments, monitoring, logging).
Integrates with CI/CD tools like Jenkins, GitHub actions, GitLab CI etc.
Manages tasks like deployments, monitoring, cloud infrastructure (AWS, Azure, GCP) and System health monitoring (Prometheus, Grafay, Slack)
Saves time.
There are various methods for installing n8n, Docker, Linux, a Desktop app, MacOS or others. The methods explained below will help you with workflows and provide image descriptions.
Install n8n Using Docker (Recommended)
Open Terminal:
Create Directory:
mkdir n8n && cd n8n
Run n8n Container:
sudo docker run -d --name n8n -p 5678:5678 -v ~/.n8n:/home/node/.n8n n8nio/n8n
Verify Container:
docker ps
The command above shows any containers active in Docker.
Install n8n via npm
Install n8n:
npm install -g n8n
This makes n8n available on your device.
Start n8n:
n8n start
This enables the n8n service for web access.
Install n8n on Kubernetes
Install prerequisites and Download the Google Cloud public signing key
sudo apt update
sudo apt install -y ca-certificates curl
sudo mkdir -p /etc/apt/keyrings
curl -fsSL https://pkgs.k8s.io/core:/stable:/v1.30/deb/Release.key | sudo tee /etc/apt/keyrings/kubernetes-apt-keyring.asc > /dev/null
echo "deb [signed-by=/etc/apt/keyrings/kubernetes-apt-keyring.asc] https://pkgs.k8s.io/core:/stable:/v1.30/deb/ /" | sudo tee /etc/apt/sources.list.d/kubernetes.list > /dev/null
Create Namespace:
kubectl create namespace n8n
Deploy n8n:
kubectl apply -f https://raw.githubusercontent.com/n8n-io/n8n/master/kubernetes/n8n-deployment.yaml
Creating a Workspace
Access Dashboard:
Create Workflow:
Name Workflow:
Deploying a Dockerized App on AWS EC2
Add Execute Command Node:
Deploy Application:
docker pull myrepo/myapp:latest
docker stop myapp-container
docker rm myapp-container
docker run -d --name myapp-container -p 80:80 myrepo/myapp:latest
Enter these commands in the “Command” field of the Execute Command node.
Test Deployment:
Deploying a Node.js App on AWS EC2 Using PM2
Below is the step-by-step process to deploy a Node.js application on an AWS EC2 instance using PM2 within your n8n workflow, similar to the structure you provided for a Dockerized app.
Add Execute Command Node:
In the n8n workflow canvas, click the "+" button to add a new node.
Search for "Execute Command" under the "SSH" category and add it to your workflow.
Configure the node with the following details for your EC2 instance:
Enter the following commands in the "Command" field of the Execute Command node:
# Navigate to the app directory (create if it doesn't exist)
mkdir -p /home/ec2-user/myapp && cd /home/ec2-user/myapp && \
# Clone or pull the latest code from your Git repository
git clone https://github.com/myrepo/myapp.git . || git pull origin main && \
# Install application dependencies and create a build
npm install && npm run build && \
# Stop any existing PM2 process for the app (if running)
pm2 stop myapp || true && \
# Start or restart the app with PM2
pm2 start index.js --name "myapp" --restart-delay=1000
Workflow of n8n for project deployment
1. Running Terraform with n8n
Deploy project in AWS EC2 Instance Using Terraform
Search for the "SSH" category and add it to your workflow.
2. Create a terraform file for deploy project
3. Add Execute Command Node:
terraform init
terraform apply -auto-approve
Add an Execute Command node and enter these Terraform commands.
n8n provides a powerful way to automate DevOps workflows, integrating with essential tools like Terraform, Prometheus, and CI/CD pipelines. DevOps teams can achieve seamless automation and efficiency by setting up workflows for deployments, monitoring and security.
Ready to transform your business with our technology solutions? Contact Us today to Leverage Our AI/ML Expertise.