DEVOPS TASK 3
FLOW CHART OF THE TASK GIVEN:
TASK DESCRIPTION:
1.Create container image that’s has Jenkins installed using dockerfile Or You can use the Jenkins Server on RHEL 8/7
Dockerfile For Jenkins
To build this image use the command as shown below :
In the Jenkins Dockerfile I have installed mailx for sending the mail and copied my custom python script for detecting the extension of the file and then on the basis of that, it builds the image and pushes to the docker hub.
docker build -t <name/of/theimage> <path/to/Dockerfile>
2. When we launch this image, it should automatically starts Jenkins service in the container.
As you can see the Jenkins is running , and to access it from your docker host or outside you need to do PATing ie Port Address Translation.
docker run -dit -p 8080:8080 --name jenkins <jenkins/image/name>
3. Create a job chain of job1, job2, job3 and job4 using build pipeline plugin in Jenkins
Job1: Pull the Github repo automatically when some developers push repo to Github.
I have used git post-commit hook to automate the pull after commit done by the Developer.
The webhook will trigger the Jenkins job to build the image with the new code pushed by the Developer and for that i have used ngrok (for tunneling) so as to provide the (public)ip to which github can connect to.
The python script will build and push the image to the Docker Hub and BUILD_NUMBER will be used as the tag for the image.
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 )
I have created the html_deployment and php_deployment yaml file along with the pvc for the document root directory and the logs.
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: php-pvc
labels:
env: test
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 1Gi
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: php-log-pvc
labels:
env: test
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 1Gi
---
apiVersion: v1
kind: Service
metadata:
name: php-svc
labels:
name: php-svc
spec:
selector:
name: php-pod
ports:
- port: 80
targetPort: 80
nodePort: 32000
type: NodePort
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: php-app
labels:
name: php-app
env: test
spec:
replicas: 1
selector:
matchExpressions:
- { key: name, operator: In , values: [ php-pod ] }
template:
metadata:
name: php-pod
labels:
name: php-pod
spec:
containers:
- name: php-con
image: raghav1674/php-6:v1
volumeMounts:
- name: php-log
mountPath: /var/log/httpd/
- name: php-dir
mountPath: /var/www/php/
volumes:
- name: php-log
persistentVolumeClaim:
claimName: php-log-pvc
- name: php-dir
persistentVolumeClaim:
claimName: php-pvc
This is the php_site_deployment.yaml file
This job is for the HTML site which will be triggered by the previous job using the remote trigger.
This job is for the PHP site which will be triggered by the previous job using the remote trigger.
Job3 : Test your app if it is working or not.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
Lets see all these jobs in action:
Initially, no k8s resource is there.
After I pushed the image and the code file to the Github
Site is working fine.
Test success
Then I intentionally made some error in the PHP code to test my job is working properly or not.
Made Syntax Error in the PHP code.
The PHP site returns HTTP code 500 so the rollback is made and the developer is informed through mail.
Rollback done
Keep going Sir ji, You are a great learner and tutor too.... always thankful for ur support
Great work raghav sir