jenkins

by joaquinito2051

Helm chartv0.10.38App 2.67

Open source continuous integration server. It supports multiple SCM tools including CVS, Subversion and Git. It can execute Apache Ant and Apache Maven-based projects as well as arbitrary scripts.

About this chart

Jenkins Helm Chart

Jenkins master and slave cluster utilizing the Jenkins Kubernetes plugin

  • https://wiki.jenkins-ci.org/display/JENKINS/Kubernetes+Plugin

Inspired by the awesome work of Carlos Sanchez mailto:[email protected]

Chart Details

This chart will do the following:

  • 1 x Jenkins Master with port 8080 exposed on an external LoadBalancer
  • All using Kubernetes Deployments

Installing the Chart

To install the chart with the release name my-release:

$ helm install --name my-release stable/jenkins

Configuration

The following tables lists the configurable parameters of the Jenkins chart and their default values.

Jenkins Master

ParameterDescriptionDefault
Master.NameJenkins master namejenkins-master
Master.ImageMaster image namejenkinsci/jenkins
Master.ImageTagMaster image tag2.46.1
Master.ImagePullPolicyMaster image pull policyAlways
Master.Componentk8s selector keyjenkins-master
Master.UseSecurityUse basic securitytrue
Master.SecurityRealmCustom Security RealmNot set
Master.ServiceLabelsCustom Service labelsNot set
Master.AuthorizationStrategyClassAuthorizationStrategy classhudson.security.FullControlOnceLoggedInAuthorizationStrategy
Master.AuthorizationStrategyAttributesList of authorization strategy attributesdenyAnonymousReadAccess: true
Master.SecurityRealmClassSecurityRealmClass classhudson.security.LegacySecurityRealm
Master.SecurityRealmAttributesList of security realm attributes{}
Master.ServiceAccountAnnotationsAnnotations to add to the service account{}
Master.AdminUserAdmin username (and password) created as a secret if useSecurity is trueadmin
Master.CpuMaster requested cpu200m
Master.MemoryMaster requested memory256Mi
Master.InitContainerEnvEnvironment variables for Init ContainerNot set
Master.ContainerEnvEnvironment variables for Jenkins ContainerNot set
Master.ServiceTypek8s service typeLoadBalancer
Master.ServicePortk8s service port8080
Master.NodePortk8s node portNot set
Master.ContainerPortMaster listening port8080
Master.SlaveListenerPortListening port for agents50000
Master.LoadBalancerSourceRangesAllowed inbound IP addresses0.0.0.0/0
Master.LoadBalancerIPOptional fixed external IPNot set
Master.JMXPortOpen a port, for JMX statsNot set
Master.CustomConfigMapUse a custom ConfigMapfalse
Master.AdditionalConfigAdd additional config files{}
Master.Ingress.AnnotationsIngress annotations{}
Master.Ingress.TLSIngress TLS configuration[]
Master.InitScriptsList of Jenkins init scriptsNot set
Master.InstallPluginsList of Jenkins plugins to installkubernetes:0.11 workflow-aggregator:2.5 credentials-binding:1.11 git:3.2.0
Master.ScriptApprovalList of groovy functions to approveNot set
Master.NodeSelectorNode labels for pod assignment{}
Master.TolerationsToleration labels for pod assignment{}
rbac.installCreate service account and ClusterRoleBinding for Kubernetes pluginfalse
rbac.apiVersionRBAC API versionv1beta1
rbac.roleRefCluster role name to bind tocluster-admin

Jenkins Agent

ParameterDescriptionDefault
Agent.AlwaysPullImageAlways pull agent container image before buildfalse
Agent.EnabledEnable Kubernetes plugin jnlp-agent podTemplatetrue
Agent.ImageAgent image namejenkinsci/jnlp-slave
Agent.ImageTagAgent image tag2.62
Agent.PrivilegedAgent privileged containerfalse
Agent.CpuAgent requested cpu200m
Agent.MemoryAgent requested memory256Mi
Agent.volumesAdditional volumesnil

Specify each parameter using the --set key=value[,key=value] argument to helm install.

Alternatively, a YAML file that specifies the values for the parameters can be provided while installing the chart. For example,

$ helm install --name my-release -f values.yaml stable/jenkins

Tip: You can use the default values.yaml

Mounting volumes into your Agent pods

Your Jenkins Agents will run as pods, and it's possible to inject volumes where needed:

Agent:
  volumes:
  - type: Secret
    secretName: jenkins-mysecrets
    mountPath: /var/run/secrets/jenkins-mysecrets

The suported volume types are: ConfigMap, EmptyDir, HostPath, Nfs, Pod, Secret. Each type supports a different set of configurable attributes, defined by the corresponding Java class.

NetworkPolicy

