DEV Community

Cover image for A Guide on how to run a Complete CI/CD Pipeline with Node.js, Docker, and Kubernetes.

A Guide on how to run a Complete CI/CD Pipeline with Node.js, Docker, and Kubernetes.

DevOps Model Defined.

DevOps is the combination of cultural philosophies, practices, and tools that increases an organization’s ability to deliver applications and services at high velocity: evolving and improving products at a faster pace than organizations using traditional software development and infrastructure management processes. This speed enables organizations to better serve their customers and compete more effectively in the market.

Also, DevOps can be best explained as people working together to conceive, build and deliver secure software at top speed. DevOps practices enable software development (dev) and operations (ops) teams to accelerate delivery through automation, collaboration, fast feedback, and iterative improvement. Stemming from an Agile approach to software development, a DevOps process expands on the cross-functional approach of building and shipping applications in a faster and more iterative manner.

In adopting a DevOps development process, you are making a decision to improve the flow and value delivery of your application by encouraging a more collaborative environment at all stages of the development cycle. DevOps represents a change in mindset for IT culture. In building on top of Agile, lean practices, and systems theory, DevOps focuses on incremental development and rapid delivery of software. Success relies on the ability to create a culture of accountability, improved collaboration, empathy, and joint responsibility for business outcomes.

***CORE DEVOPS PRINCIPLES*
Automation of the software development lifecycle**. This includes automating testing, builds, releases, the provisioning of development environments, and other manual tasks that can slow down or introduce human error into the software delivery process.

** Collaboration and communication**. A good DevOps team has automation, but a great DevOps team also has effective collaboration and communication.

Continuous improvement and minimization of waste. From automating repetitive tasks to watching performance metrics for ways to reduce release times or mean-time-to-recovery, high performing DevOps teams are regularly looking for areas that could be improved.
**
Hyperfocus on user needs with short feedback loops**. Through automation, improved communication and collaboration, and continuous improvement, DevOps teams can take a moment and focus on what real users really want, and how to give it to them.
By adopting these principles, organizations can improve code quality, achieve a faster time to market, and engage in better application planning.

However, having a niche of what DevOps is about, we dive into the practical aspect of how to run a Complete CI/CD Pipeline with Node.js, Docker, and Kubernetes, breaking down into steps on how to use the tools to achieve an application.

Before starting, you need to install these tools on your machine:

Required Downloads:

  1. Node.js (v18 or higher) - Current LTS: v20.x

Download from: https://nodejs.org/
Choose the LTS version (20.x as of 2025)
Verify installation: node --version and npm --version

  1. Git - Latest stable version

Download from: https://git-scm.com/downloads
Choose your operating system version
Verify installation: git --version

  1. Docker Desktop - Latest version

Download from: https://www.docker.com/products/docker-desktop/
Install and start Docker Desktop
Verify installation: docker --version and docker-compose --version

  1. GitHub Account

Sign up at: https://github.com
You'll need this for hosting your code and CI/CD pipeline

  1. Code Editor (Optional but recommended)

VS Code: https://code.visualstudio.com/
Or any editor you prefer (Sublime Text, Atom, etc.)

Verify Everything is Installed
node --version # Should show v18.x+ or v20.x+
npm --version # Should show 9.x+ or 10.x+
git --version # Should show 2.34+
docker --version # Should show 24.x+

The above shows that all application to be used for the project are installed.

The Procedure:

_Step 1 Creation of a Folder for the work or project you are about to do. Select File and Click on the icon Open folder, it will take you the PC folder, give the new folder the name you want it to have.

Click on the View icon, you will have some lists of icon, click on Terminal

Step 1:1 Set Up Git for Version Control_

What this step does: Configures Git on your machine so it knows who you are when you make commits, and sets up proper project tracking.

One-time Git Configuration

git config --global user.name "Your Name"
git config --global user.email "you@example.com"
git config --global init.defaultBranch main

The above shows my name and e-mail as the user.

Create and Initialize Project

mkdir new-devops-project that is, create a new project file.

cd new-devops-project

git init

The directory has been initialize by the use of git init command and it has turn to a repo although the file is still empty.

Step 2: Build a Node.js Web App

What this step does: Creates a web application using Node.js that can serve web pages and API endpoints.

Initialize Node.js Project

What this step does: Creates a package.json file that describes your project and manages dependencies.

Create package.json with default settings

npm init -y

In the image above, the default package json was created, it will be deleted because it is not the original file to be used, it will be replaced.

Below is the original file to be worked with.

Create Application File
What this code does:

Creates an HTTP server that listens on port 3000
Serves different endpoints (/, /health, /info, /metrics)
Includes security headers and proper error handling
Provides graceful shutdown capability
Exports the server for testing
Create app.js:

The code for the app.js created are shown below:

The Next Step after the main app.js file has been created, to make the code to run, we need what is called a' Dependencies".

Install Dependencies

Install testing and development tools

npm install --save-dev jest eslint supertest

Install all dependencies (creates node_modules folder)

npm install

What you'll see:

A node_modules/ folder with all installed packages
A package-lock.json file that locks dependency versions

Below is the folder called node_mouldes after the command npm install --save-dev jest eslint supertest has been ran. This holds the codes

Step 3: Create Proper Tests

What this step does: Sets up automated testing so you can verify your application works correctly every time you make changes.

Create tests directory and test file

Create a folder for your tests

mkdir tests

Create the main test file

touch tests/app.test.js

Create test file
Copy this code into tests/app.test.js: The code that was copied is shown below:

Create Jest configuration
Create jest.config.js:

Step 4: GitHub Actions CI/CD Pipeline

What this step does: Creates an automated pipeline that runs tests and builds Docker images every time you push code to GitHub.

