linux注册

下载二进制文件
curl -L --output /usr/local/bin/gitlab-runner https://gitlab-runner-downloads.s3.amazonaws.com/latest/binaries/gitlab-runner-linux-amd64

授予行权限
chmod +x /usr/local/bin/gitlab-runner

创建Gitlab用户
useradd --comment 'GitLab Runner' --create-home gitlab-runner --shell /bin/bash

安装服务
gitlab-runner install --user=gitlab-runner --working-directory=/home/gitlab-runner

注册runner
gitlab-runner register
如果遇到证书不被信任(x509错误,加上--tls-ca-file=crt证书参数)

填写gitlab信息,gitlab-hosts和gitlab-token在gitlab-web界面获取
(相关项目-Settings-CI/CD-Runners-Expand)

gitlab-hosts
gitlab-token
部门 
自定义
标签 
自定义
执行交互方式

回到gitlab-web界面查看Runner状态,步骤和上面的一样
(相关项目->Settings->CI/CD->Runners->Expand)

绿色原点表明启动成功
灰色感叹号表明启动失败

docker方式注册

创建runner容器

docker创建容器

mkdir /gitlab-runner-docker
docker run -d --name gitlab-runner-docker --restart always \

-v /gitlab-runner-docker/config:/etc/gitlab-runner \
-v /var/run/docker.sock:/var/run/docker.sock \
gitlab/gitlab-runner:latest

docker-compose创建容器

mkdir /gitlab-runner-docker
cd /gitlab-runner-docker
vim docker-compose.yml

version: "1"
services:
  app:
    image: gitlab/gitlab-runner
    container_name: gitlab-runner-docker
    restart: always
    volumes:
      - ./config:/etc/gitlab-runner
      - /var/run/docker.sock:/var/run/docker.sock

docker-compose up --build -d

注册runner

docker exec -it gitlab-runner-docker gitlab-runner register
如果遇到证书不被信任(x509错误,加上--tls-ca-file=crt证书参数),在/gitlab-runner-docker/config文件下存放着容器的runner配置,将证书存放到/gitlab-runner-docker/config
如果是内网环境,记得往容器内部添加dns解析或者hosts映射

gitlab-hosts
gitlab-token
部门 
自定义
标签 
自定义
执行交互方式
默认使用镜像

回到gitlab-web界面查看Runner状态,步骤和上面的一样
(相关项目->Settings->CI/CD->Runners->Expand)

绿色原点表明启动成功
灰色感叹号表明启动失败

k8s方式注册

安装helm

wget https://get.helm.sh/helm-v3.3.4-linux-amd64.tar.gz
tar -zxvf helm-v3.3.4-linux-amd64.tar.gz
mv linux-amd64/helm /usr/local/bin/helm
chmod +x /usr/local/bin/helm

配置helm

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

下载配置gitlab-runner charts

helm pull gitlab/gitlab-runner
tar -zxvf gitlab-runner-0.12.0.tgz
kubectl create namespace gitlab-runners

vim rabc-runner-config.yaml

apiVersion: v1
kind: ServiceAccount
metadata:
  name: gitlab
  namespace: gitlab-runners
---
kind: Role
apiVersion: rbac.authorization.k8s.io/v1
metadata:
  namespace: gitlab-runners
  name: gitlab
rules:
- apiGroups: [""] #"" indicates the core API group
  resources: ["*"]
  verbs: ["*"]
- apiGroups: ["apps"]
  resources: ["deployments"]
  verbs: ["*"]
---
kind: RoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
  name: gitlab
  namespace: gitlab-runners
subjects:
- kind: ServiceAccount
  name: gitlab # Name is case sensitive
  apiGroup: ""
roleRef:
  kind: Role #this must be Role or ClusterRole
  name: gitlab # this must match the name of the Role or ClusterRole you wish to bind to
  apiGroup: rbac.authorization.k8s.io


kubectl create -f rbac-runner-config.yaml
vim gitlab-runner/values.yaml

## 拉取策略, 先取本地镜像
imagePullPolicy: IfNotPresent
#gitlab地址
gitlabUrl: https://gitlaburl
runnerRegistrationToken: "qzxposxDst_Nnq5MMnPf"
# 和之前配置的 rbac name 对应
rbac:
  serviceAccountName: gitlab
#runner标签
tags: "gitlab-runner-k8s"

privileged: true

serviceAccountName: gitlab
#自行添加解析
hostAliases:
  - ip: "127.0.0.1"
    hostnames:
    - "gitlaburl"

部署&注册

helm install gitlab-runner gitlab/gitlab-runner -f values.yaml --namespace gitlab-runners