Custom Jenkins Docker images for production¶
Building a custom Docker image for Jenkins is the recommended approach for production environments.^[400-devops-06-kubernetes-devops-helm-helm-jenkins-readme.md]
Why use a custom image?¶
While the Jenkins Helm chart allows specifying plugins for installation, relying on runtime downloads presents risks.^[400-devops-06-kubernetes-devops-helm-helm-jenkins-readme.md] In a production scenario, connectivity issues to the Jenkins update site could cause the controller to fail if it cannot retrieve required plugins at startup.^[400-devops-06-kubernetes-devops-helm-helm-jenkins-readme.md] A custom image ensures that the specific plugins and versions required are already present, eliminating this dependency on external connectivity during deployment.^[400-devops-06-kubernetes-devops-helm-helm-jenkins-readme.md]
Creating the Dockerfile¶
To create a custom image, start with the official Jenkins LTS image and use the jenkins-plugin-cli tool to install the necessary components.^[400-devops-06-kubernetes-devops-helm-helm-jenkins-readme.md]
The following Dockerfile example demonstrates how to pre-install plugins such as Kubernetes, Workflow Aggregator, Git, and Configuration as Code:
FROM jenkins/jenkins:lts
RUN jenkins-plugin-cli --plugins kubernetes workflow-aggregator git configuration-as-code
Reproducible builds¶
To ensure the build is reproducible and avoid unexpected updates from floating tags, it is important to specify a concrete tag for the base image (e.g., jenkins/jenkins:2.249.3) and to define specific versions for the plugins.^[400-devops-06-kubernetes-devops-helm-helm-jenkins-readme.md]
Configuring Helm to use the custom image¶
Once the image is built and pushed to a container registry, the Helm values must be updated to use it.^[400-devops-06-kubernetes-devops-helm-helm-jenkins-readme.md] You must set controller.installPlugins to false to prevent the chart from attempting to download plugins again.^[400-devops-06-kubernetes-devops-helm-helm-jenkins-readme.md]
Public Registry¶
For a public registry, update your values.yaml as follows:
controller:
image: "registry/my-jenkins"
tag: "v1.2.3"
installPlugins: false
Private Registry¶
If the image is stored in a private registry, you must also specify the secret required to pull the image using imagePullSecretName:^[400-devops-06-kubernetes-devops-helm-helm-jenkins-readme.md]
controller:
image: "registry/my-jenkins"
tag: "v1.2.3"
imagePullSecretName: registry-secret
installPlugins: false
Related Concepts¶
- Jenkins
- Helm
- Kubernetes
- [[Jenkins Configuration as Code]]
Sources¶
^[400-devops-06-kubernetes-devops-helm-helm-jenkins-readme.md]