Installation guides

Setting Up a CI/CD Pipeline with Jenkins, Docker, and Kubernetes on Debian

Introduction

Continuous Integration and Continuous Deployment (CI/CD) are essential for modern DevOps. This guide will help you set up a robust CI/CD pipeline using Jenkins, Docker, and Kubernetes on Debian.

Prerequisites

  1. Jenkins Installation: Ensure Jenkins is installed and running. Follow the Installing Jenkins on Debian guide.
  2. Docker Installation: Install Docker by following the steps from the Setting Up Docker and Docker Compose on Linux.

Step 1: Configure Jenkins for Docker

  1. Install Docker Plugin in Jenkins: Navigate to Manage Jenkins -> Manage Plugins -> Available and install the Docker plugin.
  2. Set Up Docker in Jenkins: Go to Manage Jenkins -> Configure System and add a new Docker Cloud with your Docker host details.

Step 2: Install and Configure Kubernetes

  1. Install Kubernetes: Use the following commands to install Kubernetes:
   sudo apt-get update
   sudo apt-get install -y kubelet kubeadm kubectl
   sudo kubeadm init
  1. Deploy a Kubernetes Cluster: Follow the steps in the Deploying a Kubernetes Cluster on Debian.

Step 3: Create a Jenkins Pipeline

  1. Create a New Pipeline: In Jenkins, create a new pipeline job and configure it to use your Git repository.
  2. Define Your Pipeline Script: Use a Jenkinsfile in your repository to define the pipeline stages:
   pipeline {
       agent any
       stages {
           stage('Build') {
               steps {
                   script {
                       docker.build('my-app')
                   }
               }
           }
           stage('Deploy to Kubernetes') {
               steps {
                   script {
                       sh 'kubectl apply -f k8s-deployment.yaml'
                   }
               }
           }
       }
   }

Step 4: Deploy to Kubernetes

  1. Create Kubernetes Deployment File: Define your deployment in a k8s-deployment.yaml file.
   apiVersion: apps/v1
   kind: Deployment
   metadata:
     name: my-app
   spec:
     replicas: 2
     selector:
       matchLabels:
         app: my-app
     template:
       metadata:
         labels:
           app: my-app
       spec:
         containers:
         - name: my-app
           image: my-app:latest
           ports:
           - containerPort: 80
  1. Deploy Using Jenkins: The Jenkins pipeline will handle deploying the Docker image to Kubernetes.

Conclusion

By following this guide, you can set up a CI/CD pipeline with Jenkins, Docker, and Kubernetes on Debian, streamlining your development and deployment processes. For more detailed steps and related configurations, refer to the linked articles on LinuxExpert.org.

Other Recent Posts