TASK 3 DevOps

TASK 3 DevOps

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 start the 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 the 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 the 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 the app is not working, then send an email to the developer with error messages and redeploy the application after code is being edited by the developer.

Let's START

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 the concept of docker to create a 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 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.

The use of the above concept create Jenkins image…

No alt text provided for this image

FROM centos:-

Use this command or code to launch the 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 the 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 java software. Jenkins work on the java platform.

RUN yum install Jenkins -y:-

This line of code used to download the Jenkins software.

RUN echo -e “jenkins ALL=(ALL) NOPASSWD: ALL”>>/etc/sudoers:-

Give them all permission to sudo command.

CMD /etc/rc.d/init.d/jenkins start:-

This line of code used to start the Jenkins service.

EXPOSE 8080:-

This line used to expose Jenkins port number 8080 and run the Jenkins dashboard.

CMD java -jar usr/lib/jenkins/jenkins.war :-

Use this line of code to run the Jenkins.

Use above all the lines of code to create a docker container image.

Build container image…..

docker build -t jenkins:v1 .

use this line of code to create docker image.

No alt text provided for this 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

The 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 the Kubernetes concept to 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.

No alt text provided for this image

pod YAML file

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 maintained, 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.

No alt text provided for this image

PVC:-

Managing storage is a distinct problem from managing to 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.

No alt text provided for this image

Service:-

An abstract way to expose an application running on a set of Pods as a network service.

No alt text provided for this image

kustomization file:-

This file used to collect all file names in one file and run the all file and create all the pods in a single time.

No alt text provided for this image

#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

No alt text provided for this image

Use the IP address of pod or External IP created by service run the Jenkins page.

https://*.*.*.*:31938/

Use the URL to open the Jenkins web page.

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

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

No alt text provided for this image

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

No alt text provided for this image

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 a Kubernetes code to deploy the httpd server and mount the storage and create service.

Service code:-

No alt text provided for this image

Storage code:-

No alt text provided for this image

Deployments code:-

No alt text provided for this image

Use of Jenkins's second job run the code.

No alt text provided for this image

Show all services, deployments, and PVC.

No alt text provided for this image

use service to open the web page.

use URL https://***.***.**.**:32082/ open the web browser.

No alt text provided for this image

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

No alt text provided for this image

finale output:-

No alt text provided for this image

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

No alt text provided for this image


“Thanks, Vimal sir give the high level task to learn something new”








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

Siddhant Sharma的更多文章

社区洞察

其他会员也浏览了