Create workflow directory

Create the GitHub Actions directory structure

mkdir -p .github/workflows

Create CI/CD pipeline file
Create .github/workflows/ci.yml:

Step 5: Dockerfile

What this step does: Creates instructions for Docker to build a container image of your application that can run anywhere.

What this Dockerfile does:

Uses multi-stage builds for smaller image size

  • Installs curl for health checks.

  • Creates a non-root user for security.

  • Sets up proper file permissions.

  • Configures health checks.

Create Dockerfile:

Step 6: Essential Configuration Files

What this step does: Creates configuration files that tell various tools what to ignore, how to behave, and what settings to use.

Create .dockerignore

Create .dockerignore:

node_modules npm-debug.log* .git .github .env .env.local .env..local logs *.log coverage .nyc_output .vscode .idea *.swp *.swo .DS_Store Thumbs.db README.md tests/ jest.config.js .eslintrc

Create .gitignore

Create .gitignore:

Dependencies node_modules/ npm-debug.log* # Runtime data pids .pid *.seed *.pid.lock # Coverage coverage/ .nyc_output # Environment variables .env .env.local .env..local # Logs logs *.log # IDE .vscode/ .idea/ *.swp *.swo # OS .DS_Store Thumbs.db

Create environment template

Create .env.example:

Server Configuration PORT=3000 NODE_ENV=production # Logging LOG_LEVEL=info

Create ESLint configuration

Create .eslintrc.js:
module.exports = {
env: {
node: true,
es2021: true,
jest: true
},
extends: ['eslint:recommended'],
parserOptions: {
ecmaVersion: 12,
sourceType: 'module'
},
rules: {
'no-console': 'off',
'no-unused-vars': ['error', { 'argsIgnorePattern': '^_' }]
}
};

Step 7: Docker Compose for Development

What this step does: Creates a Docker Compose file that makes it easy to run your application and any supporting services with a single command.

Create docker-compose.yml:

version: '3.8'

services:
app:
build: .
ports:
- "3000:3000"
environment:
- NODE_ENV=development
- PORT=3000
restart: unless-stopped
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:3000/health"]
interval: 30s
timeout: 10s
retries: 3
start_period: 10s

Step 8: Test Everything Locally

What this step does: Shows you how to actually run and test your application locally before deploying it.

Install and Test Locally

Install all dependencies from package.json

npm install

Run your test suite to make sure everything works

npm test

What you'll see:

Tests should pass with green checkmarks: ✓ GET / should return welcome page
Server starts and shows: 🚀 Server running at http://localhost:3000/

The test ran was successful.

Start the application server

npm start

The image above shows that the application is running locally.

Test endpoints (in a new terminal window):

curl http://localhost:3000/ # Homepage

curl http://localhost:3000/health #_ Health check JSON_

curl http://localhost:3000/info # _System info JSON _

curl http://localhost:3000/metrics #_ Prometheus metrics_

Docker Commands

Build image

docker build -t my-devops-app:latest .

Run container

docker run -d \
--name my-devops-container \
-p 3000:3000 \
--restart unless-stopped \
my-devops-app:latest

Check container status

docker ps

docker logs my-devops-container

Test health check

curl http://localhost:3000/health

Stop container

docker stop my-devops-container

docker rm my-devops-container

Docker Compose Commands

Start all services defined in docker-compose.yml

docker-compose up -d

View real-time logs from all services

docker-compose logs -f

Stop all services and clean up

docker-compose down

Step 9: Deploy to GitHub

What this step does: Commits your code to Git and pushes it to GitHub so the automated CI/CD pipeline can start working.

Initial commit

Add all files to Git staging area

git add .

Create your first commit with a descriptive message

git commit -m "Initial commit: Complete DevOps setup with working CI/CD"
Connect to GitHub

⚠️ IMPORTANT: Before running these commands:

Go to GitHub.com and create a new repository called my-devops-project
DO NOT initialize it with README, .gitignore, or license (we already have these)
Copy the repository URL from GitHub
Replace YOUR_GITHUB_USERNAME below with your actual GitHub username

Set main as the default branch

git branch -M main

Connect to your GitHub repository (UPDATE THIS URL!)

git remote add origin https://github.com/YOUR_GITHUB_USERNAME/my-devops-project.git

Push your code to GitHub for the first time

git push -u origin main

What you'll see: Your code appears on GitHub, and the CI/CD pipeline starts running automatically.

Step 10: Kubernetes Deployment Configurations

What this step does: Creates Kubernetes configuration files that define how your application should run in staging and production environments.

Create directories

Create directories for Kubernetes configurations

mkdir -p k8s/staging k8s/production

Create Staging Deployment

Create k8s/staging/deployment.yml:

⚠️ IMPORTANT: Update YOUR_GITHUB_USERNAME in the image URL below!

Create Production Deployment

Create k8s/production/deployment.yml:

⚠️ IMPORTANT: Update YOUR_GITHUB_USERNAME in the image URL below

Step 11: Complete Deployment Workflow.

What this step does: Shows you how to use the complete CI/CD pipeline with proper branching strategy for staging and production deployments.

Branch-based Deployment Strategy
develop branch → Automatically deploys to staging environment
main branch → Automatically deploys to production environment
Pull requests → Run tests only (no deployment)
Deploy Changes
Deploy to staging:

Create and switch to develop branch

git checkout -b develop

Make your changes, then commit and push

git add .

git commit -m "Add new feature"

git push origin develop

What happens: GitHub Actions automatically runs tests and deploys to staging.

Deploy to production:

Switch to main branch

git checkout main

Merge changes from develop

git merge develop

Push to trigger production deployment

git push origin main

What happens: GitHub Actions runs full pipeline and deploys to production.

Top comments (0)