DevTech101

DevTech101
1 Star2 Stars3 Stars4 Stars5 Stars (1 votes, average: 1.00 out of 5)
Loading...

Installing Jenkins On your Kubernets Cluster By Using Helm Charts

I was in a need for a quick CI/CD application, I decided to try and take Jenkins (master) for a ride.

Below I will show you, how you can quickly install Jenkins by using the Jenkins Helm Chart.
Note: I am also using MetalLB (which I am a big fan of) to exposed a public IP address, more on how to configure MetalLB can be seen here and the MetallB home page is here.

The below example configuration uses the following versions:

  1. CoreOS: 2163.2.1
  2. Kubernetes client(kubectl):v1.13.1
  3. Kubernetes:v1.13.2
  4. Helm:v2.12.3
  5. Jenkins Helm chart:1.1.23
  6. Metal LB(optional):0.8.4

First lets get a starting/default Jenkins configuration.

helm inspect values stable/jenkins > jenkins.out

You can inspect all the default settings and if required overwrite them in your own values.yaml file. (as I will be doing below).
Note: For a list of available settings you can look here <https://github.com/helm/charts/tree/master/stable/jenkins> at their official GitHub page.

Next, lets prepare persistence storage that Jenkins will use and is now required at install time.
cat jenkins-storage-class.yaml

kind: StorageClass
apiVersion: storage.k8s.io/v1
metadata:
  name: local-storage
provisioner: kubernetes.io/no-provisioner
volumeBindingMode: WaitForFirstConsumer

Now, lets create the volume
cat jenkins-vol.yaml

kind: PersistentVolume
apiVersion: v1
metadata:
  name: jenkins
  namespace: jenkins
  labels:
    type: local
spec:
  storageClassName: local-storage
  capacity:
    storage: 10Gi
  accessModes:
    - ReadWriteOnce
    - ReadOnlyMany
  persistentVolumeReclaimPolicy: Retain
  hostPath:
    path: /opt/jenkins

Lastly, lets create / prepare the Volume Claim.
cat jenkins-pvc.yaml

kind: PersistentVolumeClaim
apiVersion: v1
metadata:
  name: jenkins
  namespace: jenkins
spec:
  storageClassName: local-storage
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 3Gi

Now, we are ready to install helm.

helm install stable/jenkins --tls \
    --name jenkins \
    --namespace jenkins \
    --values helm/jenkins-values.yml \
    --set persistence.existingClaim=jenkins

Overwrite configuration properties
cat helm/jenkins-values.yml

master:
  initContainerEnv:
    - name: http_proxy
      value: "http://10.10.10.17:1234"
    - name: https_proxy
      value: "http://10.10.10.17:1234"
    - name: no_proxy
      value: ""
  containerEnv:
    - name: http_proxy
      value: "http://10.10.10.17:1234"
    - name: https_proxy
      value: "http://10.10.10.17:1234"
  javaOpts: >-
    -Dhttp.proxyHost=10.10.10.17
    -Dhttp.proxyPort=1234
    -Dhttps.proxyHost=10.10.10.17
    -Dhttps.proxyPort=1234
  imageTag: "lts"
  installPlugins:
    - kubernetes:1.14.0
    - workflow-job:2.31
    - workflow-aggregator:2.6
    - credentials-binding:1.17
    - credentials:2.1.16
    - git:3.9.1
    - github:1.29.0
    - git-client:2.7.1
    - pipeline-utility-steps:2.0.2
    - script-security:1.43
    - slack:2.3
    - thinBackup:1.9

Verify deployment.

helm list --tls
NAME       REVISION    UPDATED                     STATUS      CHART             APP VERSION    NAMESPACE    
jenkins    1           Mon Jun 17 21:12:28 2019    DEPLOYED    jenkins-1.1.23    lts            jenkins      
metallb    1           Mon Feb 11 19:52:17 2019    DEPLOYED    metallb-0.8.4     0.7.3          metallb-system

If all worked correctly, you should see something like the below output.

kubectl get pv,pvc,pods,svc -n jenkins -o wide
NAME                       CAPACITY   ACCESS MODES   RECLAIM POLICY   STATUS   CLAIM             STORAGECLASS    REASON   AGE
persistentvolume/jenkins   10Gi       RWO,ROX        Retain           Bound    jenkins/jenkins   local-storage            20h

NAME                            STATUS   VOLUME    CAPACITY   ACCESS MODES   STORAGECLASS    AGE
persistentvolumeclaim/jenkins   Bound    jenkins   10Gi       RWO,ROX        local-storage   20h

