Web deployment by integrating Github, Jenkins and Docker on the top of Kubernetes

Task Description:-

2. When we launch this image, it should automatically starts Jenkins service in the container.

3. Create a job chain of job1, job2, job3 and job4 using build pipeline plugin in Jenkins

4. Job1 : Pull the Github repo automatically when some developers push repo to Github.

5. Job2 :

1. By looking at the code or program file, Jenkins should automatically start the respective language interpreter installed image container to deploy code on top of Kubernetes ( eg. If code is of PHP, then Jenkins should start the container that has PHP already installed )

2. Expose your pod so that testing team could perform the testing on the pod

3. Make the data to remain persistent ( If server collects some data like logs, other user information )

6. Job3 : Test your app if it is working or not.

7. Job4 : if app is not working , then send email to developer with error messages and redeploy the application after code is being edited by the developer

Step 1

In this step we need to create container image that’s has Jenkins installed using Dockerfile.

Dockerfile

RUN echo “name=Kubernetes” >> /etc/yum.repos.d/kubernetes.repo
RUN echo “baseurl=https://packages.cloud.google.com/yum/repos/kubernetes-el7-x86_64" >> /etc/yum.repos.d/kubernetes.repo
RUN echo “enabled=1” >> /etc/yum.repos.d/kubernetes.repo
RUN echo “gpgcheck=1” >> /etc/yum.repos.d/kubernetes.repo
RUN echo “repo_gpgcheck=1” >> /etc/yum.repos.d/kubernetes.repo
RUN echo “gpgkey=https://packages.cloud.google.com/yum/doc/yum-key.gpg https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg" >> /etc/yum.repos.d/kubernetes.repo

RUN sudo mkdir /.kube
COPY config /.kube
COPY ca.crt /
COPY client.key /
COPY client.crt /

RUN yum install -y kubectl
EXPOSE 8080
RUN echo -e “jenkins ALL=(ALL) NOPASSWD: ALL” >> /etc/sudoers
RUN mkdir /jenkins
USER jenkins
ENV USER jenkins
CMD [“java”, “-jar”, “/usr/lib/jenkins/jenkins.war”]

Configuration file for kubectl

Build the image using the command

docker build -t jenkins-kubernetes:v1

Step 2:-

In this step we have to launch a container from jenkins:v1 image and also it should automatically starts Jenkins service in the container.

Launch the container using the command

docker run -it privileged -v /:/host -p 8081:8080 — name jenkinsos jenkins:v1

We need to setup jenkins:

Step 3:-

Now we need to create a job chain of job1, job2, job3 and job4 using build pipeline plugin in Jenkins .

Let’s craete job1

Job1 : Pull the Github repo automatically when some developers push repo to Github.

Job2 :-

1. By looking at the code or program file, Jenkins should automatically start the respective language interpreter installed image container to deploy code on top of Kubernetes ( eg. If code is of PHP, then Jenkins should start the container that has PHP already installed )

2. Expose your pod so that testing team could perform the testing on the pod

3. Make the data to remain persistent ( If server collects some data like logs, other user information )

Job3 : Test your app if it is working or not.

Job4 : if app is not working , then send email to developer with error messages and redeploy the application after code is being edited by the developer

For sending the mail I am using a python code which is their in jenkins image. So if app will be not working then the code will get executed and it will notify the developer.

Here is the output of my build pipeline.

I'm passionate learner diving into the concepts of computing 💻