Dynamic Slave [JENKINS]    &           Zero-DownTime Error [k8s]

Dynamic Slave [JENKINS] & Zero-DownTime Error [k8s]

To create a Dynamic slave for Jenkins which will build the job and terminate itself after the job completion.

Objectives

1. Create container image that’s has Linux and other basic configuration required to run Slave for Jenkins. ( example here we require kubectl to be configured )


2. When we launch the job it should automatically starts job on slave based on the label provided for dynamic approach.


3. Create a job chain of job1 & job2 using build pipeline plugin in Jenkins 


4. Job1 : Pull the Github repo automatically when some developers push repo to Github and perform the following operations as:

 4.1 Create the new image dynamically for the application and copy the application code into that corresponding docker image

 4.2 Push that image to the docker hub (Public repository) 

 ( Github code contain the application code and Dockerfile to create a new image )


5. Job2 ( Should be run on the dynamic slave of Jenkins configured with Kubernetes kubectl command): Launch the application on the top of Kubernetes cluster performing following operations:

 5.1 If launching first time then create a deployment of the pod using the image created in the previous job. Else if deployment already exists then do rollout of the existing pod making zero downtime for the user.

 5.2  If Application created first time, then Expose the application. Else don’t expose it.

REQUIREMENTS

  1. Base OS- Windows10 (k8s & GIT installed)
  2. VM - RHEL8 (Jenkins & Docker installed)

For configuring git, go through my this article-

Creating container by configuring kubectl command in it, which will be treated as slave for jenkins.

FROM ubuntu:16.04


RUN apt-get update && apt-get install -y openssh-server
RUN mkdir -p /var/run/sshd
RUN echo 'root:cartoon' | chpasswd
RUN sed -i 's/PermitRootLogin prohibit-password/PermitRootLogin yes/' /etc/ssh/sshd_config


# SSH login fix. Otherwise user is kicked off after login
RUN sed 's@session\s*required\s*pam_loginuid.so@session optional pam_loginuid.so@g' -i /etc/pam.d/sshd


ENV NOTVISIBLE "in users profile"
RUN echo "export VISIBLE=now" >> /etc/profile




RUN  apt-get install openjdk-8-jre -y
RUN apt-get install curl -y
RUN mkdir /root/.kube




COPY ./.kube /root/.kube
COPY ./ca.crt /root/
COPY ./client.crt /root/
COPY ./client.key /root/




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 chmod +x ./kubectl
RUN mv ./kubectl /usr/bin/kubectl


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



Now create the container for webserver to display our webpage.

FROM centos
RUN yum install httpd -y
RUN yum install php -y

COPY *.php /var/www/html/

RUN echo "/usr/sbin/httpd" >> /root/.bashrc
RUN source /root/.bashrc 

EXPOSE 80
CMD /usr/sbin/httpd -DFOREGROUND

For remotely accessing docker edit the "ExecStart=" line inside the file "/usr/lib/systemd/system/docker.service" by adding "-H tcp://0.0.0.0:4243"

It will allow all the ip addressess which will come at this port.

No alt text provided for this image

After making any changes in the configuration file we have to restart the services by commands "systemctl daemon-reload" & "systemctl restart docker.service".

Now from remote system enter the following command-

"export DOCKER_HOST=192.168.43.138:4243"

Before configuring our jobs we have to configure our cloud-

No alt text provided for this image

Adding Docker templates

No alt text provided for this image

SSH_configuration

No alt text provided for this image

Now our cloud is set...........

Now we have to configure the jobs.

JOB_1:

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

NOTE- It will pull all the files from the github in the directory /root/jenslave and perform docker build and docker push operations, which will build and then push the container to the docker registery (docker hub)

OUTPUT_of_JOB_1-

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


JOB_2:

-provide the label which is given to the cloud which will only activate that node .

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

Conclusion-

  1. To achieve the power of dynamic node , which will complete the job asssigned by the user and terminate automatically after the job finished.
  2. ZERO-DownTime Error : due to the k8s deployment service , the rollout of pods doesn't give Downtime error.



SHRUTI GUPTA

SnowPro Certified| Talend Administration| DataBricks Fundamentals Certified| ETL|Linux|AWS|SQL|Deep Learning|Machine Learning

4 年

Great!

Abhishek Chouhan

DevOps Engineer at Toorak Capital

4 年

good job !

回复

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

Sanjay De的更多文章

  • AWS VPC Peering [Terraform]

    AWS VPC Peering [Terraform]

    What is VPC Peering ? A VPC peering connection is a networking connection between two VPCs that enables you to route…

    2 条评论
  • Dynamic CIDR & AZ [Terraform]

    Dynamic CIDR & AZ [Terraform]

    Classless Inter-Domain Routing (CIDR) - Classless Inter-Domain Routing (CIDR) blocks are for specifying a range to IP…

    4 条评论
  • Terraform state file on s3 backend

    Terraform state file on s3 backend

    Terraform state file - When you are building an infrastructure with terraform config, a state file gets generated…

    3 条评论
  • EC2 Dynamic Inventory [Ansible]

    EC2 Dynamic Inventory [Ansible]

    External or Dynamic Inventory - These inventories are the python scripts , to run these scripts a user have to provide…

  • VPC with NAT gateway

    VPC with NAT gateway

    NAT gateway- NAT Gateway is a highly available AWS managed service that makes it easy to connect to the Internet from…

    2 条评论
  • EC2-instance with EFS

    EC2-instance with EFS

    First lets discuss about EBS !!!! Amazon Elastic Block Store (EBS) Amazon Elastic Block Store (EBS) is an easy to use…

  • VPC with Internet Gateway

    VPC with Internet Gateway

    Amazon Virtual Private Cloud Amazon VPC lets you provision a logically isolated section of the AWS Cloud where you can…

    2 条评论
  • Amazon EKS

    Amazon EKS

    What is Amazon EKS ? Amazon EKS (Elastic Container Service for Kubernetes) is a managed Kubernetes service that allows…

  • Face_Mask_counter

    Face_Mask_counter

    About this Project - This project we created to achieve some helpful solution from this present pandemic situation , so…

    8 条评论
  • Configure Jenkins [Groovy]

    Configure Jenkins [Groovy]

    Jenkins DSL(Domain Specific Language)- Jenkins DSL job is a job which will create another job(s)/pipeline(s)/etc but…

社区洞察

其他会员也浏览了