K8s 集群中运行 GitLab-Runner 来执行 GitLab-CI

K8s 集群中运行 GitLab-Runner 来执行 GitLab-CI

阿里云实例教程

https://help.aliyun.com/document_detail/106968.html?spm=a2c4g.11186623.6.926.71cd629fRdBjk2
(本地使用 pv pvc 须要修改。 )

官方用 helm 安装有问题。

https://docs.gitlab.com/runner/install/kubernetes.html

Error: parse error in "gitlab-runner/templates/_helpers.tpl": template: gitlab-runner/templates/_helpers.tpl:2: function "ternary" not defined

无奈研究了下面的方法。
参考: https://blog.csdn.net/aixiaoyang168/article/details/81149264
直接修改相应参数,会直接加入

用root登录gitlab 在管理区域-- Runners 里面可以看到 注册信息。

处理

ERROR: Job failed (system failure): pods is forbidden: User “system:serviceaccount:dev:default” cannot create resource “pods” in API group “” in the namespace “gitlab-runner”

kubectl create clusterrolebinding gitlab-cluster-admin --clusterrole=cluster-admin --group=system:serviceaccounts --namespace=gitlab-runner
# 可进入系统运行 gitlab-runner register -h 查看更多参数
#--non-interactive 非交互式
#--url gitlab注册URL
#--registration-token gitlab注册令牌
#--name pod-runner 描述
#--tag-list k8s,test 标签(这行删掉就没有标签,任何任务不写标签都能调用)
#--executor kubernetes (这是意思是在k8s集群里面运行,会自动创建新的pod的来运行任务)

---

apiVersion: v1
kind: Namespace
metadata:
  name: gitlab-runner
  namespace: gitlab-runner
  
---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: gitlab-runner
  namespace: gitlab-runner
spec:
  replicas: 1
  revisionHistoryLimit: 3
  selector:
    matchLabels:
      name: gitlab-runner
  template:
    metadata:
      labels:
        name: gitlab-runner
    spec:
      containers:
      - args:
        - run
        image: gitlab/gitlab-runner:latest
        imagePullPolicy: IfNotPresent
        command: ["bash","-c","gitlab-runner register \
     --non-interactive \
     --url http://192.168.6.189/ \
     --registration-token hWj9_sVbcx9jSF7MJCvx \
     --name runner-pod \
     --tag-list k8s,test \
     --executor kubernetes \
     --kubernetes-namespace gitlab-runner && \
      gitlab-runner restart && \
      gitlab-runner run --user=gitlab-runner --working-directory=/home/gitlab-runner"]
        name: gitlab-runner
        volumeMounts:
        - mountPath: /etc/ssl/certs
          name: cacerts
          readOnly: true
      restartPolicy: Always
      volumes:
      - hostPath:
          path: /usr/share/ca-certificates/mozilla
        name: cacerts

下面是手动创建

gitlab-runner-deployment.yaml

运行完yaml文件后。 exec 到创建的pod里 执行 : gitlab-runner register
手动注册到服务。

# kubectl exec -it pod sh
# gitlab-runner register
# 填写 IP Token Tag kubernetes
---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: gitlab-runner
  namespace: default
spec:
  replicas: 1
  selector:
    matchLabels:
      name: gitlab-runner
  template:
    metadata:
      labels:
        name: gitlab-runner
    spec:
      containers:
      - args:
        - run
        image: gitlab/gitlab-runner:latest
        imagePullPolicy: IfNotPresent
        name: gitlab-runner
        volumeMounts:
       # - mountPath: /etc/gitlab-runner/
       #  name: config
        - mountPath: /etc/ssl/certs
          name: cacerts
          readOnly: true
      restartPolicy: Always
      volumes:
      #- configMap:
      #    name: gitlab-runner
      #  name: config
      - hostPath:
          path: /usr/share/ca-certificates/mozilla
        name: cacerts
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值