The website content provides a comprehensive guide on setting up Jenkins Operator in a Kubernetes cluster, including installation, configuration, and the use of Jenkins CRDs, seed jobs, and the Kubernetes Plugin for Jenkins.
Abstract
The article "Introduction to Jenkins Operator" is a technical tutorial aimed at Kubernetes users interested in deploying Jenkins within their clusters. It begins by explaining the concept of a Kubernetes operator, highlighting the Jenkins Operator as a specific example. The Jenkins Operator extends Kubernetes API capabilities to manage Jenkins instances efficiently. The guide details the prerequisites for installation, such as a Kubernetes cluster and Helm client, and provides step-by-step instructions for installing the Jenkins Operator using a Helm chart. It also covers the creation and management of Jenkins instances using Custom Resource Definitions (CRDs) and seed jobs, which are jobs that can be automatically created from a source control manager (SCM) like GitHub. The article further explains how to use the Kubernetes Plugin to dynamically provision Jenkins agents as Kubernetes Pods. The author demonstrates the process with examples, including screenshots and code snippets, and concludes by providing access to additional resources and related articles for further learning.
Opinions
The author emphasizes the importance of Kubernetes operators in managing complex applications, suggesting that the Jenkins Operator is a valuable tool for Kubernetes users.
The article implies that using the Jenkins Operator simplifies the deployment and management of Jenkins on Kubernetes, making it a preferred method over traditional deployment approaches.
The author seems to advocate for the use of seed jobs and SCMs to automate job creation in Jenkins, which aligns with modern CI/CD practices.
The use of the Kubernetes Plugin for Jenkins is presented as a beneficial feature that enhances the scalability and efficiency of Jenkins agents within a Kubernetes environment.
The author's inclusion of personal GitHub links and branches suggests a hands-on approach to learning and a willingness to share practical knowledge with the community.
The conclusion and recommendation sections indicate that the author believes in continuous learning and encourages readers to explore related topics and tools within the Kubernetes ecosystem.
Introduction to Jenkins Operator
Getting started with Jenkins Operator in Kubernetes
Before we dive into Jenkins Operator, let us spare some time to understand what a Kubernetes operator actually is. As mentioned in RedHat’s Documentation page, a Kubernetes operator is an application-specific controller that extends the functionality of the Kubernetes API to create, configure, and manage instances of complex applications on behalf of a Kubernetes user. It is a method of packaging, deploying, and managing a Kubernetes application. The Kubernetes Operator concept was developed by engineers at CoreOS in 2016. There are numerous operators available in the market as of now. Out of them, the most widely used operators are
Istio Operator
ArgoCD Operator
Cert Manager Operator
Horizontal Pod Autoscaler Operator
Kong Operator
Falco Operator
Prometheus Operator etc
In this article, we would learn about how to set up Jenkins Operator in a Kubernetes Cluster.
And now you should see the Jenkins Operator Pod starting in the jenkins-operator namespace. This operator pod will keep watching for any Jenkins CRD’s created. Let us now create one to deploy our Jenkins to the cluster.
Use the Jenkins CRD to setup Jenkins
Let us now understand the whole jenkins.yaml file.
apiVersion = jenkins.io/v1alpha2
kind = Jenkins
metadata.name = The name of the Jenkins Instance to be created
spec.service.type = LoadBalancer ( The type of the service in which Kubernetes is exposed. It can be either ClusterIP, NodePort, LoadBalancer )
spec.service.port = The port on which the service is to be exposed
spec.master = These properties represents the Jenkins master node properties
spec.master.basePlugins: BasePlugins contains plugins required by the Jenkins operator.
spec.master.plugins: The list of plugins required by the user to be installed
seedJobs: It defines the list of Jenkins seed Job Configurations from SCM’s. Here I have given my GitRepo URL and the name of the branch from which the seedJobs should be configured.
This would now Install the Jenkins in your Kubernetes cluster
Let us now get the IP of our LoadBalancer. In case if you are using a local cluster, you can use metallb as a LoadBalancer Implementation. ( MetalLb is a load-balancer implementation for bare metal Kubernetes Clusters ).
kubectl get services -n jenkins-operator jenkins-operator-http-prod-jenkins -o jsonpath='{.status.loadBalancer.ingress[0].ip}'
A seed job is a Jenkins job that runs a DSL script to generate a new job. You can thus use a groovy script to create a larger number of Jobs. As mentioned here let us prepare our repo in the same format.
cicd folder in our GitHub
You can also clone my repo containing the cicd files
Where the jobs folder contains the files required to create the Jenkins jobs and the pipelines folder contain the actual Jenkins pipeline files.
Jenkins jobs fileJenkins pipeline files use the pod template to create a pod
So our Jenkins pipeline will just execute the hostname command. Now if you have noticed in the Jenkins node our seed jobs were already created !!!
Noice ….SeedJob from our GitHub
Use the Kubernetes Plugin for Jenkins
Kubernetes Plugin is a Jenkins plugin to run dynamic agents in a Kubernetes cluster. This Plugin creates a Kubernetes Pod for each agent started. However, It is not required to run the Jenkins master inside Kubernetes. Now let us run the pipeline configured by our SeedJob. You can take a look at the pipeline configuration in my Github. As soon as I build my pipeline I can see a pod getting created in my jenkins-operator namespace. So all the stages defined in our pipeline file will be running in the same pod created by Jenkins. Once the steps in the pipeline are completed, the pod also gets terminated ( You can retain them if needed by changing the configuration ).
Pipeline creating a podJenkins pipeline Console Output
Conclusion
Thanks for reading my article. Hope you have liked it. Here are some of my other articles that may interest you.