Kubernetes Manifests for Jenkins Deployment
Refer https://devopscube.com/setup-jenkins-on-kubernetes-cluster/ for step by step process to use these manifests.
The steps below (and associated files) are nearly identical to the steps as described by devops cube in the link above. However, I have followed these steps with Docker Desktop using the local Kubernetes cluster. I hope this encourages you to try this for yourself and learn more about Kubernetes, Jenkins, Docker, and DevOps!
-
Create a Kubernetes Namespace for Jenkins.
kubectl create namespace devops-tools
-
Create the service account (
serviceAccount.yaml
) usingkubectl
.kubectl apply -f serviceAccount.yaml
-
This YAML file does the following:
-
Creates a
jenkins-admin
ClusterRole. -
Creates a
jenkins-admin
ServiceAccount. -
Binds the ClusterRole to the ServiceAccount.
-
-
-
Create a persistent volume (
volume.yaml
) in one of your worker nodes (kubectl get nodes
) usingkubectl
.kubectl apply -f volume.yaml
-
This YAML does the following:
-
Creates a
local-storage
StorageClass. -
Creates a
jenkins-pv-volume
PersistentVolume. -
Claims 3Gi for
jenkins-pv-claim
PersistentVolumeClaim.
-
-
When a pod is deleted, it's data will persist in the node volume. However, when a node is deleted, all the data will be lost.
-
-
Create the deployment (
deployment.yaml
) usingkubectl
.kubectl apply -f deployment.yaml
-
This YAML does the following:
-
Creates a
jenkins
Deployment.-
Specifies a
securityContext
for the Jenkins pod to read and write to the PersistentVolume. -
Specifies a
readinessProbe
andlivenessProbe
. -
Specifies a local persistent volume that holds the Jenkins data path
/var/jenkins_home
.
-
-
-
Check the deployment status using:
kubectl get deployments -n devops-tools
-
Get deployment details using:
kubectl describe deployments --namespace=devops-tools
-
-
Create a service (
service.yaml
) usingkubectl
.kubectl apply -f service.yaml
-
This YAML does the following:
-
Creates a
jenkins-service
Service.-
Deploys in
devops-tools
Namespace. -
Expose
jenkins-server
to all Kubernetes nodes on port 32000. -
Maps port 32000 to port 8080.
-
-
-
Get the service details using:
kubectl get services -n devops-tools
-
Since this Jenkins server is deployed locally you can access the dashboard via
http://localhost:32000
. Follow the steps below to get the administrator password.-
Get the Pod name with:
kubectl get pods -n devops-tools
-
Use the Pod name obtained previously with:
kubectl logs jenkins-85fcfbb869-mcrdp -n devops-tools
-
The administrator password can be parsed and printed to the terminal by passing a command to the service with:
kubectl exec -it jenkins-85fcfbb869-mcrdp cat /var/jenkins_home/secrets/initialAdminPassword -n devops-tools
-
-
After entering the initial administrator password you can install the suggested plugins and create an admin user.
-
-