Monday, April 4, 2022

Module 31: CI/CD Pipeline using Jenkins to deploy on Kubernetes (Demo)

 In this tutorial we will see as how we can setup CI/CD Pipeline using Jenkins to deploy on Kubernetes

Step-1 — Install kubernetes cluster and in this tutorial , I have used LXC containers .

Kubernetes Cluster Ready

Step-2 — Install Jenkins

a) Install Java

sudo apt update
sudo apt install openjdk-8-jdk

b) Add Jenkins Repository & append package repository address to the server’s source.list

wget -q -O - https://pkg.jenkins.io/debian/jenkins.io.key | sudo apt-key add -sudo sh -c 'echo deb http://pkg.jenkins.io/debian-stable binary/ > /etc/apt/sources.list.d/jenkins.list'

c) Install Jenkins

sudo apt update
sudo apt install jenkins

d) check Jenkins status

e) Configure Jenkins with necessary credentials and login to Jenkins

f) Add Jenkins to the docker group “sudo usermod -aG docker jenkins”

g) Install the following plugins for Jenkins

Docker Pipeline
Kubernetes
Kubernetes Continuous Deploy

h) The final step is to use ngrok to expose localhost Jenkins URL as public URL.

Download ngrok and execute it as shown in the image, http://a0ecbd0426f6.ngrok.io/ is the new URL to login to Jenkins and accessible over the internet.

Step-3: Configure Jenkins

a) Select Demo1 as New Pipeline Project

b) Mention the GitHub link

c) Mention the build trigger

d) In the Pipeline mention the git links and the branch it has to operate upon

e) Configure docker hub credentials

f) Update Jenkinsfile -Its a declarative pipeline which is used as a code. It helps the pipeline code easier to read and write. This code is written in a Jenkinsfile.

In this implementation, the moment code is checked-in, Jenkins will have a notification through a webhook configured in Github. it follows the following stages below

i) Check out the source

ii)Build the new image

iii) Push it to the new repository

iv) Deploy the app on Kube

g) Have the configuration of mykubeconfig in Jenkins defined

h) Also have the connection between Jenkins and Kubernetes in place

i) Mention the Jenkins URL

j)Update the pod template.

k) Configure the webhook in Github

Step-4 — Develop application deployment manifest. In this tutorial, we are deploying a simple hellowhale app exposed as NodePort.

Step-5: Check-in the application manifest in GitHub and we can see the deployment starting in Jenkins

Step-6 Once the deployment is completed, we can see the following pods(3) are in place and exposed as NodePort(31113)

Access the deployment on NodePort.

Step-7: Update the deployment by changing the replica’s from 3 to 5 and we can see 5 pods are deployed on Kube.

No comments:

Post a Comment

Module 34: Understanding Terraform

  Terraform is a platform-agnostic tool that allows you to build, change, and version infrastructure securely and efficiently. Terraform is ...