惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

阮一峰的网络日志
阮一峰的网络日志
Hugging Face - Blog
Hugging Face - Blog
Recent Announcements
Recent Announcements
MongoDB | Blog
MongoDB | Blog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
G
Google Developers Blog
L
LangChain Blog
The GitHub Blog
The GitHub Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
GbyAI
GbyAI
MyScale Blog
MyScale Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
U
Unit 42
Martin Fowler
Martin Fowler
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Apple Machine Learning Research
Apple Machine Learning Research
爱范儿
爱范儿
博客园 - 聂微东
大猫的无限游戏
大猫的无限游戏
M
MIT News - Artificial intelligence
A
About on SuperTechFans
Stack Overflow Blog
Stack Overflow Blog
V
V2EX

博客园 - Morya

不当心升级到 redis 7.4 怎么回到 valkey8 使用 cert-manager 为 traefik 自动申请和续约 https 证书 traefik学习 k8s 1.28 安装配置 knative-serving v1.15.2 + cert-manager v1.16.1 ssh端口映射玩法 golang echo group 用法的微妙注意点 使用docker最小化部署Git CI环境 使用mailpopbox构建个人独享EmailServer Influx cli cheetsheet 通过php docker快速验证简单代码 通过k8s service代理外部服务 K8S配置traefik ingressroutes支持TLS ucloud k8s部署traefik的forward-auth 使用nginx构建限频、限速、限并发的应用保护层 macos 更改罗技k810无线键盘的映射 - Morya - 博客园 C++11 thread condition_variable mutex 综合使用 goland scope pattern 设置 Go 1.11 Module 介绍 - Morya hustOJ 添加 golang 支持
run gitlab-runner in k8s
Morya · 2020-08-21 · via 博客园 - Morya

run gitlab-runner in k8s

主要成果

runner运行在k8s内

  • 衍生的job同步运行在k8s同名namespace中
  • job执行时,可以直接通过命令访问到k8s其它的services
  • 使用gcr.io/kaniko-project/executor构建docker image(替换原dind[docker in docker]模型)

versions

  • Kubernetes 1.17
  • helm 3.1.2
  • gitlab 13.1.2
  • gitlab-runner 13.2.2/13.3.0

构建方式

  • install gitlab-runner with helm
    • add gitlab charts repo
    • pull gitlab-runner
    • tweak values.yaml
    • install gitlab-runner
  • tweak docker daemon
  • config git project .gitlab-ci.yml

install gitlab-runner with helm

add gitlab charts repo

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

pull gitlab-runner

helm repo update
helm pull gitlab/gitlab-runner  --untar

tweak values.yaml

imagePullPolicy: IfNotPresent
gitlabUrl: https://git.somewhere.com      ## 修改点
runnerRegistrationToken: "xxxxxxxxxxxxxx" ## 修改点
terminationGracePeriodSeconds: 3600
concurrent: 10
checkInterval: 30
rbac:
  create: true
  clusterWideAccess: false
  podSecurityPolicy:
    enabled: false
    resourceNames:
    - gitlab-runner
metrics:
  enabled: true
runners:
  image: ubuntu:16.04
  locked: false
  tags: "in-k8s-env001"    ## 修改点
  privileged: true
  pollTimeout: 1800        ## 修改点,默认值180,但是拉取官方镜像会很慢
  outputLimit: 4096
  cache: {}
  builds: {}
  services: {}
  helpers: {}
securityContext:
  fsGroup: 65533
  runAsUser: 100
resources: {}
affinity: {}
nodeSelector: {}
tolerations: []
hostAliases: []
podAnnotations: {}
podLabels: {}

install gitlab-runner

kubectl create ns gitlab
helm -n gitlab install runner gitlab/gitlab-runner --values=values.yaml

tweak docker daemon

为加速docker拉取官方镜像速度,可以调整k8s node docker daemon的配置 /etc/docker/daemon.json

{
  "registry-mirrors": ["https://xxxxxxx.mirror.aliyuncs.com"]
}

需要去阿里云自己申请加速域名

config git project .gitlab-ci.yml

stages:
  - build
  - buildImg


variables:
  GOPROXY: https://goproxy.cn
  GO111MODULE: "on"
  APP_IMAGE_ID: ${DOCKER_REGISTRY}/${CI_PROJECT_NAME}-${CI_PROJECT_ID}:$CI_COMMIT_REF_NAME-${CI_PIPELINE_ID}

build:
  stage: build
  image:
    name: "golang:1.15"
  tags:
    - in-k8s-env001
  artifacts:
    paths:
      - app
  script:
    - go build -o app


buildImg:
  stage: buildImg
  image:
    name: gcr.io/kaniko-project/executor:debug # 参考 https://docs.gitlab.com/ee/ci/docker/using_kaniko.html
    entrypoint: [""]
  tags:
    - in-k8s-env001
  script:
    - mkdir -p /kaniko/.docker
    - echo "{\"auths\":{\"$DOCKER_REGISTRY\":{\"username\":\"${DOCKER_USER}\",\"password\":\"${DOCKER_PASSWORD}\"}}}" > /kaniko/.docker/config.json
    - /kaniko/executor --context $CI_PROJECT_DIR --dockerfile $CI_PROJECT_DIR/Dockerfile --destination $APP_IMAGE_ID