gitlab cicd (四)系列之安装git-runner kubernetes安装方式

本编博客是继gitlab cicd (三)系列之安装git-runner docker安装方式安装方式之后另一种安装gitlab-runner的安装方式—kubernetes安装方式

kubernetes集群的安装
请参考kubernetes v1.11.0 从代码编译到部署文档-部署

kubernetes版本

[root@master-47-35 ~]# kubectl version 
Client Version: version.Info{Major:"1", Minor:"11+", GitVersion:"v1.11.0-168+f47446a730ca03", GitCommit:"f47446a730ca037473fb3bf0c5abeea648c1ac12", GitTreeState:"clean", BuildDate:"2018-08-25T21:05:52Z", GoVersion:"go1.10.3", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"11+", GitVersion:"v1.11.0-168+f47446a730ca03", GitCommit:"f47446a730ca037473fb3bf0c5abeea648c1ac12", GitTreeState:"clean", BuildDate:"2018-08-25T21:05:52Z", GoVersion:"go1.10.3", Compiler:"gc", Platform:"linux/amd64"}

准备ConfigMap

token gitlab
从gitlab服务中获取

gitlab cicd (四)系列之安装git-runner kubernetes安装方式_第1张图片

[root@master-47-35 gitlab]# cat configmap.yaml 
apiVersion: v1
kind: ConfigMap
metadata:
  name: gitlab-runner
  namespace: gitlab
data:
  config.toml: |
    concurrent = 4

    [[runners]]
      name = "Kubernetes Runner"
      url = "http://10.39.47.63/"
      token = "d4027a7f23390e8e2519d93564c0a7"
      executor = "kubernetes"
      [runners.kubernetes]
        namespace = "gitlab"
        image = "busybox"

deployment

[root@master-47-35 gitlab]# cat deployment.yaml 
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: gitlab-runner
  namespace: gitlab
spec:
  replicas: 1
  selector:
    matchLabels:
      name: gitlab-runner
  template:
    metadata:
      labels:
        name: gitlab-runner
    spec:
      containers:
      - args:
        - run
        image: harbor.enncloud.cn/paas/gitlab-runner:latest
        imagePullPolicy: IfNotPresent
        name: gitlab-runner
        volumeMounts:
        - mountPath: /etc/gitlab-runner
          name: config
        - mountPath: /etc/kubernetes/ssl/
          name: cacerts
          readOnly: true
        - mountPath: /var/run/docker.sock
          name: docker-sock
          readOnly: true
      restartPolicy: Always
      hostNetwork: true
      volumes:
      - configMap:
          name: gitlab-runner
        name: config
      - hostPath:
          path: /etc/kubernetes/ssl/
        name: cacerts
      - hostPath:
          path: /var/run/docker.sock
        name: docker-sock

创建名为gitlab的namespace,

kubectl create ns gitlab

部署

[root@master-47-35 gitlab]# kubectl create -f configmap.yaml 
configmap/gitlab-runner created
[root@master-47-35 gitlab]# kubectl create -f deployment.yaml 
deployment.extensions/gitlab-runner created

进入到容器注册gitlab-runner

[root@master-47-35 gitlab]# kubectl exec -it gitlab-runner-7dcfcb8d44-d4vdf sh -n gitlab

gitlab cicd (四)系列之安装git-runner kubernetes安装方式_第2张图片

查看部署结果

[root@master-47-35 gitlab]# kubectl get pods -n gitlab -owide
NAME                             READY     STATUS    RESTARTS   AGE       IP              NODE          NOMINATED NODE
gitlab-runner-7dcfcb8d44-d4vdf   1/1       Running   0          43s       10.253.109.42   slave-47-33   

gitlab cicd (四)系列之安装git-runner kubernetes安装方式_第3张图片

注意文件config.toml这个里面的token要跟页面的一样
gitlab cicd (四)系列之安装git-runner kubernetes安装方式_第4张图片

root@slave-47-33:/# cat /etc/gitlab-runner/config.toml 
concurrent = 4

[[runners]]
  name = "Kubernetes Runner"
  url = "http://10.39.47.63/"
  token = "75a8c62d5b0652dff24c57c341fc60"
  executor = "kubernetes"
  [runners.kubernetes]
     namespace = "gitlab"
     namespace_overwrite_allowed = "ci-.*"
     bearer_token_overwrite_allowed = true
     privileged = true

gitlab cicd (四)系列之安装git-runner kubernetes安装方式_第5张图片

[root@master-47-35 gitlab]# kubectl get pods -n gitlab 
NAME                                          READY     STATUS              RESTARTS   AGE
gitlab-runner-6bff6d5579-hnrpb                1/1       Running             0          18m
runner-75a8c62d-project-2-concurrent-0shtsp   0/5       ContainerCreating   0          56s
[root@master-47-35 gitlab]# kubectl get pods -n gitlab 
NAME                                          READY     STATUS              RESTARTS   AGE
gitlab-runner-6bff6d5579-hnrpb                1/1       Running             0          18m
runner-75a8c62d-project-2-concurrent-0shtsp   0/5       ContainerCreating   0          58s
[root@master-47-35 gitlab]# kubectl get pods -n gitlab 
NAME                                          READY     STATUS              RESTARTS   AGE
gitlab-runner-6bff6d5579-hnrpb                1/1       Running             0          18m
runner-75a8c62d-project-2-concurrent-0shtsp   0/5       ContainerCreating   0          59s
[root@master-47-35 gitlab]# kubectl get pods -n gitlab 
NAME                                          READY     STATUS              RESTARTS   AGE
gitlab-runner-6bff6d5579-hnrpb                1/1       Running             0          18m
runner-75a8c62d-project-2-concurrent-0shtsp   0/5       ContainerCreating   0          1m
[root@master-47-35 gitlab]# kubectl get pods -n gitlab 
NAME                                          READY     STATUS              RESTARTS   AGE
gitlab-runner-6bff6d5579-hnrpb                1/1       Running             0          18m
runner-75a8c62d-project-2-concurrent-0shtsp   0/5       ContainerCreating   0          1m

end

参考
Run GitLab Runner on a Kubernetes cluster
kubernetes-executors
Advanced configuration

你可能感兴趣的:(cicd)