Building the CI/CD of the Future, create your first pipeline in Jenkins
In this tutorial, I will share my experience as a DevOps engineer at Cloudify.co, this is the last post of the tutorial in which I will describe how to configure Jenkins Kubernetes plugin and how to create your first pipeline.
Building the CI/CD of the Future published posts:
- Introduction
- Creating the VPC for EKS cluster
- Creating the EKS cluster
- Adding the Cluster Autoscaler
- Add Ingress Nginx and Cert-Manager
- Install and configure Jenkins
- Create your first pipeline
Let’s start.
Kubernetes plugin for Jenkins
Jenkins plugin to run dynamic agents in a Kubernetes cluster.
https://plugins.jenkins.io/kubernetes/
Login to Jenkins
I explained how to get the password in the previous post: Install and configure Jenkins
Get the admin password of Jenkins
Configure Jenkins Kubernetes plugin
Go to dashboard -> Manage Jenkins -> Configure system
At the bottom of the page, you will see ‘Cloud’ section which is the configuration of the Jenkins Kubernetes plugin
Click on ‘a separate configuration page’
Let’s configure the most important fields:
Name: Kubernetes
Kubernetes URL: https://kubernetes.default
Kubernetes Namespace: jenkins (if you installed Jenkins to this namespace)
Credentials: click on Credentials -> add, select kind: ‘Kubernetes service account’
You created this service account in previous post, jenkins service account: Install and configure Jenkins
Click ‘Test Connection’ to test connectivity with the k8s cluster, if you see some connectivity problem: validate you created service account properly.
Jenkins URL: http://jenkins.jenkins.svc.cluster.local:8080
Jenkins Tunnel: jenkins-agent.jenkins.svc.cluster.local:50000
Be careful with those two fields, validate you have a correct domain name for jenkins (jenkins.jenkins.svc.cluster.local), meaning jenkins service located in jenkins namespace with port 8080, also jenkins agent is correct, by running ‘kubectl get svc -n jenkins’.
If those fields misconfigured you will have multiple errors when running the pipeline, you can run ’kubectl logs/describe’ on the running pod and see the exact problem. In my case, I misconfigured Jenkins Tunnel and had multiple errors in JNLP agent which wasn’t able to connect to Jenkins through the tunnel because the service name I used for Jenkins Tunnel wasn’t correct.
You can use defaults for the rest.
Create a pipeline to test the integration of Jenkins with Kubernetes cluster
Click on Dashboard -> New Item
Let’s create a pipeline to test integration with Kubernetes by getting pods in all namespaces
We using ‘gcr.io/cloud-builders/kubectl’ docker container with kubectl tool and running ‘kubectl get pods -all-namespaces’, to check we have access to the cluster through the service account we configured.
Click to save, go to this pipeline and run build:
You can use nodeSelector if you use labels for worker nodes and want to run pipeline on specific worker nodes (I want to run pipeline on spot in this case):
In the console output, you will see something similar to that
In case you have some problems, troubleshoot your pod with ‘kubectl describe/logs’
It was the last post of the ‘Building the CI/CD of the Future’ series. In this post, I covered how to configure Jenkins Kubernetes plugin and how to create your first pipeline to test connectivity with Kubernetes cluster from Jenkins by listing all the pods.
Thank you for reading, it was a great journey and I hope you enjoyed it.
Please subscribe to my YT channel
Please follow me on Twitter (@warolv)
I will save all configuration created in this tutorial in my Github