一,前言
- 在持续集成Jenkins+Gitlab,叙述了Gitlab的基本配置
- 在k8s部署文档(详细版),叙述了k8s的部署
- 下面在记录一下,gitlab docker版
docker pull registry.cn-hangzhou.aliyuncs.com/imooc/gitlab-ce:latest
cat <<EOF > start.sh
#!/bin/bash
HOST_NAME=gitlab.test.com
GITLAB_DIR=`pwd`
docker stop gitlab
docker rm gitlab
docker run -d \\
--hostname \${HOST_NAME} \\
-p 8443:443 -p 8080:80 -p 2222:22 \\
--name gitlab \\
-v \${GITLAB_DIR}/config:/etc/gitlab \\
-v \${GITLAB_DIR}/logs:/var/log/gitlab \\
-v \${GITLAB_DIR}/data:/var/opt/gitlab \\
registry.cn-hangzhou.aliyuncs.com/imooc/gitlab-ce:latest
EOF
sh start.sh
二,gitlab集成k8s
#在service下gitlab runner要用到的配置,来自[官网修改]()
[root@C1 services]# ll | grep gitlab
-rw-r--r-- 1 root root 776 5月 10 16:22 gitlab-deployment.yaml
-rw-r--r-- 1 root root 98 5月 10 16:26 gitlab-ns.yaml
-rw-r--r-- 1 root root 361 5月 10 17:05 gitlab.yaml
#下面是文件内容
#gitlab-ns 注册gitlab命名空间
[root@C1 services]# cat gitlab-ns.yaml
apiVersion: v1
kind: Namespace
metadata:
name: gitlab
labels:
name: gitlab
#gitlab 为需要的ConfigMap,注意修改url和token,在gitlab中查看,下面会说明
[root@C1 services]# cat gitlab.yaml
apiVersion: v1
kind: ConfigMap
metadata:
name: gitlab-runner
namespace: gitlab
data:
config.toml: |
concurrent = 4
[[runners]]
name = "Kubernetes Runner"
url = "http://192.168.66.129/"
token = "zNzrDbWRrxyHQxuDkcyg"
executor = "kubernetes"
[runners.kubernetes]
namespace = "gitlab"
image = "busybox"
#gitlab-deployment为gitlabdeploy
[root@C1 services]# cat gitlab-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: gitlab/gitlab-runner:latest
imagePullPolicy: Always
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
#依次创建
kubectl create -f gitlab-ns.yaml
kubectl create -f gitlab.yaml
kubectl create -f gitlab-deployment.yaml
#查看状态
[root@C1 services]# kubectl -n gitlab get pods -o wide
NAME READY STATUS RESTARTS AGE IP NODE
gitlab-runner-5c4554ddb5-4dnlt 1/1 Running 1 3d 172.20.12.7 192.168.66.136
[root@C1 services]# kubectl -n gitlab get deploy
NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE
gitlab-runner 1 1 1 1 3d
#待pod运行后,进入docker容器中,注册gitlab runner即可,如下图
image.png
ps:gitlab runner url和token位置如下图
image.png
注册完后,刷新此页面,看到刚刚的runner即可
image.png
网友评论