From Setup to Deployment: Automated CI/CD Pipelines with Jenkins X and Kubernetes

Managing applications in a Kubernetes environment can be complex, especially when it comes to package management and CI/CD. In this blog post, we’ll explore two essential tools specifically designed for Kubernetes to address these challenges: Helm and Jenkins X.

Step 1: Helm – Kubernetes Package Management

Helm is a package manager specifically designed for Kubernetes and maintained by the Cloud Native Computing Foundation (CNCF) in collaboration with Microsoft, Google, Bitnami, and the Helm community. Much like Linux package managers like APT or YUM, Helm hides the complexity of application installations and their dependencies behind the scenes, making application sharing and management significantly easier. Helm uses “Charts” to package applications into predefined resources that can be managed with simple commands.

# Example Helm Chart for a simple application
apiVersion: v1
appVersion: “1.0”
description: A simple nginx application
name: my-nginx
version: 1.0.0

Step 2: Jenkins X – CI/CD for Kubernetes

Jenkins X is a CI/CD tool built specifically for Kubernetes, aimed at automating production pipelines and environments. Using Docker images, Helm charts, and the Jenkins Pipeline engine, Jenkins X can automatically manage releases and versions and promote applications across environments on GitHub.

pipeline {
agent any
stages {
stage(‘Build’) {
steps {
// Steps to build the application
}
}
stage(‘Test’) {
steps {
// Steps to test the application
}
}
stage(‘Deploy’) {
steps {
// Steps to deploy the application
}
}
}
}

Step 3: Practical Implementation

To demonstrate the functionality of Helm and Jenkins X, we’ll conduct a practical exercise. First, we’ll set up a local Kubernetes cluster environment with Minikube, then install Helm on the cluster and create a sample chart to deploy an application. Afterward, we’ll use Jenkins X to set up a CI/CD pipeline and automate our application.

# Sample commands to set up a Minikube environment and install Helm
minikube start
helm install myapp ./mychart

Step 4: Setting Up Jenkins X

First, install the jx CLI tool and configure Docker to use insecure registries for the local IP range. Then, create your Minikube Kubernetes cluster with CI/CD capabilities:

curl -L https://github.com/jenkins-x/jx/releases/download/v1.3.781/jx-linux-amd64.tar.gz | tar xzv
mv jx /usr/local/bin

echo ‘{ “insecure-registries” : [“0.0.0.0/0”] }’ | sudo tee /etc/docker/daemon.json
sudo systemctl restart docker

jx create cluster minikube –cpu=5 –default-admin-password=admin –vm-driver=none –memory=13314

Step 5: Creating a Test Application

Clone a sample application and import it into Jenkins X:

git clone https://github.com/do-community/rsvpapp.git
cd rsvpapp
rm -r .git/

jx import

Adjust the application configuration, push it to your GitHub repository, and monitor the pipeline status:

sed -i ‘s/servicePort: 5000/servicePort: 8080/’ values.yaml
git add .
git commit -m “Change servicePort to 8080”
git push origin main

jx get build logs

Open your application in the browser:

Step 6: Promoting the Application to Production

Use the `jx promote` command to move the application to the production environment:

jx promote rsvpapp –version=0.0.2 –env=production

Open the application in your browser to verify that it has been successfully promoted to production:

minikube service rsvpapp –namespace=jx-production

With these 6 steps, you have successfully set up a Jenkins X environment and moved a test application to production using a Jenkins X pipeline

Create a Free Account

Register now and get access to our Cloud Services.

Posts you might be interested in:

centron Managed Cloud Hosting in Deutschland

How to Calculate BLEU Score in Python?

Python
How to Calculate BLEU Score in Python? BLEU score in Python is a metric that measures the goodness of Machine Translation models. Though originally it was designed for only translation…