Running and setting up Jenkins in Kubernetes

This guide will help you set up jenkins in kubernetes using helm.

Jenkins is a free and open source automation server. It helps automate the parts of software development related to building, testing, and deploying, facilitating continuous integration and continuous delivery.

Kubernetes is an open-source container-orchestration system for automating computer application deployment, scaling, and management.

Requirements:

  • Kubernetes cluster (I am using version v1.19.7)
  • Access to kubernetes cluster (kubectl) (I am using version v1.20.2)
  • Helm installed (I am using version v3.5.1)

Adding jenkins helm chart repo

Add the helm chart repo as follows:

helm repo add jenkins https://charts.jenkins.io
helm repo update
helm search repo jenkins

To confirm that the repo has been added, list with this command:

helm repo list

Installing jenkins

We will need our jenkins configuration to persist restarts and jenkins recreation. To achieve this, we are going to have a pvc with the following config:

kind: PersistentVolumeClaim
apiVersion: v1
metadata:
  name: jenkins-vol
  namespace: tooling
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: "50Gi"

Create the pvc with the command :

kubectl create -f jenkins-vol.yaml

I like to have a customized values.yaml to modify some configs in jenkins. Mine looks like this:

controller:
  componentName: Jenkins-Master
  tag: "2.263.3-alpine"
  imagePullPolicy: IfNotPresent
  numExecutors: 0
  disableRememberMe: false

  adminUser: admin
  adminPassword: MLGv62PftDimwGc3YBNgGsFM!%xa4X
  jenkinsAdminEmail: admin@citizix.com
  jenkinsUrl: "https://jenkins.dev.citizix.com"

  installPlugins:
    - kubernetes:1.28.7
    - git:4.5.2
    - job-dsl:1.77
    - github:1.32.0
    - blueocean:1.24.4
    - slack:2.45
    - workflow-job:2.40
    - workflow-aggregator:2.6
    - credentials:2.3.14
    - credentials-binding:1.24
    - github-branch-source:2.10.0
    - configuration-as-code:1.46
    - rebuild:1.31

  ingress:
    enabled: true
    hostName: jenkins.dev.citizix.com
    path: "/"
    apiVersion: "networking.k8s.io/v1"
    annotations:
      kubernetes.io/ingress.class: nginx
      cert-manager.io/cluster-issuer: letsencrypt-prod-issuer
      kubernetes.io/tls-acme: "true"
    tls:
      - secretName: the-jenkins-tls-tooling
        hosts:
          - jenkins.dev.citizix.com

  JCasC:
    configScripts:
      welcome-message: |
        jenkins:
          systemMessage: Welcome to Citizix CI\CD server.

persistence:
  enabled: true
  existingClaim: jenkins-vol
  annotations: {}

agent:
  enabled: true
  websocket: true
  customJenkinsLabels:
    - runner

To install jenkins using helm chart:

helm upgrade -i jenkins jenkins/jenkins -f ./values.yaml -n tooling
comments powered by Disqus
Citizix Ltd
Built with Hugo
Theme Stack designed by Jimmy