CI/CD: Jenkins,Kubernetes With DockerHub

CI/CD: Jenkins,Kubernetes With DockerHub


As always I'll explain some basic terminologies that we need to know before getting started and jumping onto the project..... so that if anybody who is not comfortable with these devops stuff will learn something from the project also be able to link on to the project.

What is Docker and DockerHub ?

- Docker is one of the most demanding technology that is growing very much fastly in terms of improvement in the form of different technogies like PodMan , CRI- O

- All these tools uses containerization technology and thus each of them is very effective in launching a operating system inside any system in less than 10 seconds which was som interesting to know

- Now since every operating system needs some images to get booted , so in docker , we normally store all of our docker images into a single registry like SCM and this registry is none other than DockerHub

What is Kubernetes? 

- Kubernetes is one of the great DevOps tools that we use for launching containers, monitoring them , keeping their storage permanent and all about containerization technology

- It's unique quality to intricate with different types of technology i.e Docker, Podman and CRI-O .So, one doesn't have to learn different technologies.

- Only getting comfortable with Kubernetes will work.

What is Jenkins ?

- It is the main program using which we are able to achieve automation in this agile world and can preform various tasks involving commands to get onto work in the form of chain of jobs that we also call mainly by pipelines

Why this task ? 

- To help others and those who are in need of cool stuffs like this and don't know much about this technology to get them a flavour of what's the great here in this tool 

What's the motto ?

The situation is like that suppose a developer pushes some code to our company's SCM and we as operator guys wants to update the code onto our company's site our maybe we will want code to be deployed onto testing environment so that QA team can take actions on it.

Here we want to automate things by making use of docker images such that we will copy the code to our docker container, make an image out of it and then finally upload it onto our production environment.

Here are some prerequisites that one should have inorder to get onto the project :

  • Basics of Kubernetes
  • Minikube setup already installed and configured with kubectl 
  • A Basic knowledge on linux interface like Redhat

So lets get started without wasting further more time.............

Here is the Dockerfile for the image that we have to use as our dynamic jenkins slave

#!/bin/bash
FROM centos:latest
#Basic downloading commands
RUN dnf install wget -y
#Root priviledge giving command
RUN dnf install sudo -y
RUN dnf install java-11-openjdk.x86_64 -y
RUN dnf install net-tools -y
RUN dnf install git -y
#ssh for key injection
RUN dnf install openssh-server -y
#generating ssh key for starting the sshd environment
RUN ssh-keygen -A
#config file for kubectl
COPY config  /root/.kube/config
COPY ca.crt /root/ca.crt
COPY client.crt /root/client.crt
COPY client.key /root/client.key
RUN curl -LO https://storage.googleapis.com/kubernetes-release/release/`curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt`/bin/linux/amd64/kubectl
RUN sudo mv ./kubectl /usr/bin/kubectl
RUN sudo chmod +x /usr/bin/kubectl
EXPOSE 8080
#starting sshd environment for ssh
RUN bash

CMD [ "/usr/sbin/sshd", "-D" ]

Here I have used the credentials for my minikube setup and created an image named ssjnm/ssjnmkube and that thing depends on your keys ,certificates and client certificates

Important thing to notice here is that I have also installed and started SSH daemon (environment) so that I can use it to login to the new OS created and thereby we have to inject some SSH keys for getting connectivity

Use the following command to start building the docker image

docker build -t <your image name>:<version> <PATH>
No alt text provided for this image

So here we have Image ready and If we will want the image to run dynamically then there''s one more thing we have to do

No alt text provided for this image

We have to host our docker server running inside our linux VM so that external docker clients can also get connected to it which is a need for dynamic slave setup

But there's a special port 4243 only on which we will be able to get request

Of course this can be changed by using docker main configuration file.

No alt text provided for this image

Now just reload the environment by using the following commands:

systemctl daemon-reload
systemctl restart docker
No alt text provided for this image

Now we can see in the status of docker server that external requests are allowed.

No alt text provided for this image


So let's use my ssjnmjenkins image to launch a jenkins on Docker onto which we will we working and creating the CI/CD setup

So, first unlock Jenkins and Try to install the basic plugins because it covers almost every plugin that we will be needing in our current setup


No alt text provided for this image
No alt text provided for this image

Here, we have to download one more plugin for docker cloud provisioning

No alt text provided for this image

Now that we have downloaded the plugins, its time to setup the Redhat node and Cloud provisioner. If you are unfamiliar with the setup for static slave agents then have a look onto my previous article for task 3

No alt text provided for this image

Here , we have used SSH method to log onto our Redhat slave agent and I have used a label docker to represent that slave

So, lets configure cloud for getting started.

No alt text provided for this image

Here make sure that you have enabled the cloud and exported DOCKER_HOST to set the IP address of host internally

This was about configuring docker for clod provisioning but if we want a specific image to work as a slave then we have one option for templated using which we will specify to use ssjnm/ssjnmkube image for kubectl command to run

No alt text provided for this image

And here at connectivity use option for SSH key injection to get access to OS launched byy images

So, all the work for configuration is done and now its time for starting our jobs

Job1 : To copy the developer codes inside our environment images

No alt text provided for this image
No alt text provided for this image
No alt text provided for this image

Here I have used the docker plugin to automatically build the code by making use of Dockerfile and the codes in the same directory. Just give your credentials to the plugin so that it can upload the image to DockerHub

No alt text provided for this image

Job2: To launch or to update the previously running docker images servers onto our Kubernetes Clusters. Here we will use the dynamic slave node for kubectl

No alt text provided for this image
No alt text provided for this image

Here I have written a code expressing my needs for current setup or the setup-that was already running ,we just have to update our deployment or create new ones my making use of these.

No alt text provided for this image

Before getting to job3 , lets us configure our smtp mail server so that if a build will be unstable then a email will be send to us to get notified

No alt text provided for this image

Job3: To check the status of site whether its working or not

No alt text provided for this image
No alt text provided for this image

Everything's ready now , just start a build pipeline for all of our jobs and if you don't know that, then refer my previous article.

So let me create hooks for post commit program and I'll be using triggers by links inorder to start our build so that whenever the code is changed by developer, the new code will be deployed onto our environment.

No alt text provided for this image

Here I have edited the file index.html and then finally commited the changes as a developer

No alt text provided for this image
No alt text provided for this image

Here we can see that our Pipeline is started Once we have triggered our change in code

No alt text provided for this image
No alt text provided for this image

Yeeeah! The build is Successful and thus achieved what I wanted

No alt text provided for this image

For checking manually we can use the console output and take a look onto the site.

No alt text provided for this image

See here , exactly same code as that of the changed code.

No alt text provided for this image

This was the output I was getting during build failure .

No alt text provided for this image

But when my Build has returned to stable , I have received this email from Jenkins :)

No alt text provided for this image

This way the project is completed and that's all for now.............


要查看或添加评论,请登录

Nishant Singh的更多文章

  • Configuring Hive with HDFS & MapReduce Cluster backend

    Configuring Hive with HDFS & MapReduce Cluster backend

    Hello to the reader , hope you are all doing great. Now that you are here, Lets just start it already ??.

  • Why handlers are used in Ansible?

    Why handlers are used in Ansible?

    Handlers are the tasks which gets triggered when some changes are made to a particular task. This solves a very…

  • Setting up AWS CDN with AWS CLI

    Setting up AWS CDN with AWS CLI

    Content Delivery Networks is one of the best utilization of a company's own private network across the globe. A company…

  • Play with IPs , IPv4 in particular

    Play with IPs , IPv4 in particular

    This article is an interesting one at least for me, Although it takes time to understand networking concepts since I…

  • A Session with two experts

    A Session with two experts

    The session was started by Mr. Arun Eapen with the explanation of what automation is and specially why we need it,So…

  • Configuring HAProxy-LB with Ansible

    Configuring HAProxy-LB with Ansible

    As I always say its always better to have a look onto the basic technical terms to get started, and so lets see what we…

  • Configuring Hadoop(NN/DN) via Ansible

    Configuring Hadoop(NN/DN) via Ansible

    Before getting hands on into any practical implementation its always good to know the terminologies..

  • Getting started with AWS CLI....

    Getting started with AWS CLI....

    This is an small article on explanation of getting started with Command line interface with some easy and helpful…

  • Ubisoft got enhanced with AWS

    Ubisoft got enhanced with AWS

    Normally Every Gaming company demands some big infrastructure with good quality CPU, RAM for the game development and…

  • Hybrid Cloud Setup: K8s and RDS

    Hybrid Cloud Setup: K8s and RDS

    A great setup to learn the intrication of the two different cloud platforms working together with the help of terraform…

社区洞察

其他会员也浏览了