Website Deployment Using Kubernetes
What is GIT ?
Git is a distributed version-control system for tracking changes in source code during software development. It is designed for coordinating work among programmers, but it can be used to track changes in any set of files. Its goals include speed, data integrity, and support for distributed, non-linear workflows.
What is GITHUB ?
GitHub, Inc. is a United States-based global company that provides hosting for software development and version control using Git. It has been a subsidiary of Microsoft since 2018. It offers the distributed version control and source code management functionality of Git, plus its own features.
What is Jenkins ?
Jenkins is a free and open source automation server. It helps automate the parts of software development related to building, testing, and deploying, facilitating continuous integration and continuous delivery. It is a server-based system that runs in servlet containers such as Apache Tomcat.
What is Kubernetes ?
Kubernetes is an open-source container-orchestration system for automating computer application deployment, scaling, and management. It was originally designed by Google and is now maintained by the Cloud Native Computing Foundation.
Problem Statement :
Perform second task on top of Kubernetes where we use Kubernetes resources like Pods, ReplicaSet, Deployment, PVC and Service.
1. Create container image that’s has Jenkins installed using dockerfile Or You can use the Jenkins Server on RHEL 8/7.
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 :
A. 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 )
B. Expose your pod so that testing team could perform the testing on the pod
C. 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 and developer push the code in Github.
Solution :
First of all we have to create the docker image which jenkins as well as kubectl configured.
Dockerfile
Dockerfile for html code
JOB1:
This job is triggered when developer push some the repo/code from Git to Github then jenkins automatically download the code. In the job1 we use poll scm to see the code of Github if somethink is changed then it trigger the job1.
JOB2:
In this job we check the code file extension and according to the code type Jenkins should automatically start the respective language interpreter installed image container to deploy code on top of Kubernetes. Expose your pod so that testing team could perform the testing on the pod. Also make the data to remain persistent ( If server collects some data like apache logs).
Deployment for code by using yaml file:
apiVersion: apps/v1 kind: Deployment metadata: name: myweb-deploy labels: app: webapp spec: selector: matchLabels: app: webapp env: production template: metadata: name: myweb-pod labels: env: production app: webapp spec: containers: - name: myweb-con image: hemant123/myweb:v1 ports: - containerPort: 80 volumeMounts: - mountPath: "/usr/local/apache2/htdocs" name: jenkins-pvc volumes: - name: jenkins-pvc persistentVolumeClaim:
claimName: pv-claim-jenkins
Exposing the service by using yaml file:
apiVersion: v1 kind: Service metadata: name: myweblb spec: selector: app: webapp type: NodePort ports: - port: 80 targetPort: 80 nodePort: 31000
Create PVC for storing the logs of apache web server by yaml file:
apiVersion: v1 kind: PersistentVolumeClaim metadata: name: pv-claim-jenkins labels: app: webapp spec: accessModes: - ReadWriteOnce resources: requests: storage: 1Gi
JOB3:
In this job we check the status code of the code.Mainly it is the testing job.
JOB4:
If the code is not running properly then this job send the mail to the developer and remove all the pods , services as well as persistent volume.