高哲技术博客 高哲技术博客
首页
编程
爬虫
运维
硬件
收藏
归档
关于

嘉美伯爵

前途光明,无需畏惧
首页
编程
爬虫
运维
硬件
收藏
归档
关于
  • 方案

  • 数据库

  • 虚拟化

  • 自动化部署

    • CI

      • 什么是持续集成
      • gitlab runner安装教程及使用(k8s)
        • 下载gitlab-runner
        • 配置 helm
        • 安装
        • 配置权限
        • k8s配置文件
        • docker 配置文件
        • helm 目录
        • 优化
        • 参数
        • 参考
      • Jenkins在持续集成(CI)中的应用
      • gitlab runner原理篇
    • CD

    • k8s

    • 构建

  • 中间件

  • 可观测

  • 操作系统

  • 运维
  • 自动化部署
  • CI
fovegage
2023-07-12
目录

gitlab runner安装教程及使用(k8s)

# 下载gitlab-runner

helm repo add gitlab https://charts.gitlab.io
helm repo list
# 下载到本地
helm fetch gitlab/gitlab-runner
# 解压
tar xf gitlab-runner-0.54.0.tgz
1
2
3
4
5
6

# 配置 helm

vi gitlab-runner/values.yaml
# 只需要修改下面的两个配置即可
gitlabUrl: "https://jh-xiaomage.gitlab.cn"  #设置为自己的gitlab地址
runnerRegistrationToken: "sFV-HEkLC_NgH2vLALfG"  #填写对应的注册令牌
1
2
3
4

# 安装

# 创建命名空间
kubectl create ns devops

# 安装
helm install gitlab-runner ./gitlab-runner --values ./gitlab-runner/values.yaml -n devops

# 更新
helm upgrade  gitlab-runner gitlab-runner  -f ./gitlab-runner/values.yaml -n devops

# 输出
root@kbmaster:~# helm install gitlab-runner ./gitlab-runner --values ./gitlab-runner/values.yaml 
NAME: gitlab-runner
LAST DEPLOYED: Wed Jul 12 15:31:09 2023
NAMESPACE: default
STATUS: deployed
REVISION: 1
TEST SUITE: None
NOTES:
Your GitLab Runner should now be registered against the GitLab instance reachable at: "http://git.hongyuan.com/"

Runner namespace "default" was found in runners.config template.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21

# 配置权限

vi gitlab-runner/values.yaml

## GitLab Runner Image
gitlabUrl: http://example.domain/
runnerRegistrationToken: "<token>"

rbac:
  create: true
  rules:
    - apiGroups: [""]
      resources: ["pods"]
      verbs: ["list", "get", "watch", "create", "delete"]
    - apiGroups: [""]
      resources: ["pods/exec"]
      verbs: ["create"]
    - apiGroups: [""]
      resources: ["pods/log"]
      verbs: ["get"]
    - apiGroups: [""]
      resources: ["pods/attach"]
      verbs: ["list", "get", "create", "delete", "update"]
    - apiGroups: [""]
      resources: ["secrets"]
      verbs: ["list", "get", "create", "delete", "update"]      
    - apiGroups: [""]
      resources: ["configmaps"]
      verbs: ["list", "get", "create", "delete", "update"]      

runners:
  privileged: true
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

# k8s配置文件

config: |
  [[runners]]
    name = "runner"
    url = "http://git.hongyuan.com/"
    token = "xyMegqUefLfKz3dc7x7y"
    executor = "kubernetes"
    [runners.kubernetes]
      namespace = "devops"
      image = "ubuntu:22.04"
      privileged = true
      [runners.kubernetes.volumes]
        [[runners.kubernetes.volumes.host_path]]
          name = "docker-sock"
          mount_path = "/var/run/docker.sock"
          host_path = "/var/run/docker.sock"
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

# docker 配置文件

concurrent = 5
check_interval = 5

[session_server]
session_timeout = 1800

[[runners]]
  name = "spider-docker-runner"
  url = "http://git.xxx.com/"
  token = "xxx"
  executor = "docker"
  [runners.custom_build_dir]
  [runners.cache]
    Type = "s3"
    Path = "prefix"
    Shared = false
  [runners.cache.s3]
    ServerAddress = "10.6.16.32:31001"
    AccessKey = "minioadmin"
    SecretKey = "minioadmin"
    BucketName = "gitlab-runner"
    InSecure = true
  [runners.docker]
    tls_verify = false
    image = "alpine:latest"
    privileged = true
    disable_entrypoint_overwrite = false
    oom_kill_disable = false
    disable_cache = false
    volumes = ["/cache", "/var/run/docker.sock:/var/run/docker.sock", "/data/.m2/:/.m2/"]
    pull_policy = "if-not-present"
    shm_size = 0
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

# helm 目录

root@kbmaster:~/gitlab-runner# tree
.
├── CHANGELOG.md
├── Chart.yaml
├── CONTRIBUTING.md
├── DEVELOPMENT.md
├── LICENSE
├── Makefile
├── NOTICE
├── README.md
├── templates
│   ├── configmap.yaml
│   ├── deployment.yaml
│   ├── _env_vars.tpl
│   ├── _helpers.tpl
│   ├── hpa.yaml
│   ├── NOTES.txt
│   ├── role-binding.yaml
│   ├── role.yaml
│   ├── secrets.yaml
│   ├── service-account.yaml
│   ├── servicemonitor.yaml
│   ├── service-session-server.yaml
│   └── service.yaml
└── values.yaml
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

# 优化

# 配置minio缓存  (注意 minio两个端口 需要在数据端口,否则会存不进去)
[runners.cache]
  Type = "s3"
  Path = "prefix"
  Shared = false
  [runners.cache.s3]
    ServerAddress = "172.17.0.4:9000"
    AccessKey = "12345678"
    SecretKey = "87654321"
    BucketName = "fizz-minio"
Insecure = true
1
2
3
4
5
6
7
8
9
10
11

# 参数

concurrent	限制可以同时运行的作业数量
log_level	日志级别
log_format	日志格式
check_interval	检查新作业的间隔长度,默认为3秒
sentry_dsn	启用Sentry错误跟踪
listen_address	http服务监听地址
1
2
3
4
5
6

# 参考

  • 部署 GitLab Runner (opens new window)
  • GitLab-Runner配置参数详解 (opens new window)
  • Go + Docker技巧-私人仓库和Gitlab CI (opens new window)
  • GitLab Runner 配置分布式缓存MinIO (opens new window)
  • 极狐GitLab CI/CD 作业令牌 (opens new window)
  • 在kubernetes安装gitlab-runner (opens new window)
  • 配置GitLab Runner跑CI (opens new window)
  • Not able to execute GitLab Runner in Kubernetes cluster: cannot create resource "secrets" in API group "" in the namespace "gitlab" (opens new window)
上次更新: 2023-07-31 10:01:32
什么是持续集成
Jenkins在持续集成(CI)中的应用

← 什么是持续集成 Jenkins在持续集成(CI)中的应用→

最近更新
01
token embed和postion embed
06-10
02
k8s pod日志排查问题
10-24
03
golang内部私服建设方案
10-21
更多文章>
Theme by Vdoing | Copyright © 2018-2025 嘉美伯爵 | 鲁ICP备20001560号-4
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式