To make use of the NetworkPolicy resources created by default, install a networking plugin that implements the Kubernetes NetworkPolicy spec.

For Kubernetes v1.5 & v1.6, you must also turn on NetworkPolicy by setting the DefaultDeny namespace annotation. Note: this will enforce policy for all pods in the namespace:

kubectl annotate namespace default "net.beta.kubernetes.io/network-policy={\"ingress\":{\"isolation\":\"DefaultDeny\"}}"

Adding customized securityRealm

Master.SecurityRealm in values can be used to support custom security realm instead of default LegacySecurityRealm. For example, you can add a security realm to authenticate via keycloak.

SecurityRealm: |-
 <securityRealm class="org.jenkinsci.plugins.oic.OicSecurityRealm" plugin="[email protected]">
   <clientId>testId</clientId>
   <clientSecret>testsecret</clientSecret>
   <tokenServerUrl>https:testurl</tokenServerUrl>
   <authorizationServerUrl>https:testAuthUrl</authorizationServerUrl>
   <userNameField>email</userNameField>
   <scopes>openid email</scopes>
 </securityRealm>

Adding additional configs

Master.AdditionalConfig can be used to add additional config files in config.yaml. For example, it can be used to add additional config files for keycloak authentication.

AdditionalConfig:
 testConfig.txt: |-
   - name: testName
     clientKey: testKey
     clientURL: testUrl

Adding customized labels

Master.ServiceLabels can be used to add custom labels in jenkins-master-svc.yaml. For example,

ServiceLabels:
 expose: true

Persistence

The Jenkins image stores persistence under /var/jenkins_home path of the container. A dynamically managed Persistent Volume Claim is used to keep the data across deployments, by default. This is known to work in GCE, AWS, and minikube. Alternatively, a previously configured Persistent Volume Claim can be used.

It is possible to mount several volumes using Persistence.volumes and Persistence.mounts parameters.

Persistence Values

ParameterDescriptionDefault
Persistence.EnabledEnable the use of a Jenkins PVCtrue
Persistence.ExistingClaimProvide the name of a PVCnil
Persistence.AccessModeThe PVC access modeReadWriteOnce
Persistence.SizeThe size of the PVC8Gi
Persistence.volumesAdditional volumesnil
Persistence.mountsAdditional mountsnil

Existing PersistentVolumeClaim

  1. Create the PersistentVolume
  2. Create the PersistentVolumeClaim
  3. Install the chart
$ helm install --name my-release --set Persistence.ExistingClaim=PVC_NAME stable/jenkins

Custom ConfigMap

When creating a new chart with this chart as a dependency, CustomConfigMap can be used to override the default config.xml provided. It also allows for providing additional xml configuration files that will be copied into /var/jenkins_home. In the parent chart's values.yaml, set the value to true and provide the file templates/config.yaml for your use case. If you start by copying config.yaml from this chart and want to access values from this chart you must change all references from .Values to .Values.jenkins.

jenkins:
  Master:
    CustomConfigMap: true

RBAC

If running upon a cluster with RBAC enabled you will need to do the following:

  • helm install stable/jenkins --set rbac.install=true
  • Create a Jenkins credential of type Kubernetes service account with service account name provided in the helm status output.
  • Under configure Jenkins -- Update the credentials config in the cloud section to use the service account credential you created in the step above.

Running behind a forward proxy

The master pod uses an Init Container to install plugins etc. If you are behind a corporate proxy it may be useful to set Master.InitContainerEnv to add environment variables such as http_proxy, so that these can be downloaded.

Additionally, you may want to add env vars for the Jenkins container, and the JVM (Master.JavaOpts).

Master:
  InitContainerEnv:
    - name: http_proxy
      value: "http://192.168.64.1:3128"
    - name: https_proxy
      value: "http://192.168.64.1:3128"
    - name: no_proxy
      value: ""
  ContainerEnv:
    - name: http_proxy
      value: "http://192.168.64.1:3128"
    - name: https_proxy
      value: "http://192.168.64.1:3128"
  JavaOpts: 

Deploy jenkins with OpenTenant

Each tenant gets its own release of this chart, with its own namespace, secrets and domain. The builder below already has jenkins on a Hetzner server. Change the host, add apps from the marketplace, then copy the generated files. Providers and prices are samples, and nothing here is sent anywhere.

  1. Pick a serverConnect Hetzner, OVHcloud or AWS. The builder starts on Hetzner, the cheapest sample rate.
  2. Place the chartjenkins is pinned at v0.10.38 in opentenant.yaml. Drag more apps from the marketplace onto a rack.
  3. ApplySave opentenant.yaml and main.tf from the console, then run the commands below.
# opentenant.yaml, main.tf and dns.tf come from the builder below
opentenant validate opentenant.yaml
terraform init && terraform apply