Helm版本GitLab Runner搭建使用

准备

已经安装运行一个 Kubernetes 集群。

安装Helm Client

本来想用一键安装脚本安装的,无奈网络太慢

所以先下载 helm 的压缩包

1
2
3
4
5
6
7
wget https://get.helm.sh/helm-v2.14.0-linux-amd64.tar.gz

# 解压
tar -zxvf helm-v2.0.0-linux-amd64.tgz

# 移动到/usr/bin目录下
mv linux-amd64/helm /usr/local/bin/helm

安装 Tiller

Tiller是 Helm 的服务器部分,通常在您的 Kubernetes 集群内部运行。但是对于开发,它也可以在本地运行,并配置为与远程 Kubernetes 集群通信。

执行下面的命令可以安装tiller

1
helm init

repo 可以是 https://kubernetes.oss-cn-hangzhou.aliyuncs.com/charts

指定更多的参数

  • --tiller-image: 指定 tiller 的镜像,因为默认是取的google镜像仓库,需要翻墙,可以去 阿里云镜像仓库找找
    (https://cr.console.aliyun.com/cn-hangzhou/instances/repositories)

  • --tiller-namespace: 指定安装到哪个 namespace

  • --kube-context: 制定安装到哪个K8S集群
  • --service-account: 指定 tiller 的 ServiceAccount

PS:如果直接 helm init安装的,可以看到镜像拉不下来,可以去阿里镜像仓库找对应的版本拉到对应的运行节点上,然后给这个镜像重新 tag 一下。

安装完可以使用下面的命令看到 helm 的版本。

1
2
3
[root@node9 gitlab-runner]# helm version
Client: &version.Version{SemVer:"v2.14.0", GitCommit:"05811b84a3f93603dd6c2fcfe57944dfa7ab7fd0", GitTreeState:"clean"}
Server: &version.Version{SemVer:"v2.14.0", GitCommit:"05811b84a3f93603dd6c2fcfe57944dfa7ab7fd0", GitTreeState:"clean"}

Helm 安装 Gitlab Runner

先使用下面的命令给 tiller 授个权

1
2
3
4
5
kubectl create serviceaccount --namespace kube-system tiller

kubectl create clusterrolebinding tiller-cluster-rule --clusterrole=cluster-admin --serviceaccount=kube-system:tiller

kubectl patch deploy --namespace kube-system tiller-deploy -p '{"spec":{"template":{"spec":{"serviceAccount":"tiller"}}}}'

配置 chart 需要的配置文件

values.yml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
## The GitLab Server URL (with protocol) that want to register the runner against
## ref: https://docs.gitlab.com/runner/commands/README.html#gitlab-runner-register
##
gitlabUrl: https://gitlab.example.com/

## The registration token for adding new Runners to the GitLab server. This must
## be retrieved from your GitLab instance.
## ref: https://docs.gitlab.com/ee/ci/runners/
##
runnerRegistrationToken: ""

## Set the certsSecretName in order to pass custom certificates for GitLab Runner to use
## Provide resource name for a Kubernetes Secret Object in the same namespace,
## this is used to populate the /etc/gitlab-runner/certs directory
## ref: https://docs.gitlab.com/runner/configuration/tls-self-signed.html#supported-options-for-self-signed-certificates
##
#certsSecretName:

## Configure the maximum number of concurrent jobs
## ref: https://docs.gitlab.com/runner/configuration/advanced-configuration.html#the-global-section
##
concurrent: 10

## Defines in seconds how often to check GitLab for a new builds
## ref: https://docs.gitlab.com/runner/configuration/advanced-configuration.html#the-global-section
##
checkInterval: 30

## For RBAC support:
rbac:
create: false

## Run the gitlab-bastion container with the ability to deploy/manage containers of jobs
## cluster-wide or only within namespace
clusterWideAccess: false

## If RBAC is disabled in this Helm chart, use the following Kubernetes Service Account name.
##
# serviceAccountName: default

## Configuration for the Pods that the runner launches for each new job
##
runners:
## Default container image to use for builds when none is specified
##
image: apline:3.9

## Run all containers with the privileged flag enabled
## This will allow the docker:stable-dind image to run if you need to run Docker
## commands. Please read the docs before turning this on:
## ref: https://docs.gitlab.com/runner/executors/kubernetes.html#using-docker-dind
##
privileged: false

## Namespace to run Kubernetes jobs in (defaults to 'default')
##
# namespace:

## Build Container specific configuration
##
builds:
# cpuLimit: 200m
# memoryLimit: 256Mi
cpuRequests: 100m
memoryRequests: 128Mi

## Service Container specific configuration
##
services:
# cpuLimit: 200m
# memoryLimit: 256Mi
cpuRequests: 100m
memoryRequests: 128Mi

## Helper Container specific configuration
##
helpers:
# cpuLimit: 200m
# memoryLimit: 256Mi
cpuRequests: 100m
memoryRequests: 128Mi
  • gitlabUrl: 配置gitlab的地址
  • runnerRegistrationToken: 项目的token,Settings -> CI/CD -> Runners 里面能看到
  • concurrent: 部署在 Kubernetes 上的单个 GitLab Runner 能够通过自动启动其他 Runner pod 来并行执行多个作业。并发设置控制一次允许的最大pod数,默认为10
  • rbac.create: 配置为false自动创建
  • runners.image: job 默认镜像
  • runners.privileged: 需要在 job 里面用 docker 环境就配置为 true 吧。

使用如下命令添加 HelmChart 仓库

1
helm repo add gitlab https://charts.gitlab.io

先创建 gitlab 这个名称空间

1
kubectl create namespace gitlab

使用 Helm Chart 安装 GitLab Runner

1
helm install --namespace gitlab --name gitlab-runner -f values.yml gitlab/gitlab-runner

安装完成之后可以在 Settings->CI/CD->Runner 看到新建的 Runner,可以在当前页面编辑 Runner 给这个 Runner 打上一些 tag。

使用 Helm Chart 更新 GitLab Runner

先使用如下命令查看 release name

1
2
3
[root@node9 ~]# helm list
NAME REVISION UPDATED STATUS CHART APP VERSION NAMESPACE
gitlab-runner 2 Thu Jun 6 14:44:23 2019 DEPLOYED gitlab-runner-0.5.2 11.11.2 gitlab
1
helm upgrade --namespace gitlab -f values.yml gitlab gitlab/gitlab-runner

使用 Helm Chart 删除 GitLab Runner

1
helm delete --namespace <NAMESPACE> <RELEASE-NAME>

参考链接