Jenkins Helm Charts

repository·main·Indexed 20 days ago

https://github.com/jenkinsci/helm-charts

Helm charts for deploying and managing Jenkins on Kubernetes. Includes support for standardized packaging, Jenkins Configuration as Code (JCasC), custom Docker images with pre-installed plugins, Prometheus metrics integration, and Kubernetes agent configuration. Supports installation via standard Helm repositories or OCI images (version 5.6.0+).

Tokens
12.2K
Snippets
42
Records
56
Agent score
71%

What's inside jenkinsci-helm-charts

  1. Use Jenkins Configuration as Code (JCasC) via Helm values

    main

    JCasC configuration is passed through the controller.JCasC key. You can provide custom configuration scripts using the controller.JCasC.configScripts sub-key.

    Each sub-key (e.g., welcome-message) acts as a label and becomes a filename in /var/jenkins_home/casc_configs. The content following the | character is the YAML content of that file.

    Important: Do not attempt to configure jenkinsUrl or jenkinsAdminEmail inside configScripts if they are already defined as top-level Helm values, as this will cause a conflict. Use the top-level keys instead.

    Example: Setting a custom system message:

    controller:
      JCasC:
        configScripts:
          welcome-message: |
            jenkins:
              systemMessage: Welcome to our CI/CD server.
  2. Use a custom Jenkins Docker image with pre-installed plugins

    main

    For production, it is recommended to build a custom Jenkins image with required plugins pre-installed to avoid connectivity issues during startup and ensure reproducibility.

    When using a custom image, set controller.installPlugins to false to disable the automatic plugin download sidecar. If using a private registry, specify the controller.imagePullSecretName.

    Example Dockerfile snippet:

    FROM jenkins/jenkins:lts
    RUN jenkins-plugin-cli --plugins kubernetes workflow-aggregator git configuration-as-code
    controller:
      image: "registry/my-jenkins"
      tag: "v1.2.3"
      imagePullSecretName: registry-secret
      installPlugins: false
  3. View Jenkins Helm Chart configuration options

    main

    To see all configurable options for the Jenkins chart, you can view the values.yaml file in the repository or use the Helm CLI to display the default values with comments:

    # Helm 3
    $ helm show values jenkins/jenkins

    A summary of all configurable options is also available in the VALUES.md file.

    # Helm 3
    $ helm show values jenkins/jenkins
  4. Migrate Jenkins Helm Chart releases

    main

    From stable repository

    To upgrade an existing release from stable/jenkins to jenkins/jenkins, ensure you have the latest repository info and run the upgrade commands specifying the jenkins/jenkins chart.

    Major Version Upgrades

    Chart release versions follow SemVer. A MAJOR version change (e.g., 1.0.0 -> 2.0.0) indicates incompatible breaking changes that require manual actions. Refer to UPGRADING.md for a detailed list of breaking changes.

  5. Upgrade Jenkins Helm Chart to 4.0.0

    main

    When upgrading to 4.0.0, be aware of changes to remotingSecurity.

    If you are using a Jenkins container tag older than 2.326, the automatic remotingSecurity setting is removed. To maintain compatibility with older versions, you must explicitly set .controller.legacyRemotingSecurityEnabled to true in your values.

    controller:
      legacyRemotingSecurityEnabled: true
  6. Upgrade Jenkins Helm Chart to 5.0.0

    main

    Upgrading to version 5.0.0 involves significant breaking changes to the configuration schema, specifically regarding image definitions and administrative credentials.

    Image Configuration Changes

    Direct image and tag keys have been removed in favor of structured objects. If you need to override images, use the new sub-keys:

    • Controller Image: Replace controller.image, controller.tag, and controller.tagLabel with controller.image.registry, controller.image.repository, controller.image.tag, and controller.image.tagLabel. Also, move controller.imagePullPolicy to controller.image.pullPolicy.
    • Sidecar (configAutoReload): Replace controller.sidecars.configAutoReload.image with controller.sidecars.configAutoReload.image.registry, controller.sidecars.configAutoReload.image.repository, controller.sidecars.configAutoReload.image.tag, and controller.sidecars.configAutoReload.image.tagLabel.
    • Agent Image: Replace agent.image and agent.tag with agent.image.repository and agent.image.tag. The registry is still configurable via agent.jnlpregistry.
    • Helmtest BATS: Split helmtest.bats.image into helmtest.bats.image.registry, helmtest.bats.image.repository, and helmtest.bats.image.tag.

    Renamed Keys

    • Admin Credentials: controller.adminUsername $\rightarrow$ controller.admin.username, controller.adminPassword $\rightarrow$ controller.admin.password, and controller.adminSecret $\rightarrow$ controller.admin.createSecret.
    • Sidecars: controller.sidecars.other $\rightarrow$ controller.sidecars.additionalSidecarContainers.
    • Agent Containers: agent.additionalContainers[*].image $\rightarrow$ agent.additionalContainers[*].image.repository and agent.additionalContainers[*].tag $\rightarrow$ agent.additionalContainers[*].image.tag.
    • Additional Agents/Clouds: All image and tag keys under additionalAgents and additionalClouds have been moved under an image.repository and image.tag hierarchy.

    Removed Features

    • backup.* has been removed. Use external Kubernetes backup solutions.
    # Example of new 5.0.0 image configuration
    controller:
      image:
        registry: docker.io
        repository: jenkins/jenkins
        tag: lts
        pullPolicy: Always
  7. Upgrade Jenkins Helm Chart to 2.0.0

    main

    Version 2.0.0 introduces two major changes: Jenkins Configuration as Code (JCasC) is now the default, and the container no longer runs as root.

    Configuration as Code (JCasC)

    Configuration is managed via the Jenkins Configuration as Code Plugin.

    • Warning: Manual changes made via the Jenkins UI will likely be reset to the defaults defined in your Helm values.
    • Migration: Export your current settings using Manage Jenkins $\rightarrow$ Configuration as Code $\rightarrow$ Download Configuration and use that as a starting point for your Helm values.

    Non-Root Execution

    Containers no longer run as root.

    • Action Required: Ensure your Jenkins image supports the configured user/group ID (default is 1000:1000). You may need to manually update file permissions.

    Migration Steps

    1. Ensure your image contains user/group ID 1000 (e.g., jenkins/jenkins:lts).
    2. Backup your persistent volume.
    3. Ensure the configuration-as-code plugin is installed.
    4. Export current settings via the plugin.
    5. Prepare your values.yaml with JCasC settings.
    6. Put Jenkins in Quiet Down mode (<JENKINS_URL>/quietDown).
    7. Update file permissions inside the pod:
      kubectl exec -it <jenkins_pod> -c jenkins -- /bin/bash
      chown -R 1000:1000 /var/jenkins_home
    8. Perform the Helm upgrade.
    # Default values introduced in 2.0.0
    controller:
      runAsUser: 1000
      fsGroup: 1000
      JCasC:
        enabled: true
        defaultConfig: true
      sidecars:
        configAutoReload:
          enabled: true
  8. Configure the Jenkins Helm chart

    main
    The Jenkins Helm chart is configured using a values.yaml file. You can customize the deployment by providing a custom values file during the helm install or helm upgrade command. The configuration parameters are organized into logical groups (e.g., controller, agent, persistence) to manage different components of the Jenkins installation.
  9. Enable JCasC Auto-Reload with a sidecar

    main

    By default, JCasC changes require a pod restart. To enable on-the-fly reloading, enable the configAutoReload sidecar. This sidecar watches for changes to configScripts, updates the filesystem, and triggers a reload via a POST request to http://<jenkins_url>/reload-configuration-as-code.

    To use this, you must also enable RBAC (rbac.create: true) so the sidecar can watch ConfigMaps.

    Monitoring logs: kubectl logs <controller_pod> -c config-reload -f

    controller:
      sidecars:
        configAutoReload:
          enabled: true
    rbac:
      create: true
  10. Add chart maintainers to a Jenkins Helm Chart

    main

    To add a new maintainer for a specific chart, you must update the configuration within the chart itself and ensure they are recognized by the repository's ownership rules.

    Follow these steps:

    1. Update the Chart: Add the new maintainer's information directly within the chart's configuration files.
    2. Update CODEOWNERS: Create or update the .github/CODEOWNERS file to include the new maintainer so they are eligible to approve pull requests for that chart.
    3. Approval Process: The pull request requires two approvals:
      • An approval from an existing chart maintainer.
      • An approval from a repository administrator.
    4. Permissions: Once the PR is merged, a repository administrator must grant the new maintainer write permissions to the repository.
  11. Upgrade Jenkins Helm Chart to 3.0.0

    main

    Upgrading to 3.0.0 involves major architectural and terminology shifts:

    Requirements and Architecture

    • Helm Version: You must use Helm 3 as the chart uses apiVersion: v2.
    • Workload Type: Jenkins has transitioned from a Deployment to a StatefulSet.

    Configuration Changes

    • XML to JCasC: All XML configuration options have been removed. You must migrate to Jenkins Configuration as Code (JCasC).
    • Security: You must check and adjust your securityRealm and authorizationStrategy to prevent your configured users and permissions from being overridden.

    Terminology Mapping (Values Renaming)

    Many values have been renamed from master to controller or slave to agent:

    • master $\rightarrow$ controller
    • master.useSecurity $\rightarrow$ controller.adminSecret
    • master.slaveListenerPort $\rightarrow$ controller.agentListenerPort
    • master.slaveHostPort $\rightarrow$ controller.agentListenerHostPort
    • master.slaveKubernetesNamespace $\rightarrow$ agent.namespace
    • master.slaveDefaultsProviderTemplate $\rightarrow$ agent.defaultsProviderTemplate
    • master.slaveJenkinsUrl $\rightarrow$ agent.jenkinsUrl
    • master.slaveJenkinsTunnel $\rightarrow$ agent.jenkinsTunnel
    • master.slaveConnectTimeout $\rightarrow$ agent.kubernetesConnectTimeout
    • master.slaveReadTimeout $\rightarrow$ agent.kubernetesReadTimeout
    • master.slaveListenerServiceAnnotations $\rightarrow$ controller.agentListenerServiceAnnotations
    • master.slaveListenerServiceType $\rightarrow$ controller.agentListenerServiceType
    • master.slaveListenerLoadBalancerIP $\rightarrow$ controller.agentListenerLoadBalancerIP
    • agent.slaveConnectTimeout $\rightarrow$ agent.connectTimeout
    • master.imageTag $\rightarrow$ use controller.image and controller.tag
    • slave.imageTag $\rightarrow$ use agent.image and agent.tag