This repository is for the Jenkins Online Meetup featuring Jenkins on Kubernetes
MIT License
This guide will help you set up Jenkins on Kubernetes using Minikube in a few simple steps. Follow the instructions below to get started.
getstarted.sh
Script)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:
Dockerfile
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:
kubectl
, and others.jenkins-plugin-cli
to install plugins necessary for Kubernetes integration.getstarted.sh
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:
kubectl
Installation: Installs Minikube and kubectl
if they are not already installed.jenkins-admin-rbac.yaml
This file configures Role-Based Access Control (RBAC) for Jenkins, granting it the necessary permissions to interact with Kubernetes resources.
jenkins-service.yaml
Defines the Jenkins service in Kubernetes, exposing it on a specific NodePort for external access.
jenkins-deployment.yaml
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.
getstarted.sh
Script)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:
kubectl
if they are not already installed.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!