• Mail us
  • Book a Meeting
  • Call us
  • Chat with us

AI/ML

The Power of n8n for DevOps Automation


Introduction to n8n

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.

     

Installing n8n

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:

  • Open your terminal application (e.g. Bash on Linux, PowerShell on Windows or Terminal on macOS).

Create Directory:

mkdir n8n && cd n8n

 

  • This will create a new n8n folder and open it.

Run n8n Container:

sudo docker run -d --name n8n -p 5678:5678 -v ~/.n8n:/home/node/.n8n n8nio/n8n
  • The command above executes the n8n container in detached mode (-d), which allows the n8n instance to run in the background without tying up the terminal. The command binds port 5678 to the host while mapping a file directory for data persistence.

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 updatesudo apt install -y ca-certificates curlsudo mkdir -p /etc/apt/keyringscurl -fsSL https://pkgs.k8s.io/core:/stable:/v1.30/deb/Release.key | sudo tee /etc/apt/keyrings/kubernetes-apt-keyring.asc > /dev/nullecho "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
  • This command provisions a Kubernetes namespace for isolated n8n resource usage.

 

Deploy n8n:

kubectl apply -f https://raw.githubusercontent.com/n8n-io/n8n/master/kubernetes/n8n-deployment.yaml

  • This command sets the deployment configuration for n8n from the official repository.

 

Setting Up n8n for DevOps Workflows

Creating a Workspace

Access Dashboard:

  • Open http://localhost:5678 in your web browser (or the URL of your hosted n8n instance).

Create Workflow:

  • Click the “New Workflow” button on the dashboard.

Name Workflow:

  • Enter a name for your workflow (e.g., “Deploy_EC2_App”) in the name field at the top of the canvas.

 

Running Deployments with n8n

Deploying a Dockerized App on AWS EC2

Add Execute Command Node:

  • In the n8n workflow canvas, click the "+" button to add a node.
  • Search “Execute Command” in “SSH” and add it.
  • Configure the node with the EC2 instance’s IP address, username (e.g., ec2-user), and authentication method (e.g., private key or password).

 

Deploy Application:

docker pull myrepo/myapp:latestdocker stop myapp-containerdocker rm myapp-containerdocker run -d --name myapp-container -p 80:80 myrepo/myapp:latest

 

Enter these commands in the “Command” field of the Execute Command node.

n8n

 

Test Deployment:

  • Access the EC2 instance’s public IP in a browser (e.g., http://54.123.45.67).

 

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:

  • IP Address: The public IP of your EC2 instance (e.g., 54.123.45.67).
  • Username: The default username for your EC2 instance (e.g., ec2-user for Amazon Linux, or ubuntu for Ubuntu instances).
  • Authentication Method: Choose your authentication method:
  • Private Key: If using a key pair, paste the private key (e.g., the .pem file contents) and ensure the key pair is associated with your EC2 instance.
  • Password: If using password-based authentication, provide the password (though key-based authentication is more secure and recommended for EC2).
  • Port: The default port for SSH is 22 unless you’ve changed it in your EC2 security group or instance settings.

 

 

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 repositorygit clone https://github.com/myrepo/myapp.git . || git pull origin main && \# Install application dependencies and create a buildnpm install && npm run build && \# Stop any existing PM2 process for the app (if running)pm2 stop myapp || true && \# Start or restart the app with PM2pm2 start index.js --name "myapp" --restart-delay=1000

 

Workflow of n8n for project deployment

 

Infrastructure Automation

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 initterraform apply -auto-approve

 

Add an Execute Command node and enter these Terraform commands.

 

Conclusion

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. 

Share

facebook
LinkedIn
Twitter
Mail
AI/ML

Related Center Of Excellence