Task_3|DevOps Assembly Line
In this task we learn lots of Kubernetes,apply the Kubernetes concept solve task?
Description of task……..
Use Kubernetes resources like Pods, ReplicaSet, Deployment, PVC and Service.
step1.Create container image that’s has Jenkins installed using dockerfile Or You can use the Jenkins Server on RHEL 8/7
step2. When we launch this image, it should automatically starts Jenkins service in the container.
step3. Create a job chain of job1, job2, job3 and job4 using build pipeline plugin in Jenkins
step4. Job1 : Pull the Github repo automatically when some developers push repo to Github.
step5. create Job2
step5.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 )
step5.2. Expose your pod so that testing team could perform the testing on the pod
step5.3. Make the data to remain persistent ( If server collects some data like logs, other user information )
step6. Job3 : Test your app if it is working or not.
step7. 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.
Prerequisite or Knowledge
->Minikube install in the system, because Kubernetes work on behind the minikube.
step1.Create container image that’s has Jenkins installed using dockerfile Or You can use the Jenkins Server on RHEL 8/7
In this step we use concept of docker to create container image.
Dockerfile:-
Docker can build images automatically by reading the instructions from a Dockerfile
. A Dockerfile
is a text document that contains all the commands a user could call on the command line to assemble an image. Using docker build
users can create an automated build that executes several command-line instructions in succession.
FROM:-
The FROM
instruction initializes a new build stage and sets the Base Image for subsequent instructions. As such, a valid Dockerfile
must start with a FROM
instruction. The image can be any valid image – it is especially easy to start by pulling an image from the Public Repositories.
RUN:-
The RUN
instruction will execute any commands in a new layer on top of the current image and commit the results. The resulting committed image will be used for the next step in the Dockerfile
.
CMD:-
The CMD
instruction has three forms:
CMD ["executable","param1","param2"]
(exec form, this is the preferred form)CMD ["param1","param2"]
(as default parameters to ENTRYPOINT)CMD command param1 param2
(shell form)
The main purpose of a CMD
is to provide defaults for an executing container.
Use of above concept create Jenkins image…
FROM centos :-
Use this command or code to launch prebuild operating system Centos.
RUN yum install sudo -y :-
Use this code to give the user root permission.
RUN yum install curl -y :-
Curl is a tool to transfer data from or to a server, using one of the supported protocols (FTP, FTPS, HTTP). The command is designed to work without user interaction.
RUN yum install wget -y :-
Wget is a free software package for retrieving files using HTTP, HTTPS, FTP and FTPS the most widely-used Internet protocols.
RUN wget -O /etc/yum.repos.d/jenkins.repo https://pkg.jenkins.io/redhat-stable/jenkins.repo
RUN rpm --import https://pkg.jenkins.io/redhat-stable/jenkins.io.key
Use above code to install the repository or download the Jenkins or java.
RUN yum install java-11-openjdk.x86_64 -y :-
Use this code to install the java software. Jenkins work on the java platform.
RUN yum install Jenkins -y :-
This line of code use to download the Jenkins software.
RUN echo -e “jenkins ALL=(ALL) NOPASSWD:ALL”>>/etc/sudoers :-
Give the all permission to sudo command.
CMD /etc/rc.d/init.d/jenkins start :-
This line of code use to start the Jenkins service.
EXPOSE 8080 :-
This line use to expose the Jenkins port number 8080 and run Jenkins dashboard.
CMD java -jar usr/lib/jenkins/jenkins.war :-
Use this line of code run the Jenkins.
Use above all the line of code create docker container image.
Build container image…..
docker build -t jenkins:v1 .
use this line of code create docker image.
Use Kubernetes concept launch the POD.
Use yml programming language concept launch the pods.
YAML:-
YAML Ain’t Markup Language is a data serialization language that matches user’s expectations about data. It designed to be human friendly and works perfectly with other programming languages. It is useful to manage data and includes Unicode printable characters. This chapter will give you an introduction to YAML and gives you an idea about its features.
Rules for Creating YAML file
When you are creating a file in YAML, you should remember the following basic rules −
- YAML is case sensitive.
- The files should have .yaml as the extension.
- YAML does not allow the use of tabs while creating YAML files; spaces are allowed instead.
Basic Components of YAML File
The basic components of YAML are described below −
Conventional Block Format
This block format uses hyphen+space to begin a new item in a specified list. Observe the example shown below −
--- # Favorite movies
- Casablanca
- North by Northwest
- The Man Who Wasn't There
Inline Format
Inline format is delimited with comma and space and the items are enclosed in JSON. Observe the example shown below −
--- # Shopping list
[milk, groceries, eggs, juice, fruits]
Folded Text
Folded text converts newlines to spaces and removes the leading whitespace. Observe the example shown below −
- {name: John Smith, age: 33}
- name: Mary Smith
age: 27
The structure which follows all the basic conventions of YAML is shown below −
men: [John Smith, Bill Jones]
women:
- Mary Smith
- Susan Williams
Use Kubernetes concept create pods and replica set.
Pod:-
A Pod (as in a pod of whales or pea pod) is a group of one or more containers (such as Docker containers), with shared storage/network, and a specification for how to run the containers.
Replica-set:-
A Replica Set’s purpose is to maintain a stable set of replica Pods running at any given time. A Replica Set is defined with fields, including a selector that specifies how to identify Pods it can acquire, a number of replicas indicating how many Pods it should be maintaining, and a pod template specifying the data of new Pods it should create to meet the number of replicas criteria. A Replica Set then fulfills its purpose by creating and deleting Pods as needed to reach the desired number.
PVC:-
Managing storage is a distinct problem from managing compute instances.
PV:-
A PersistentVolume (PV) is a piece of storage in the cluster that has been provisioned by an administrator or dynamically provisioned using Storage Classes. PVs are volume plugins like Volumes, but have a lifecycle independent of any individual Pod that uses the PV.
PVC:-
A PersistentVolumeClaim (PVC) is a request for storage by a user. It is similar to a Pod. Pods consume node resources and PVCs consume PV resources. Pods can request specific levels of resources (CPU and Memory).
Note:- Use PVC dynamic type pvc create by default PV.
Service:-
An abstract way to expose an application running on a set of Pods as a network service.
Kustomization file:-
This file use to collect the all file name in one file and run the all file and create all the pods in single time.
#kubectl create -k .
run above command create all the pods and services.
Run the kustomization file and show the all the service,pods,pvc use single command
Kubcectl get all
Use IP address of pod or External IP created by service run the Jenkins page.
http://*.*.*.*:31938/
Use URL to open the Jenkins web page.
step3. Create a job chain of job1, job2, job3 and job4 using build pipeline plugin in Jenkins
Goto Jenkins dashboard click Manage Jenkins->Manage Plugins ->Available ->Build Pipeline Plugin
step4. Job1 : Pull the GitHub repo automatically when some developers push repo to GitHub.
Write a code upload on the github.Fallow below link learn about How to integrate with Git and GitHub?.
https://medium.com/@neeteeshyadav98/integration-with-git-github-cec65fb4ec3f
step5. Job2 : By looking at the code or program file, Jenkins should automatically start the respective language interpreter install image container to deploy code ( eg. If code is of PHP, then Jenkins should start the container that has PHP already installed ).
Create Kubernetes code to deploy the httpd server and mount the storage and create service.
Service code:-
Storage code:-
Deployments code:-
Use of Jenkins second job run the code.
Show the all services,deployments and PVC.
use service to open the web page.
use url http://***.***.**.**:32082/ open the web browser.
step6. Job3 : Test your app if it is working or not.
finale output:-
step7. 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.
Conclusion:-
In this artical we learn how to install jenkins use of Kubernetes and Kubernetes integrate with the Jenkins and deploy the webpage.
“Thanks Vimal sir give high level task to learn something new”.