by Anish
Posted on Friday Jnauary 11, 2019
This sample chapter extracted from the book, Kubernetes for DevOps .
Get this book on Just $9 or Ask Author for Discount
In this article we will learn how to to setup jenkins in kubernetes cluster using helm
Helm: Helm is a tool for managing Kubernetes charts. Charts are packages of pre-configured Kubernetes resources.
Let’s Begin deploying Jenkins using helm in kubernetes
root@kube-master:# cat jenkins-hostpath.yaml
apiVersion: v1
kind: PersistentVolume
metadata:
name: jenkins-pv
spec:
capacity:
storage: 2Gi
accessModes:
- ReadWriteOnce
- ReadOnlyMany
persistentVolumeReclaimPolicy: Retain
hostPath:
path: /opt/jenkins
root@kube-master:# kubectl create -f jenkins-hostpath.yaml
persistentvolume/jenkins-pv created
root@kube-master:# kubectl get pv
NAME CAPACITY ACCESS MODES RECLAIM POLICY STATUS CLAIM STORAGECLASS REASON AGE
jenkins-pv 1Gi RWO,ROX Retain Available 15s
root@kube-master:/home/ansible# cat jenkins-pvc.yaml
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: jenkins-pvc
spec:
storageClassName: ""
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 1Gi
root@kube-master:# kubectl create -f jenkins-pvc.yaml
persistentvolumeclaim/jenkins-pvc created
root@kube-master:/home/ansible# kubectl get pvc
NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE
jenkins-pvc Bound jenkins-pv 1Gi RWO,ROX 6s
helm install --name jenkins --set
Persistence.ExistingClaim=jenkins-pvc stable/jenkins
while setting up jenkins cluster the persistence.existingClaim=jenkins-pvc
is set which we have created earlier.
root@kube-master:# helm install --name jenkins --set Persistence.ExistingClaim=jenkins-pvc stable/jenkins
NAME: jenkins
LAST DEPLOYED: Fri Jan 11 10:07:03 2019
NAMESPACE: default
STATUS: DEPLOYED
RESOURCES:
==> v1/Pod(related)
NAME READY STATUS RESTARTS AGE
jenkins-5564885478-d9shr 0/1 Init:0/1 0 1s
==> v1/Secret
NAME TYPE DATA AGE
jenkins Opaque 2 2s
==> v1/ConfigMap
NAME DATA AGE
jenkins 5 2s
jenkins-tests 1 2s
==> v1/Service
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
jenkins-agent ClusterIP 10.105.120.164 <none> 50000/TCP 2s
jenkins LoadBalancer 10.106.23.98 <pending> 8080:30726/TCP 2s
==> v1/Deployment
NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE
jenkins 1 1 1 0 2s
NOTES:
1. Get your 'admin' user password by running:
printf $(kubectl get secret --namespace default jenkins -o jsonpath="{.data.jenkins-admin-password}" | base64 --decode);echo
2. Get the Jenkins URL to visit by running these commands in the same shell:
NOTE: It may take a few minutes for the LoadBalancer IP to be available.
You can watch the status of by running 'kubectl get svc --namespace default -w jenkins'
export SERVICE_IP=$(kubectl get svc --namespace default jenkins --template "{{ range (index .status.loadBalancer.ingress 0) }}{{ . }}{{ end }}")
echo http://$SERVICE_IP:8080/login
3. Login with the password from step 1 and the username: admin
For more information on running Jenkins on Kubernetes, visit:
https://cloud.google.com/solutions/jenkins-on-container-engine
root@kube-master:# kubectl get pods --watch
NAME READY STATUS RESTARTS AGE
jenkins-5564885478-d9shr 0/1 Init:0/1 0 1m
jenkins-5564885478-d9shr 0/1 PodInitializing 0 2m
jenkins-5564885478-d9shr 0/1 Running 0 2m
Once the jenkins POD is up and running , your jenkins is ready to use
To get your admin password of jenkins run
root@kube-master:# kubectl get secret --namespace default jenkins -o jsonpath="{.data.jenkins-admin-password}" | base64 --decode; echo
EbbXwTgHrW
root@kube-master:# kubectl get secret --namespace default jenkins -o jsonpath="{.data.jenkins-admin-user}" | base64 --decode; echo
admin
root@kube-master:# kubectl get pods
NAME READY STATUS RESTARTS AGE
jenkins-5564885478-mqtdp 0/1 Running 0 2m
root@kube-master:#
root@kube-master:# kubectl port-forward jenkins-5564885478-mqtdp 9000:8080
Forwarding from 127.0.0.1:9000 -> 8080
Forwarding from [::1]:9000 -> 8080
All right you have successfully created Jenkins start scheduling the jobs
Related Jenkins
Thanku for reading !!! Give a Share for Support
Instead of directly asking for donations, I'm thrilled to offer you all nine of my books for just $9 on leanpub By grabbing this bundle you not only help cover my coffee, beer, and Amazon bills but also play a crucial role in advancing and refining this project. Your contribution is indispensable, and I'm genuinely grateful for your involvement in this journey!
Any private key value that you enter or we generate is not stored on this site, this tool is provided via an HTTPS URL to ensure that private keys cannot be stolen, for extra security run this software on your network, no cloud dependency