kubernetes with jenkins for CI/CD

A development methodology of the developer integration to deliver automation builds

  • Seamless integration of development ,testing,staging and production
  • Encourages hands-free , automated deployments
  • with every commit results in a new build
  • Important aspect of DevOps

for kubernetes install click here

for docker details click here

Based on try fast and fail fast paradigm,

Containers and CI/CD

  • Container Images are smaller than VM templates
  • Containers are provisioned and unprovision much faster than Vms
  • Container Registry has become the centralized location to store artifiacts
  • Containers have put CI/CD on steroids

Kubernetes is an ideal candicate for integrating CI/CD pipelines

Kubernetes has quite power full API and CLI (kubectl).You can perform Blue/Green Developments or Canary Developments with in kubernetes

Kubectl set image deployment <deployment> <container>=<image>

Kubectl rollout history deployment <deployment>

Kubectl rollout undo deploy/<deployment>

Jenkins

Open source contiuous integration tools written in Java with plugins built for CI purpose.Integration with Source code control system, testing tools ,provisioning tool, configuration management and deployment targets.

Building CI CD Pipelines with Jenkins and Kubernetes

Pre Requistion

  1. Kubernetes cluster setup
  2. Jenkins
  3. Github for develop
  4. Dockerhub for public images push/pull

Docker images deployment in kubernetes

Login to kubernetes cluster

Check out the github source code

#Git clone https://github.com/msatyanp/simpledocker

Build and push docker images

#cd simpledocker

#docker build . –t simpledocker

#docker tag simpledocker msatya/simpledocker

login dockerhub credentical and push the images

#docker login -u msatya

Password:

Login Succeeded

#docker push msatya/simpledocker

Deploy docker images(pod) to kubernets

#kubectl create deployment simpledocker –image msatya/simpledocker

Expose(services) to get app external to the kubernetes cluster

#kubectl expose deployment/simpledocker –port=80 –name=simpledocker –type=LoadBalancer

Deploy from kubernetes dashboard

checking the service and pods

#browser the app from kubernetes port map with port as in local external ip has not been give if we deploy in cloud we can get the public ip .Now the application is deploy in the cluster with two pods running in different nodes

This is just a deployment of simple docker application in the kubernetes cluster.Now moving to CI/CD starting with Jenkins

Login to Jenkis server to connect our jenkins server and github to get trigger from github and thing changes will result that trigger(webhook ) to jenkins sever

Manage Jenkins->configure system

Configure Envornmental variables with dockerhub credentials

Jenkins changes private ip to public ips so that it can be access by github so that it can build the images for triggering

GitHun web hook configuration in Jenkins

Now configure the github repo with just created webhook url

Login to github creditails and move to ur project

https://github.com/msatyanp/simpledocker

Setting->Integration and services->aviable services (jenkins)

copy and paste the url webhook from Jenkins and test the system

Okay, the test payload is on its way. This show up when test service check is verified.

Now automate the system in jenkis to process what will do after that trigger made from github

Create a job in jenkis with free style project

Build trigger with GitHUB hook triffer for GITSCM polling

Connect kubernets to build image to docker and change the image in kubernete cluster

Build

cd /var/lib/jenkins/workspace/simpledocker

IMAGE_NAME=”msatya/simpledocker:${BUILD_NUMBER}”

docker build . -t $IMAGE_NAME

docker login -u msatya -p ${DOCKER_HUB}

docker push $IMAGE_NAME

Similary add this line for change the image of kubernete cluster

IMAGE_NAME=”msatya/simpledocker:${BUILD_NUMBER}”

kubectl set image deployment/simpledocker simpledocker=$IMAGE_NAME

Configure remote ssh for kubernets in Jenkins

Final output from Jenkins

success console build process

Now all the process for CI/CD completed so test and change the github which will trigger Jenkins server which will ultimate trigger docker push in dockerhub and change the image in kubernetes cluster.

Please find the complete vedio fro this in youtube url link.

https://youtu.be/N9ghvkYUitQ

Leave a Reply

Your email address will not be published.