DEV Community

Birks Sachdev
Birks Sachdev

Posted on

CI/CD with Kubernetes: Automating Deployments using Jenkins and Helm

Why CI/CD with Kubernetes Matters

In today's fast paced software engineering landscape, Continuous Integration/Continuous Deployment (CI/CD) has become essential to ensure faster delivery with minimal errors. Kubernetes, combined with tools like Jenkins and Helm, offers a powerful platform for automating deployments, scaling workloads, and delivering updates efficiently.

This article provides a step-by-step educational guide on setting up CI/CD pipelines with Jenkins and Helm for Kubernetes deployments. It will also walk through real-world scenarios to demonstrate the effectiveness of this setup.

Overview of Jenkins, Helm, and Kubernetes

Let's first define each of these frameworks below:

  • Jenkins: An open-source automation server widely used for building, testing, and deploying software.
  • Helm: A package manager for Kubernetes that makes it easy to define, install, and upgrade applications. Kubernetes: An orchestration platform for managing containerized applications at scale.

Together, these tools streamline the deployment process by:

  • Automating builds and tests with Jenkins
  • Packaging applications with Helm for seamless deployment on Kubernetes.
  • Ensuring scalability and high availability with Kubernetes clusters.

Architecture of CI/CD with Jenkins, Helm, and Kubernetes

A typical CI/CD pipeline using Jenkins and Helm follows these steps:

  1. Code Commit: A developer pushes code to the repository (e.g., GitHub).
  2. Build and Test: Jenkins automatically builds the code and runs tests.
  3. Docker Image Creation: Jenkins creates a Docker image of the application.
  4. Helm Chart Deployment: Jenkins uses Helm to deploy the application to Kubernetes.
  5. Verification: Kubernetes ensures the application is deployed and running as expected.

3. Real-World Example: Deploying a Node.js App Using Jenkins and Helm

This example will walk you through how to set up a CI/CD pipeline that builds and deploys a Node.js application to Kubernetes.

Step 1: Prerequisites

  • A Kubernetes cluster (e.g., Minikube or EKS).
  • Jenkins installed on the Kubernetes cluster.
  • Helm installed.
  • Docker Hub or any container registry for storing the application images.
  • A Helm chart configured for the Node.js app.

Step 2: Create a Helm Chart for Your Application

Use the following command to create a Helm chart:

helm create nodejs-app
Enter fullscreen mode Exit fullscreen mode

Modify the values.yaml to define the image and resource configurations:

image:
  repository: your-dockerhub-username/nodejs-app
  tag: "latest"

resources:
  limits:
    cpu: 500m
    memory: 512Mi
  requests:
    cpu: 250m
    memory: 256Mi
Enter fullscreen mode Exit fullscreen mode

Step 3: Configure Jenkins Pipeline
In Jenkins, create a pipeline project and add the following pipeline script in the configuration:

pipeline {
    agent any
    environment {
        DOCKER_IMAGE = 'your-dockerhub-username/nodejs-app'
    }
    stages {
        stage('Clone Repository') {
            steps {
                git 'https://github.com/your-username/nodejs-app.git'
            }
        }
        stage('Build Docker Image') {
            steps {
                sh 'docker build -t $DOCKER_IMAGE .'
            }
        }
        stage('Push Docker Image') {
            steps {
                withCredentials([string(credentialsId: 'docker-hub-password', variable: 'DOCKER_PASS')]) {
                    sh """
                    echo "$DOCKER_PASS" | docker login -u your-dockerhub-username --password-stdin
                    docker push $DOCKER_IMAGE
                    """
                }
            }
        }
        stage('Deploy to Kubernetes') {
            steps {
                sh 'helm upgrade --install nodejs-app ./nodejs-app --namespace default'
            }
        }
    }
}
Enter fullscreen mode Exit fullscreen mode

Step 4: Set Up Jenkins on Kubernetes

Deploy Jenkins using the official Helm chart:

helm repo add jenkins https://charts.jenkins.io
helm repo update
helm install jenkins jenkins/jenkins --namespace jenkins --create-namespace
Enter fullscreen mode Exit fullscreen mode

Access Jenkins and configure the necessary plugins (e.g., Docker, GitHub Integration).

Step 5: Verify Deployment on Kubernetes
After the Jenkins pipeline completes, check if the Node.js application is running:

kubectl get pods
kubectl get services
Enter fullscreen mode Exit fullscreen mode

You should see your Node.js application running as a pod, exposed via a Kubernetes service.

Advanced Configuration: Blue-Green Deployment with Helm

Blue-green deployment minimizes downtime by having two identical environments—one active (blue) and one idle (green). Here’s how to implement it using Helm:

Deploy the initial version as blue:

helm upgrade --install nodejs-app-blue ./nodejs-app --namespace default
Enter fullscreen mode Exit fullscreen mode

Deploy the green environment with the updated version:

helm upgrade --install nodejs-app-green ./nodejs-app --namespace default
Enter fullscreen mode Exit fullscreen mode

Switch traffic to the green environment:

kubectl patch service nodejs-app-blue -p '{"spec":{"selector":{"app":"nodejs-app-green"}}}'
Enter fullscreen mode Exit fullscreen mode

This ensures the new version is ready before switching traffic, with no downtime for users.

Benefits of using Kubernetes, Jenkins, and Helm for CI/CD

  • Faster Deployments: Automate every step from code push to deployment.
  • Scalability: Kubernetes ensures apps scale seamlessly under load.
  • Rollback Support: Helm allows easy rollback to previous versions.
  • Zero Downtime Deployments: With strategies like Blue-Green deployment and Canary releases.

Real-World Example: Netflix

Netflix, known for its microservice architecture, uses Kubernetes and Jenkins to manage thousands of deployments daily. With Helm, they achieve consistent and automated deployments across their entire platform, ensuring quick rollback if issues arise. This pipeline has helped Netflix deliver new features faster with near-zero downtime.

Summary

Integrating Jenkins and Helm with Kubernetes gives you a powerful CI/CD pipeline capable of automating builds and deployments. Whether you’re deploying simple applications or complex microservices, this setup ensures speed, scalability, and reliability. With real-world techniques like Blue-Green deployments, you can reduce downtime and confidently release new features.

Top comments (0)