NAME                           READY   STATUS    RESTARTS   AGE     IP          NODE          NOMINATED NODE   READINESS GATES
pod/jenkins-5d448c689f-btvpq   1/1     Running   0          3h17m   10.20.4.5   dc2-coreos2              

NAME                    TYPE           CLUSTER-IP    EXTERNAL-IP     PORT(S)          AGE   SELECTOR
service/jenkins         LoadBalancer   10.30.5.120   10.50.108.160   8080:31248/TCP   18h   app.kubernetes.io/component=jenkins-master,app.kubernetes.io/instance=jenkins
service/jenkins-agent   ClusterIP      10.30.1.197             50000/TCP        18h   app.kubernetes.io/component=jenkins-master,app.kubernetes.io/instance=jenkins

To get the Jenkins admin password, run the below.

printf $(kubectl get secret --namespace jenkins jenkins -o jsonpath="{.data.jenkins-admin-password}" | base64 --decode);echo
FOEf8vHW33
You can now login to Jenkins by going to (or whatever your load balancer IP address is).
http://10.50.108.160:8080

Checking for issues – Troubleshooting
One of the issues I had was being behind a corporate proxy/firewall.
Jenkins by default will try to install a list of plugins at install time, which if it fails/timeout will cause the install to not complete and fail.

To get around this issue, you have two options.

  1. Add an empty install plugins list. you do so by adding a line installPlugins: to your helm/jenkins-values.yml with no entry
  2. Add your proxy to the helm/jenkins-values.yml (like the configuration above)

To see cause of the issue, you can use docker (or kubectl logs …).
For example in my case, the below error was shown.

NAMESPACE        NAME                                      READY   STATUS     RESTARTS   AGE
jenkins          pod/jenkins-b9484f7bd-vq4qh               0/1     Init:0/1   0          55s

# OR.
NAMESPACE        NAME                                  READY   STATUS                  RESTARTS   AGE
jenkins          jenkins-74b9746545-ngcr4              0/1     Init:CrashLoopBackOff   3          89s

# OR.
NAMESPACE        NAME                                  READY   STATUS                  RESTARTS   AGE
jenkins          jenkins-74b9784f75-nq4qv              0/1     Init:Error   3          23s

And the corresponding pod showed the below issue (timeout).

docker logs afeca364f2b3
Creating initial locks...
Analyzing war...
Registering preinstalled plugins...
Downloading plugins...
Downloading plugin: kubernetes from https://updates.jenkins.io/download/plugins/kubernetes/1.14.0/kubernetes.hpi
Downloading plugin: workflow-job from https://updates.jenkins.io/download/plugins/workflow-job/2.31/workflow-job.hpi
Downloading plugin: workflow-aggregator from https://updates.jenkins.io/download/plugins/workflow-aggregator/2.6/workflow-aggregator.hpi
Downloading plugin: credentials-binding from https://updates.jenkins.io/download/plugins/credentials-binding/1.17/credentials-binding.hpi
Downloading plugin: git from https://updates.jenkins.io/download/plugins/git/3.9.1/git.hpi
cp: overwrite '/var/jenkins_home/config.xml'? cp: overwrite '/var/jenkins_home/jenkins.CLI.xml'? cp: overwrite '/var/jenkins_home/jenkins.model.JenkinsLocationConfiguration.xml'? cccccuuuuurrrrrlllll:::::     (((((2222288888)))))  R   eRRReRsseeeoosssllooovvllilivvnvniigignn n tggg ti  titmtimieimemdmed e edoodd uu o ttouou u ttata  ff ttaeaaefrffrtte et rer22 r0 022 5520005533315311 30  mm1 miii mllllmilliiliislllsiseiecsesccoeenccdooonosnnddn
dssds

s

19:28:07 Failure (28) Retrying in 1 seconds...
19:28:07 Failure (28) Retrying in 1 seconds...
19:28:07 Failure (28) Retrying in 1 seconds...
19:28:07 Failure (28) Retrying in 1 seconds...
19:28:07 Failure (28) Retrying in 1 seconds...
curl: (28) Resolving timed out after 20532 milliseconds
curl: (28) Resolving timed out aftceru r2l0:5 3(22 8m)i lRleissoelcvoinndgs
timed out after 20532 milliseconds

The full list of Jenkins Helm Chart Available Properties is available here

Like what you’re reading? please provide feedback, any feedback is appreciated.

You might also like – realted to Docker Kubernetes / micro-services.

0 0 votes
Article Rating
Subscribe
Notify of
guest
2 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
PAVEL GLAGOLEV
PAVEL GLAGOLEV
October 18, 2019 8:31 am

Hello)
I have the same problem. Did you manage to fix this problem?

2
0
Would love your thoughts, please comment.x
()
x
%d bloggers like this: