1、add gitlab helm repo

  1. $ helm repo add gitlab https://charts.gitlab.io
  2. # For Helm 3
  3. $ helm install --namespace <NAMESPACE> gitlab-runner -f <CONFIG_VALUES_FILE> gitlab/gitlab-runner

2、upgrade gitlab runner chart

Once your GitLab Runner Chart is installed, configuration changes and chart updates should be done using helm upgrade:

  1. $ helm upgrade --namespace <NAMESPACE> -f <CONFIG_VALUES_FILE> <RELEASE-NAME> gitlab/gitlab-runner

3、Check available GitLab Runner Helm Chart versions

  1. # For Helm 3
  2. helm search repo -l gitlab/gitlab-runner

4、Configuring GitLab Runner using the Helm Chart

ref: https://gitlab.com/gitlab-org/charts/gitlab-runner/blob/main/values.yaml

4.1、必须配置

For GitLab Runner to function, your configuration file must specify the following:

gitlabUrl - the GitLab server full URL (e.g., https://gitlab.example.com)) to register the runner against.

runnerRegistrationToken - The registration token for adding new runners to GitLab. This must be retrieved from your GitLab instance.

4.2、可选配置

Using cache with configuration template
To use the cache with your configuration template, set the following variables in values.yaml:

runners.cache.secretName with the secret name for your object storage provider (s3access, gcsaccess, google-application-credentials, or azureaccess).
runners.config with the other settings for the cache. Use toml formatting.

S3

  1. runners:
  2. config: |
  3. [[runners]]
  4. [runners.kubernetes]
  5. image = "ubuntu:16.04"
  6. [runners.cache]
  7. Type = "s3"
  8. Path = "runner"
  9. Shared = true
  10. [runners.cache.s3]
  11. ServerAddress = "s3.amazonaws.com"
  12. BucketName = "my_bucket_name"
  13. BucketLocation = "eu-west-1"
  14. Insecure = false
  15. cache:
  16. secretName: s3access

Next, create an s3access Kubernetes secret that contains accesskey and secretkey:

  1. $ kubectl create secret generic s3access \
  2. --from-literal=accesskey="YourAccessKey" \
  3. --from-literal=secretkey="YourSecretKey"

其他可选配置参考:https://docs.gitlab.com/runner/install/kubernetes.html

完整value.yaml参考:

  1. ## GitLab Runner Image
  2. ##
  3. ## By default it's using gitlab/gitlab-runner:alpine-v{VERSION}
  4. ## where {VERSION} is taken from Chart.yaml from appVersion field
  5. ##
  6. ## ref: https://hub.docker.com/r/gitlab/gitlab-runner/tags/
  7. ##
  8. #image: gitlab/gitlab-runner:alpine
  9. image: registry.cn-beijing.aliyuncs.com/xljc-proxy/gitlab-runner:alpine
  10. ## Specify a imagePullPolicy
  11. ## 'Always' if imageTag is 'latest', else set to 'IfNotPresent'
  12. ## ref: http://kubernetes.io/docs/user-guide/images/#pre-pulling-images
  13. ##
  14. imagePullPolicy: Always
  15. ## The GitLab Server URL (with protocol) that want to register the runner against
  16. ## ref: https://docs.gitlab.com/runner/commands/README.html#gitlab-runner-register
  17. ##
  18. gitlabUrl: http://gitlab.xljc.art/
  19. ## The Registration Token for adding new Runners to the GitLab Server. This must
  20. ## be retrieved from your GitLab Instance.
  21. ## ref: https://docs.gitlab.com/ce/ci/runners/README.html
  22. ##
  23. runnerRegistrationToken: "Wzb_***v_z5A"
  24. ## The Runner Token for adding new Runners to the GitLab Server. This must
  25. ## be retrieved from your GitLab Instance. It is token of already registered runner.
  26. ## ref: (we don't yet have docs for that, but we want to use existing token)
  27. ##
  28. # runnerToken: ""
  29. #
  30. ## Unregister all runners before termination
  31. ##
  32. ## Updating the runner's chart version or configuration will cause the runner container
  33. ## to be terminated and created again. This may cause your Gitlab instance to reference
  34. ## non-existant runners. Un-registering the runner before termination mitigates this issue.
  35. ## ref: https://docs.gitlab.com/runner/commands/README.html#gitlab-runner-unregister
  36. ##
  37. unregisterRunners: true
  38. ## When stopping ther runner, give it time to wait for it's jobs to terminate.
  39. ##
  40. ## Updating the runner's chart version or configuration will cause the runner container
  41. ## to be terminated with a graceful stop request. terminationGracePeriodSeconds
  42. ## instructs Kubernetes to wait long enough for the runner pod to terminate gracefully.
  43. ## ref: https://docs.gitlab.com/runner/commands/#signals
  44. terminationGracePeriodSeconds: 3600
  45. ## Set the certsSecretName in order to pass custom certficates for GitLab Runner to use
  46. ## Provide resource name for a Kubernetes Secret Object in the same namespace,
  47. ## this is used to populate the /home/gitlab-runner/.gitlab-runner/certs/ directory
  48. ## ref: https://docs.gitlab.com/runner/configuration/tls-self-signed.html#supported-options-for-self-signed-certificates
  49. ##
  50. # certsSecretName:
  51. ## Configure the maximum number of concurrent jobs
  52. ## ref: https://docs.gitlab.com/runner/configuration/advanced-configuration.html#the-global-section
  53. ##
  54. concurrent: 10
  55. ## Defines in seconds how often to check GitLab for a new builds
  56. ## ref: https://docs.gitlab.com/runner/configuration/advanced-configuration.html#the-global-section
  57. ##
  58. checkInterval: 30
  59. ## Configure GitLab Runner's logging level. Available values are: debug, info, warn, error, fatal, panic
  60. ## ref: https://docs.gitlab.com/runner/configuration/advanced-configuration.html#the-global-section
  61. ##
  62. # logLevel:
  63. ## Configure GitLab Runner's logging format. Available values are: runner, text, json
  64. ## ref: https://docs.gitlab.com/runner/configuration/advanced-configuration.html#the-global-section
  65. ##
  66. # logFormat:
  67. ## For RBAC support:
  68. rbac:
  69. create: true
  70. ## Define specific rbac permissions.
  71. # resources: ["pods", "pods/exec", "secrets"]
  72. # verbs: ["get", "list", "watch", "create", "patch", "delete"]
  73. ## Run the gitlab-bastion container with the ability to deploy/manage containers of jobs
  74. ## cluster-wide or only within namespace
  75. clusterWideAccess: true
  76. ## Use the following Kubernetes Service Account name if RBAC is disabled in this Helm chart (see rbac.create)
  77. ##
  78. # serviceAccountName: default
  79. ## Configure integrated Prometheus metrics exporter
  80. ## ref: https://docs.gitlab.com/runner/monitoring/#configuration-of-the-metrics-http-server
  81. metrics:
  82. enabled: true
  83. ## Configuration for the Pods that that the runner launches for each new job
  84. ##
  85. runners:
  86. ## Default container image to use for builds when none is specified
  87. ##
  88. config: |
  89. [[runners]]
  90. [runners.kubernetes]
  91. image = "ubuntu:16.04"
  92. [runners.cache]
  93. Type = "s3"
  94. Shared = false
  95. [runners.cache.s3]
  96. ServerAddress = "minio-storage.infra.svc.cluster.local:9000"
  97. AccessKey = "LTAI4Fh****1rWf"
  98. SecretKey = "d3vu*****HdVYG"
  99. BucketName = "gitlab-runner-caches"
  100. Insecure = false
  101. # image: maven:3-jdk-8
  102. image: registry.cn-******/maven:3-jdk-8
  103. ## Specify one or more imagePullSecrets
  104. ##
  105. ## ref: https://kubernetes.io/docs/tasks/configure-pod-container/pull-image-private-registry/
  106. ##
  107. imagePullSecrets:
  108. - name: dockerconfig
  109. ## Specify the image pull policy: never, if-not-present, always. The cluster default will be used if not set.
  110. ##
  111. imagePullPolicy: "always"
  112. ## Defines number of concurrent requests for new job from GitLab
  113. ## ref: https://docs.gitlab.com/runner/configuration/advanced-configuration.html#the-runners-section
  114. ##
  115. requestConcurrency: 1
  116. ## Specify whether the runner should be locked to a specific project: true, false. Defaults to true.
  117. ##
  118. # locked: true
  119. ## Specify the tags associated with the runner. Comma-separated list of tags.
  120. ##
  121. ## ref: https://docs.gitlab.com/ce/ci/runners/#using-tags
  122. ##
  123. tags: "jdk,maven,jdk-8,k8s,golang,go"
  124. ## Specify if jobs without tags should be run.
  125. ## If not specified, Runner will default to true if no tags were specified. In other case it will
  126. ## default to false.
  127. ##
  128. ## ref: https://docs.gitlab.com/ce/ci/runners/#allowing-runners-with-tags-to-pick-jobs-without-tags
  129. ##
  130. runUntagged: false
  131. ## Specify whether the runner should only run protected branches.
  132. ## Defaults to False.
  133. ##
  134. ## ref: https://docs.gitlab.com/ee/ci/runners/#protected-runners
  135. ##
  136. # protected: true
  137. ## Run all containers with the privileged flag enabled
  138. ## This will allow the docker:dind image to run if you need to run Docker
  139. ## commands. Please read the docs before turning this on:
  140. ## ref: https://docs.gitlab.com/runner/executors/kubernetes.html#using-docker-dind
  141. ##
  142. privileged: false
  143. ## The name of the secret containing runner-token and runner-registration-token
  144. # secret: gitlab-runner
  145. ## Namespace to run Kubernetes jobs in (defaults to the same namespace of this release)
  146. ##
  147. namespace: cicd
  148. ## The amount of time, in seconds, that needs to pass before the runner will
  149. ## timeout attempting to connect to the container it has just created.
  150. ## ref: https://docs.gitlab.com/runner/executors/kubernetes.html
  151. pollTimeout: 180
  152. ## Set maximum build log size in kilobytes, by default set to 4096 (4MB)
  153. ## ref: https://docs.gitlab.com/runner/configuration/advanced-configuration.html#the-runners-section
  154. outputLimit: 4096
  155. ## Distributed runners caching
  156. ## ref: https://gitlab.com/gitlab-org/gitlab-runner/blob/master/docs/configuration/autoscale.md#distributed-runners-caching
  157. ##
  158. ## If you want to use s3 based distributing caching:
  159. ## First of all you need to uncomment General settings and S3 settings sections.
  160. ##
  161. ## Create a secret 's3access' containing 'accesskey' & 'secretkey'
  162. ## ref: https://aws.amazon.com/blogs/security/wheres-my-secret-access-key/
  163. ##
  164. ## $ kubectl create secret generic s3access \
  165. ## --from-literal=accesskey="YourAccessKey" \
  166. ## --from-literal=secretkey="YourSecretKey"
  167. ## ref: https://kubernetes.io/docs/concepts/configuration/secret/
  168. ##
  169. ## If you want to use gcs based distributing caching:
  170. ## First of all you need to uncomment General settings and GCS settings sections.
  171. ##
  172. ## Access using credentials file:
  173. ## Create a secret 'google-application-credentials' containing your application credentials file.
  174. ## ref: https://docs.gitlab.com/runner/configuration/advanced-configuration.html#the-runnerscachegcs-section
  175. ## You could configure
  176. ## $ kubectl create secret generic google-application-credentials \
  177. ## --from-file=gcs-applicaton-credentials-file=./path-to-your-google-application-credentials-file.json
  178. ## ref: https://kubernetes.io/docs/concepts/configuration/secret/
  179. ##
  180. ## Access using access-id and private-key:
  181. ## Create a secret 'gcsaccess' containing 'gcs-access-id' & 'gcs-private-key'.
  182. ## ref: https://docs.gitlab.com/runner/configuration/advanced-configuration.html#the-runners-cache-gcs-section
  183. ## You could configure
  184. ## $ kubectl create secret generic gcsaccess \
  185. ## --from-literal=gcs-access-id="YourAccessID" \
  186. ## --from-literal=gcs-private-key="YourPrivateKey"
  187. ## ref: https://kubernetes.io/docs/concepts/configuration/secret/
  188. cache:
  189. ## General settings
  190. cacheType: s3
  191. cachePath: ""
  192. cacheShared: true
  193. ## S3 settings
  194. s3ServerAddress: minio-storage.infra.svc.cluster.local:9000
  195. s3BucketName: gitlab-runner-caches
  196. # s3BucketLocation:
  197. s3CacheInsecure: true
  198. secretName: gitlab-runner-cache-access
  199. ## GCS settings
  200. # gcsBucketName:
  201. ## Use this line for access using access-id and private-key
  202. # secretName: gcsaccess
  203. ## Use this line for access using google-application-credentials file
  204. # secretName: google-application-credentials
  205. ## Build Container specific configuration
  206. ##
  207. builds: {}
  208. # cpuLimit: 200m
  209. # memoryLimit: 256Mi
  210. # cpuRequests: 100m
  211. # memoryRequests: 128Mi
  212. ## Service Container specific configuration
  213. ##
  214. services: {}
  215. # cpuLimit: 200m
  216. # memoryLimit: 256Mi
  217. # cpuRequests: 100m
  218. # memoryRequests: 128Mi
  219. ## Helper Container specific configuration
  220. ##
  221. helpers:
  222. # cpuLimit: 200m
  223. # memoryLimit: 256Mi
  224. # cpuRequests: 100m
  225. # memoryRequests: 128Mi
  226. # image: gitlab/gitlab-runner-helper:x86_64-latest
  227. image: registry.cn-****/gitlab-runner-helper:x86_64-latest
  228. ## Service Account to be used for runners
  229. ##
  230. # serviceAccountName:
  231. serviceAccountOverwriteAllowed: "gitlab-ci"
  232. ## If Gitlab is not reachable through $CI_SERVER_URL
  233. ##
  234. # cloneUrl:
  235. ## Specify node labels for CI job pods assignment
  236. ## ref: https://kubernetes.io/docs/concepts/configuration/assign-pod-node/
  237. ##
  238. # nodeSelector: {}
  239. ## Specify pod labels for CI job pods
  240. ##
  241. # podLabels: {}
  242. ## Specify annotations for job pods, useful for annotations such as iam.amazonaws.com/role
  243. # podAnnotations: {}
  244. ## Configure environment variables that will be injected to the pods that are created while
  245. ## the build is running. These variables are passed as parameters, i.e. `--env "NAME=VALUE"`,
  246. ## to `gitlab-runner register` command.
  247. ##
  248. ## Note that `envVars` (see below) are only present in the runner pod, not the pods that are
  249. ## created for each build.
  250. ##
  251. ## ref: https://docs.gitlab.com/runner/commands/#gitlab-runner-register
  252. ##
  253. # env:
  254. # NAME: VALUE
  255. env:
  256. DOCKER_AUTH_CONFIG: '{\"auths\":{\"registry.cn-beijing.aliyuncs.com\":{\"auth\": \"5bCP57uD*****MyMDIx\"}}}'
  257. ## Configure securitycontext
  258. ## ref: http://kubernetes.io/docs/user-guide/security-context/
  259. ##
  260. securityContext:
  261. fsGroup: 65533
  262. runAsUser: 100
  263. ## Configure resource requests and limits
  264. ## ref: http://kubernetes.io/docs/user-guide/compute-resources/
  265. ##
  266. resources: {}
  267. # limits:
  268. # memory: 256Mi
  269. # cpu: 200m
  270. # requests:
  271. # memory: 128Mi
  272. # cpu: 100m
  273. ## Affinity for pod assignment
  274. ## Ref: https://kubernetes.io/docs/concepts/configuration/assign-pod-node/#affinity-and-anti-affinity
  275. ##
  276. affinity: {}
  277. ## Node labels for pod assignment
  278. ## Ref: https://kubernetes.io/docs/user-guide/node-selection/
  279. ##
  280. nodeSelector: {}
  281. # Example: The gitlab runner manager should not run on spot instances so you can assign
  282. # them to the regular worker nodes only.
  283. # node-role.kubernetes.io/worker: "true"
  284. ## List of node taints to tolerate (requires Kubernetes >= 1.6)
  285. ## Ref: https://kubernetes.io/docs/concepts/configuration/taint-and-toleration/
  286. ##
  287. tolerations: []
  288. # Example: Regular worker nodes may have a taint, thus you need to tolerate the taint
  289. # when you assign the gitlab runner manager with nodeSelector or affinity to the nodes.
  290. # - key: "node-role.kubernetes.io/worker"
  291. # operator: "Exists"
  292. ## Configure environment variables that will be present when the registration command runs
  293. ## This provides further control over the registration process and the config.toml file
  294. ## ref: `gitlab-runner register --help`
  295. ## ref: https://docs.gitlab.com/runner/configuration/advanced-configuration.html
  296. ##
  297. # envVars:
  298. ## list of hosts and IPs that will be injected into the pod's hosts file
  299. hostAliases: []
  300. # Example:
  301. # - ip: "127.0.0.1"
  302. # hostnames:
  303. # - "foo.local"
  304. # - "bar.local"
  305. # - ip: "10.1.2.3"
  306. # hostnames:
  307. # - "foo.remote"
  308. # - "bar.remote"
  309. ## Annotations to be added to manager pod
  310. ##
  311. podAnnotations: {}
  312. # Example:
  313. # iam.amazonaws.com/role: <my_role_arn>
  314. ## Labels to be added to manager pod
  315. ##
  316. podLabels: {}
  317. # Example:
  318. # owner.team: <my_cool_team>
  319. ## HPA support for custom metrics:
  320. ## This section enables runners to autoscale based on defined custom metrics.
  321. ## In order to use this functionality, Need to enable a custom metrics API server by
  322. ## implementing "custom.metrics.k8s.io" using supported third party adapter
  323. ## Example: https://github.com/directxman12/k8s-prometheus-adapter
  324. ##
  325. hpa:
  326. minReplicas: 1
  327. maxReplicas: 10
  328. metrics:
  329. - type: Pods
  330. pods:
  331. metricName: gitlab_runner_jobs
  332. targetAverageValue: 400m