Kubernetes jenkins Installation (helm)

by Anish

Posted on Friday Jnauary 11, 2019

Referefce

Introduction

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

  • First define the PersistentVolume jenkins-pv where the jenkins data to be stored. The hostPath tells the jenkins directory is in /opt/jenkins location
[email protected]:# 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
  • Create PersistentVolume in kube cluster
[email protected]:# kubectl create -f  jenkins-hostpath.yaml 
persistentvolume/jenkins-pv created
  • Check the PersistentVolume jenkins-pv is available for use
[email protected]:# kubectl get pv 
NAME       CAPACITY   ACCESS MODES   RECLAIM POLICY   STATUS      CLAIM     STORAGECLASS   REASON    AGE
jenkins-pv   1Gi        RWO,ROX        Retain           Available                                      15s
  • Define PersistentVolumeClaim jenkins-pvc
[email protected]:/home/ansible# cat jenkins-pvc.yaml 
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
  name: jenkins-pvc
spec:
  storageClassName: ""
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 1Gi
  • create PersistentVolumeClaim jenkins-pvc in kube cluster
[email protected]:# kubectl create -f  jenkins-pvc.yaml 
persistentvolumeclaim/jenkins-pvc created
  • Check the PersistentVolumeClaim jenkins-pvc is bounded to jenkins-pv
[email protected]:/home/ansible# kubectl get pvc
NAME        STATUS    VOLUME     CAPACITY   ACCESS MODES   STORAGECLASS   AGE
jenkins-pvc   Bound     jenkins-pv   1Gi        RWO,ROX                       6s
  • jenkins Installation starts here, this is done through helm the kubernetes package manager,

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.

[email protected]:# 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
  • View the Jenkins conatiner pod is up and running
[email protected]:# 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

[email protected]:# kubectl get secret --namespace default jenkins -o jsonpath="{.data.jenkins-admin-password}" | base64 --decode; echo
EbbXwTgHrW
  • To get your admin user of jenkins run
[email protected]:# kubectl get secret --namespace default jenkins -o jsonpath="{.data.jenkins-admin-user}" | base64 --decode; echo
admin
  • To connect to your jenkins server from outside the K8s cluster
[email protected]:# kubectl get pods
NAME                       READY     STATUS    RESTARTS   AGE
jenkins-5564885478-mqtdp   0/1       Running   0          2m
[email protected]:# 
[email protected]:# kubectl port-forward jenkins-5564885478-mqtdp 9000:8080
Forwarding from 127.0.0.1:9000 -> 8080
Forwarding from [::1]:9000 -> 8080

Jenkins UI

All right you have successfully created Jenkins start scheduling the jobs


Related Jenkins


Video Demo


Thanku for reading !!! Give a Share for Support

Asking for donation sound bad to me, so i'm raising fund from by offering all my Nine book for just $9



python Cryptography Topics
Topics
For Coffee/ Beer/ Amazon Bill and further development of the project Support by Purchasing, The Modern Cryptography CookBook for Just $9 Coupon Price

Kubernetes for DevOps

Hello Dockerfile

Cryptography for Python Developers

Cryptography for JavaScript Developers

Go lang ryptography for Developers

Here