This guide will help you set up Jenkins on Kubernetes using Minikube in a few simple steps. Follow the instructions below to get started.
- Code Walkthrough
- Steps to Get Started (Manual)
- Steps to Get Started (Using
getstarted.sh
Script) - Opening Issues and Submitting Pull Requests
The project consists of several key files and scripts that are necessary to deploy Jenkins on a Kubernetes cluster. Let's walk through the main components:
The Dockerfile
sets up a Jenkins instance with required tools such as Docker CLI and kubectl
. It installs necessary packages and plugins to make Jenkins work seamlessly within a Kubernetes environment. The final image can be used as a Jenkins master node.
Key steps:
- Base Image: Starts with the official Jenkins LTS image.
- Packages Installation: Installs essential packages like Docker CLI,
kubectl
, and others. - Plugins Installation: Uses
jenkins-plugin-cli
to install plugins necessary for Kubernetes integration.
This script automates the process of setting up Jenkins on Kubernetes. It checks for the existence of Minikube and kubectl
, installs them if necessary, and then sets up the Kubernetes cluster and Jenkins deployment.
Key steps:
- Minikube and
kubectl
Installation: Installs Minikube andkubectl
if they are not already installed. - Kubernetes Cluster Setup: Starts a Minikube cluster.
- Jenkins Deployment: Creates necessary resources like namespace, PersistentVolume, RBAC configurations, and then deploys Jenkins.
- Port Forwarding: Automatically forwards the Jenkins service port to your local machine for easy access.
This file configures Role-Based Access Control (RBAC) for Jenkins, granting it the necessary permissions to interact with Kubernetes resources.
Defines the Jenkins service in Kubernetes, exposing it on a specific NodePort for external access.
This file sets up the actual Jenkins deployment in Kubernetes, specifying the image to use, volume mounts, and other deployment details.
-
Start Minikube: Set up a local Kubernetes cluster by running the following command:
minikube start
-
Create a Namespace for Jenkins: Organize Jenkins resources under a dedicated namespace:
kubectl create namespace jenkins
-
Apply RBAC Configuration: Grant Jenkins the necessary permissions:
kubectl apply -f jenkins-admin-rbac.yaml
-
Create Jenkins Service: Deploy the Jenkins service:
kubectl apply -f jenkins-service.yaml
-
Deploy Jenkins: Deploy the Jenkins instance:
kubectl apply -f jenkins-deployment.yaml
-
Get Minikube IP: Obtain the Minikube IP:
minikube ip
-
Access Jenkins UI: Combine the Minikube IP with the NodePort to access Jenkins. For example:
http://<Minikube-IP>:<NodePort>
-
Configure Build Executor: In Jenkins UI, navigate to "Manage Jenkins" > "Manage Nodes and Clouds" to configure the Kubernetes cloud.
-
Test the Connection: Verify the Kubernetes integration by testing the connection within Jenkins.
-
Create and Run a Job: Set up a freestyle job in Jenkins to confirm everything is functioning as expected.
To automate the entire setup process, you can use the provided getstarted.sh
script:
-
Ensure Prerequisites: Ensure that you have a bash-compatible shell, and that the script is executable. If needed, make it executable with:
chmod +x getstarted.sh
-
Run the Script: Execute the script:
./getstarted.sh
-
Follow the Prompts: The script will guide you through the installation process. It will:
- Install Minikube and
kubectl
if they are not already installed. - Start a Minikube cluster.
- Set up Kubernetes resources and deploy Jenkins.
- Automatically forward the Jenkins service port to your local machine.
- Install Minikube and
-
Access Jenkins UI: Once the script completes, it will provide you with a URL to access Jenkins, such as
http://localhost:8080
. Open this in your web browser.
If you encounter any issues or have suggestions for new features, you can open an issue or submit a pull request. Here's how:
-
Opening Issues: Navigate to the GitHub Issues page and create a new issue. Please provide as much detail as possible, including steps to reproduce the problem if applicable.
-
Submitting Pull Requests: Fork the repository, make your changes, and submit a pull request. Ensure that your code follows the existing style and conventions. If you're adding new functionality, consider adding relevant tests.
DockerHub Repository: You can find the pre-built Docker image on DockerHub here.
Enjoy a seamless CI/CD experience with Jenkins on Kubernetes!