jenkins-kubernetes-pipeline
Jenkins Kubernetes Pipeline for Containerized PHP Web Application - A Step-by-Step Guide 📚
-
In this blog post, we’ll walk through the process of setting up a Jenkins pipeline to containerize a PHP web application and deploy it to Kubernetes Minikube. Before we dive into the details, make sure you have the following prerequisites in place:
-
for creating all the steps follow this repos Access the GitHub repo here
Prerequisites 📜
1- Installed Jenkins on the local system or any VM. how to install Jenkins
[for add credentials] (https://yahyagulshan.com/posts/how-to-add-credentials-on-jenkins/)
2- Installed Kubernetes minikube. how to install
3- Installed Docker.how to install
4- Make sure Jenkins has a connection with Kubernetes how to make connection
5- DockerHub Repository:
- Have a DockerHub repository ready to store your Docker images.
How to configure Jenkins Project ☰
-
after installing Jenkins open it on Browser.
-
click on manage jennkins
-
click on Credentials
-
then add credentials for Dockerhub and Kubernetes and GitHub. (for GitHub password should be “token”)
-
After creating the credentials create Pipeline for that click on newItem
- then give suitable name click on “pipeline” and press “ok”
-
new page open open click on Github project and give the link of github repo
-
In the last “Pipeline” section in
defination
select “pipeline script fo SCM”. In repository again give the github repo link. for credentials select “none”. in “branches to build” give your branch name and then save. -
now press “build now”
- pipeline should be running
- this repo we have
Dockerfile
&
index.php
file.
these files are for creating php web page.
Important Note (To run the auto-trigger pipeline our Jenkins should be on a Public host like “EC2” )
- For auto trigger we need to create a webhook on the GitHub repo because the webhook needs to communicate over the public IP.
Steps for autotrigger pipeline 👣
- First we need to create the webhook on our GitHub repo for this go to setting > webhook > Add webhook
- here give the info Jenkins “Ec2” publicIP with “8080” Port and click add webhook.
-
Now go to Jenkins open the Project click on “configure”
-
configuration page opens here find “Build Triggers” and click on “GitHub hook trigger for GITScm polling”
- Now when we commit new changes on Github with the Specified Branch our Jenkins pipeline should trigger automatically.
Jenkinsfile Overview 📋
The Jenkinsfile orchestrates the pipeline:
- 1- Builds the Docker image.
- 2- Pushes the image to the DockerHub repository.
- 3- Deploys the image to Kubernetes Minikube.
Note: Customize the Jenkinsfile
- Change the DockerHub credentials in line #16.
- Update the username in line #17.
- Change the Kubernetes credentials in line #28.
Kubernetes Manifest File (deployment.yaml)
The deployment.yaml
file creates a Pod and Service in Kubernetes Minikube.
-
account.yaml
File Details: -
This file is used for creating a service account with the secret for the Kubernetes-plugin in Minikube.
-
Feel free to adapt these files and configurations based on your project requirements. Happy coding! 🚀