Monday, 19 March 2018

Jenkins on Kubernetes (Helm)

Deploy Jenkins on kubernetes with Helm


Writing a bunch of Kubernetes configuration files is not so much fun. For a few
containers, you will end up with 10+ yaml files. Maintaining them is only one issue,
but running in different environments or using the same files for CI/CD is a nightmare.
You can always use some bash tricks to replace some values, but that is a bad practice.
Here is where Helm comes into place. 


Installing helm
####################################
[root@ip-172-31-26-230 ~]# wget https://storage.googleapis.com/
kubernetes-helm/helm-v2.8.1-linux-amd64.tar.gz

[root@ip-172-31-26-230 ~]# ls
anaconda-ks.cfg  helm-v2.8.1-linux-amd64.tar.gz  original-ks.cfg

[root@ip-172-31-26-230 ~]# tar -xvf helm-v2.8.1-linux-amd64.tar.gz
linux-amd64/
linux-amd64/README.md
linux-amd64/LICENSE
linux-amd64/helm

[root@ip-172-31-26-230 ~]# cd linux-amd64/

[root@ip-172-31-26-230 linux-amd64]# ls
helm  LICENSE  README.md

[root@ip-172-31-26-230 linux-amd64]# sudo mv helm /usr/local/bin/.

[ec2-user@ip-172-31-26-230 ~]$ helm init
Creating /home/ec2-user/.helm
Creating /home/ec2-user/.helm/repository
Creating /home/ec2-user/.helm/repository/cache
Creating /home/ec2-user/.helm/repository/local
Creating /home/ec2-user/.helm/plugins
Creating /home/ec2-user/.helm/starters
Creating /home/ec2-user/.helm/cache/archive
Creating /home/ec2-user/.helm/repository/repositories.yaml
Adding stable repo with URL: https://kubernetes-charts.storage.googleapis.com
Adding local repo with URL: http://127.0.0.1:8879/charts
$HELM_HOME has been configured at /home/ec2-user/.helm.

Tiller (the Helm server-side component) has been installed into your 
Kubernetes Cluster.
Happy Helming!

[ec2-user@ip-172-31-26-230 ~]$ helm init --upgrade
$HELM_HOME has been configured at /home/ec2-user/.helm.

Tiller (the Helm server-side component) has been upgraded to the current version.
Happy Helming!
[ec2-user@ip-172-31-26-230 ~]$ kubectl create serviceaccount --namespace kube-system tiller
serviceaccount "tiller" created

[ec2-user@ip-172-31-26-230 ~]$ kubectl create clusterrolebinding tiller-cluster-
rule --clusterrole=cluster-admin --serviceaccount=kube-system:tiller
clusterrolebinding "tiller-cluster-rule" created

[ec2-user@ip-172-31-26-230 ~]$ kubectl patch deploy --namespace kube-system 
tiller-deploy -p '{"spec":{"template":{"spec":{"serviceAccount":"tiller"}}}}'
deployment "tiller-deploy" patched


Installing jenkins using helm
############################################
[ec2-user@ip-172-31-26-230 ~]$ helm search jenkins
NAME           CHART VERSION APP VERSION DESCRIPTION                                       
stable/jenkins 0.13.5        2.73        Open source continuous integration server. It s...

[ec2-user@ip-172-31-26-230 ~]$ helm repo update
Hang tight while we grab the latest from your chart repositories...
...Skip local chart repository
...Successfully got an update from the "stable" chart repository
Update Complete. ⎈ Happy Helming!⎈


[ec2-user@ip-172-31-26-230 ~]$ helm install --name jenkins  --namespace default stable/jenkins
NAME:   jenkins
LAST DEPLOYED: Tue Mar  6 09:39:30 2018
NAMESPACE: default
STATUS: DEPLOYED

RESOURCES:
==> v1/Service
NAME           TYPE CLUSTER-IP      EXTERNAL-IP PORT(S) AGE
jenkins-agent  ClusterIP 10.105.182.108  <none> 50000/TCP 0s
jenkins        LoadBalancer 10.98.234.179   <pending> 8080:30664/TCP 0s

==> v1beta1/Deployment
NAME     DESIRED CURRENT  UP-TO-DATE AVAILABLE  AGE
jenkins  1 0        0 0     0s

==> v1/Pod(related)
NAME                      READY STATUS RESTARTS AGE
jenkins-5b98f4ff49-4vtmn  0/1 Pending 0 0s

==> v1/Secret
NAME     TYPE DATA  AGE
jenkins  Opaque 2     0s

==> v1/ConfigMap
NAME           DATA AGE
jenkins        3 0s
jenkins-tests  1 0s

==> v1/PersistentVolumeClaim
NAME     STATUS VOLUME  CAPACITY ACCESS MODES  STORAGECLASS AGE
jenkins  Pending 0s


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

Get your admin password
###################################
[ec2-user@ip-172-31-26-230 ~]$ printf $(kubectl get secret --namespace default 
jenkins -o jsonpath="{.data.jenkins-admin-password}" | base64 --decode);echo
rTpR91KHEJ

Watch the status of by running
######################################
[ec2-user@ip-172-31-26-230 ~]$ kubectl get svc --namespace default -w jenkins
NAME      TYPE     CLUSTER-IP EXTERNAL-IP   PORT(S) AGE
jenkins   LoadBalancer   10.98.234.179 <pending>     8080:30664/TCP 2m

[ec2-user@ip-172-31-26-230 ~]$ helm list
NAME    REVISION UPDATED                  STATUS   CHART          NAMESPACE
jenkins 1        Tue Mar  6 09:39:30 2018 DEPLOYED jenkins-0.13.5 default

Check the pods list
########################
[ec2-user@ip-172-31-26-230 ~]$ kubectl get pods
NAME                       READY STATUS RESTARTS   AGE
jenkins-5b98f4ff49-4vtmn   0/1 Init:0/1 0     5m

1 comment:

  1. Migration necessities: Whereas migrating to the cloud you must have each tiny particulars in place like, which particular information, servers, or functions must be migrated? This is great blog. If you want to know more about this visit here AWS Cloud Certified.

    ReplyDelete

Amazon EKS - Kubernetes on AWS

By Komal Devgaonkar Amazon Elastic Container Service for Kubernetes (Amazon EKS), which is highly available and scalable AWS service....