In this comprehensive guide, we’ll go through the installation of Jenkins on a Kubernetes (K8s) cluster using Helm and set up the NGINX Ingress Controller for both private and public clusters. This tutorial applies to various cloud providers, including Azure AKSAWS EKS, and Google Kubernetes Engine (GKE). Additionally, we’ll cover SSL configuration using your own certificates, Let’s Encrypt, or a Kubernetes ClusterIssuer.

Follow this article to install Kubectl, helm required to follow this guide properly.

Prerequisites

  • Kubernetes Cluster: Ensure you have an existing Kubernetes cluster (AKS, EKS, or GKE).
  • kubectl: Installed and configured to interact with your Kubernetes cluster.
  • Helm: Installed on your local machine to deploy Jenkins and the NGINX Ingress Controller.
  • Certificates: Either have your SSL certificates ready or be prepared to generate them using Let’s Encrypt or Kubernetes ClusterIssuer. In this example, we have lets encrypt certs saved in files tls.crt and tis.key.
  • DNS setting: Access to your DNS provider i.e cloudflare, Godaddy, Namecheap etc to modify dns records.

Setting Up the NGINX Ingress Controller on Kubernetes

Before we install Jenkins on Kubernetes with Helm, we need to set up an NGINX Ingress Controller. Below are steps for both public and private clusters, and annotations specific to each cloud provider.

Step 1: Install and Configure the Nginx Ingress Controller Based on Your Cloud Provider.

Here’s how to set up the Ingress Controller with provider-specific annotations:

For Private Clusters

Ingress-Nginx-Controller by helm

helm repo add ingress-nginx https://kubernetes.github.io/ingress-nginx 
helm repo update
helm install ingress-nginx ingress-nginx/ingress-nginx \ 
--namespace ingress-nginx \ --create-namespace \ 
--set controller.service.annotations."service\.beta\.kubernetes\.io/azure-load-balancer-internal"="true"
helm repo add ingress-nginx https://kubernetes.github.io/ingress-nginx 
helm repo update
helm install ingress-nginx ingress-nginx/ingress-nginx \ 
--namespace ingress-nginx \ 
--create-namespace \ 
--set controller.service.annotations."service\.beta\.kubernetes\.io/aws-load-balancer-internal"="true"
helm repo add ingress-nginx https://kubernetes.github.io/ingress-nginx 
helm repo update
helm install ingress-nginx ingress-nginx/ingress-nginx \
--namespace ingress-nginx --create-namespace \
--set controller.service.type=LoadBalancer \
--set controller.service.annotations."cloud\.google\.com/load-balancer-type"=Internal
For Public Clusters

If your cluster is public, simply skip the internal load balancer annotation:

helm repo add ingress-nginx https://kubernetes.github.io/ingress-nginx 
helm repo update
helm install ingress-nginx ingress-nginx/ingress-nginx \
  --namespace ingress-nginx \
  --create-namespace
Code language: Bash (bash)

Step 2: Verify the Ingress Installation

Run the following command to verify the Ingress Controller’s installation:

kubectl get svc -n ingress-nginx
Code language: Bash (bash)

This will output details of the Ingress service. For public clusters, you’ll see an external IP, while for private clusters, an internal IP will be displayed. Use this IP to configure your domain’s DNS settings.

Installing Jenkins on Kubernetes with Helm

With the Ingress Controller ready, we’ll now install Jenkins on the Kubernetes cluster.

Step 3: Add the Jenkins Helm Repository

Add the Jenkins Helm chart repository:

helm repo add jenkins https://charts.jenkins.io
helm repo update
Code language: Bash (bash)

Step 4: Set Up SSL Certificates

To secure your Jenkins instance, you need SSL certificates. You have three options:

  • Use Your Own Certificates: If you have your certificates, create a TLS secret which will be used by Jenkins ingress later on to serve HTTPS Traffic:
kubectl create secret tls jenkins-tls-secret --cert=./tls.crt --key=./tls.key --namespace jenkins
Code language: Bash (bash)
  • Use Let’s Encrypt: Install and configure Cert-Manager to manage certificates in your cluster. You can use an Ingress resource to automatically generate and renew certificates from Let’s Encrypt.
  • Use a ClusterIssuer: Follow your provider’s documentation for helm.

Step 5: Create a Custom values.yaml for Jenkins

Define the ingress settings in a values.yaml file:

controller:
  hostName: jenkins.yourdomain.com
  ingress:
    enabled: true
    annotations:
      nginx.ingress.kubernetes.io/force-ssl-redirect: "true"
      nginx.ingress.kubernetes.io/ssl-redirect: "true"
    ingressClassName: nginx
    hostName: jenkins.yourdomain.com
    tls:
    - secretName: jenkins-tls-secret
      hosts:
        - jenkins.yourdomain.com

Code language: YAML (yaml)

Replace jenkins.yourdomain.com with your domain and ensure the secretName matches the TLS secret created in Step 4.

If you don’t want your domain url to redirect from http:// to https:// automatically , change these annotations to false.

      nginx.ingress.kubernetes.io/force-ssl-redirect: "false"
      nginx.ingress.kubernetes.io/ssl-redirect: "false"
Code language: YAML (yaml)

Step 6: Installing Jenkins on Kubernetes with Helm

Now that the Ingress Controller is set up, let’s install Jenkins on the Kubernetes cluster using Helm.

Use the custom values.yaml to install Jenkins:

helm upgrade --install -f values.yaml jenkins jenkins/jenkins --namespace jenkins --create-namespace
Code language: Bash (bash)

This command deploys Jenkins using the specified settings in values.yaml.

Summary

You’ve successfully installed Jenkins on a Kubernetes cluster using Helm and set up the NGINX Ingress Controller for both private and public clusters on AKS, EKS, and GKE.

Explore More

Want to learn more about deploying applications on Kubernetes? Check out our other guides for detailed tutorials on setting up environments for various use cases.

Leave a Response

share on: