Introduction

Jenkins is a open-source automation server, which enables building, testing, and deploying, facilitating continuous integration and continuous delivery and offers over 1600 plugins to automate almost everything.

Jenkins has been around for some time and is one of the more popular automation servers. You can read more up about Jenkins on their website.

This guide will show you how to Deploy Jenkins from the Civo App Marketplace, and demonstrate basic usage. You will be able to take this guide and extend it to automate your own projects.

Prerequisites

If you would like to follow along in this guide, you need a Civo account and also require Kubernetes access. At the time of writing, Civo's Kubernetes offering is currently in Beta, but you can apply for access, using this link.

When you join the #KUBE100 Beta, you don't only get access to a awesome Kubernetes service, but you also get:

  • $70 free credit every month
  • Early access to new features
  • Invited to a community Slack channel
  • Exclusive rewards for contributions
  • Free Swag

You also require kubectl to access your Kubernetes cluster.

Deploy a Kubernetes Cluster

From the dashboard, go ahead and create a new cluster:

Cluster creation

In my case, I will name my cluster "jenkins", with 3 nodes of the "Small" instance type:

Jenkins cluster

Because Jenkins requires persistent volumes, we require Longhorn. Select Longhorn from the "Storage" section:

Persistent storage

Then head over to the "CI/CD" section, select Jenkins and select the volume size appropriate for your project, then select create cluster:

Marketplace

Once your cluster is deployed, you should see the following information that also includes your DNS name that we will require later for our Traefik Ingress:

jenkins-civo-kube100-image

From the "Installed applications" section, you will find more information about Jenkins, such as your username and password to access Jenkins, as well as allowing external access via Traefik:

Jenkins info

Set your DNS name and application name if you would like to access Jenkins as jenkins.{your-id}.k8s.civo.com:

$ export CIVO_DNS=5cdffe7b-038a-49ea-8387-be4bae6f5eb6.k8s.civo.com
$ export CIVO_APP=jenkins

$ cat > jenkins-ingress.yaml << EOF
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: jenkins-ingress
spec:
  rules:
  - host: ${CIVO_APP}.${CIVO_DNS}
    http:
      paths:
      - backend:
          serviceName: jenkins-frontend
          servicePort: 8080
EOF

You can of course create the jenkins-ingress.yaml file manually, pasting in the above and editing in the host values from your dashboard.

Then go ahead and create the ingress:

$ kubectl apply -f jenkins-ingress.yaml
ingress.extensions/jenkins-ingress created

Get the information from your ingress:

$ kubectl get ingress
NAME              HOSTS                                                       ADDRESS        PORTS   AGE
jenkins-ingress   jenkins.5cdffe7b-038a-49ea-8387-be4bae6f5eb6.k8s.civo.com   172.31.2.107   80      22s

Access Jenkins

Now that Jenkins has been deployed, visit the address that was received from the ingress output:

Jenkins login

You can retrieve the username and password from the Civo Dashboard under "Installed applications":

Credentials

After logging in, you should see this interface:

Interface

To get started, let's create a traditional hello-world job, which in this case is a shell script that outputs the time:

Hello World!

From the build section, select the execute shell option:

Execute shell

Then we will execute a very basic shell script that returns the date in South Africa's timezone:

Time Zone script

After saving the job, select build now:

jenkins-civo-kube100-image

Then from the build, view the console output:

Console output

Testing Data Persistence

As we know, containers are stateless by design. If we did not have persistent volumes associated to our container, were we to delete the container, our saved job in Jenkins will be missing when the container comes back up.

But since we are using persistent volumes, the configured data is persisted in our volumes and when the container is deleted, the new container will still have the saved data that was stored on the volumes.

In this example, we will delete the pod to determine if the data is still there when the new pod comes up.

View the pods with the wide output flag so that we can see on which node the pod is running:

$ kubectl get pods --selector app=jenkins --output wide                                                                                                   
NAME                       READY   STATUS    RESTARTS   AGE   IP             NODE             NOMINATED NODE   READINESS GATES
jenkins-8559cc77b7-qwcng   1/1     Running   0          17m   192.168.1.14   kube-node-fb88   <none>           <none>

Now delete the pod by specifying the pod id returned in the above command:

$ kubectl delete pod/jenkins-8559cc77b7-qwcng
pod "jenkins-8559cc77b7-qwcng" deleted

Then once the pod comes back up, we can view the pod again and notice in this case that the pod runs on a different node on our kubernetes cluster:

$ kubectl get pods --selector app=jenkins --output wide
NAME                       READY   STATUS    RESTARTS   AGE    IP             NODE               NOMINATED NODE   READINESS GATES
jenkins-8559cc77b7-hvdqq   1/1     Running   0          101s   192.168.0.17   kube-master-d1a3   <none>           <none>

Access the Jenkins UI again. After re-authenticating, we can see that our Jenkins job has persisted and still available:

Persisted state

Once you are done, you can go ahead and delete your cluster, or use the setup you have to continue to experiment with automation. If you have a project with a test suite, you can have Jenkins run the tests and rebuild your containers, as well as push the container(s) to a registry for access by others!

Conclusion

Civo really makes it easy provisioning Kubernetes clusters and Deploying applications such as Jenkins to your Cluster. Have a look at all the other applications that are available on the marketplace - or if you think it's missing one, submit it for the benefit of the community! The marketplace is open-source.

Until next time.