【原文链接】Gitlab----基于Kubernetes安装Gitlab
(1)创建命名空间gitlba
kubectl create namespace gitlab
(2)然后创建Gitlab用的PVC,编写yaml配置文件如下
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
namespace: gitlab
name: gitlab-data
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 40Gi
然后使用如下命令创建
kubectl apply -f pvc-gitlab.yaml
(3)创建Postgre用的PVC的配置文件 pvc-postsql.yaml
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: postsql
namespace: gitlab
spec:
accessModes:
- ReadWriteMany
resources:
requests:
storage: 5Gi
然后执行如下命令
kubectl apply -f pvc-postsql.yaml
(4)为redis创建pvc,文件名 pvc-redis.yaml
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: redis-data
namespace: gitlab
spec:
accessModes:
- ReadWriteMany
resources:
requests:
storage: 5Gi
然后执行如下命令创建供redis使用的pvc
kubectl apply -f pvc-redis.yaml
(5)编写创建postgresql的yaml配置文件
apiVersion: apps/v1
kind: Deployment
metadata:
name: postgresql
namespace: gitlab
labels:
name: postgresql
spec:
selector:
matchLabels:
name: postgresql
template:
metadata:
labels:
name: postgresql
spec:
containers:
- name: postgresql
image: sameersbn/postgresql:10
imagePullPolicy: IfNotPresent
env:
- name: DB_USER
value: gitlab
- name: DB_PASS
value: gitlab
- name: DB_NAME
value: gitlab_production
- name: DB_EXTENSION
value: pg_trgm
ports:
- name: postgres
containerPort: 5432
volumeMounts:
- mountPath: /var/lib/postgresql
name: data
livenessProbe:
exec:
command:
- pg_isready
- -h
- localhost
- -U
- postgres
initialDelaySeconds: 30
timeoutSeconds: 5
readinessProbe:
exec:
command:
- pg_isready
- -h
- localhost
- -U
- postgres
initialDelaySeconds: 5
timeoutSeconds: 1
volumes:
- name: data
persistentVolumeClaim:
claimName: postsql
---
apiVersion: v1
kind: Service
metadata:
name: postgresql
namespace: gitlab
labels:
name: postgresql
spec:
ports:
- name: postgres
port: 5432
targetPort: postgres
selector:
name: postgresql
然后执行如下命令创建Pod
kubectl apply -f pvc-redis.yaml
(6)编写redis的yaml配置文件
apiVersion: apps/v1
kind: Deployment
metadata:
name: redis
namespace: gitlab
labels:
name: redis
spec:
selector:
matchLabels:
name: redis
template:
metadata:
name: redis
labels:
name: redis
spec:
containers:
- name: redis
image: sameersbn/redis
imagePullPolicy: IfNotPresent
ports:
- name: redis
containerPort: 6379
volumeMounts:
- mountPath: /var/lib/redis
name: data
livenessProbe:
exec:
command:
- redis-cli
- ping
initialDelaySeconds: 30
timeoutSeconds: 5
readinessProbe:
exec:
command:
- redis-cli
- ping
initialDelaySeconds: 5
timeoutSeconds: 1
volumes:
- name: data
persistentVolumeClaim:
claimName: redis-data
---
apiVersion: v1
kind: Service
metadata:
name: redis
namespace: gitlab
labels:
name: redis
spec:
ports:
- name: redis
port: 6379
targetPort: redis
selector:
name: redis
然后执行如下命令即可创建
kubectl apply -f redis.yaml
(7)编写创建gitlab的yaml配置文件
apiVersion: apps/v1
kind: Deployment
metadata:
name: gitlab
namespace: gitlab
labels:
name: gitlab
spec:
selector:
matchLabels:
name: gitlab
template:
metadata:
name: gitlab
labels:
name: gitlab
spec:
containers:
- name: gitlab
image: sameersbn/gitlab:11.8.1
imagePullPolicy: IfNotPresent
env:
- name: TZ
value: Asia/Shanghai
- name: GITLAB_TIMEZONE
value: Beijing
- name: GITLAB_SECRETS_DB_KEY_BASE
value: long-and-random-alpha-numeric-string
- name: GITLAB_SECRETS_SECRET_KEY_BASE
value: long-and-RANDOM-ALPHA-NUMERIc-string
- name: GITLAB_SECRETS_OTP_KEY_BASE
value: long-and-random-alpha-numeric-string
- name: GITLAB_ROOT_PASSWORD
value: admin321
- name: GITLAB_ROOT_EMAIL
value: hitredrose@163.com ##这里填自己的邮箱
- name: GITLAB_HOST
value: 192.168.16.40 ##这里填gitlab的host地址,可以是主节点的ip
- name: GITLAB_PORT
value: "32765" # 与下面Service中配置的nodePort一致
- name: GITLAB_SSH_PORT # 与下面Service中配置的nodePort一致
value: "32766"
- name: GITLAB_NOTIFY_ON_BROKEN_BUILDS
value: "true"
- name: GITLAB_NOTIFY_PUSHER
value: "false"
- name: GITLAB_BACKUP_SCHEDULE
value: daily
- name: GITLAB_BACKUP_TIME
value: 01:00
- name: DB_TYPE
value: postgres
- name: DB_HOST
value: postgresql
- name: DB_PORT
value: "5432"
- name: DB_USER
value: gitlab
- name: DB_PASS
value: gitlab
- name: DB_NAME
value: gitlab_production
- name: REDIS_HOST
value: redis
- name: REDIS_PORT
value: "6379"
ports:
- name: http
containerPort: 80
- name: ssh
containerPort: 22
volumeMounts:
- mountPath: /home/git/data
name: data
livenessProbe:
httpGet:
path: /
port: 80
initialDelaySeconds: 360 #这个值可以设置大一点,gitlab在启动时比较慢会处于一段时间的502,如果探测时间超过会进行重启,这样gitlab会一直处于重启状态
timeoutSeconds: 50
readinessProbe:
httpGet:
path: /
port: 80
initialDelaySeconds: 360
timeoutSeconds: 50
volumes:
- name: data
persistentVolumeClaim:
claimName: gitlab-data
---
apiVersion: v1
kind: Service
metadata:
name: gitlab
namespace: gitlab
labels:
name: gitlab
spec:
ports:
- name: http
port: 80
targetPort: http
nodePort: 32765
- name: ssh
port: 22
nodePort: 32766
targetPort: ssh
selector:
name: gitlab
type: NodePort
然后执行如下命令创建gitlab
kubectl apply -f gitlab.yaml
(8)此时执行如下命令查看gitlab命名空间中的pod的状态,如下都为running,表示正常
[root@master gitlab]# kubectl get pod -n gitlab
NAME READY STATUS RESTARTS AGE
gitlab-855b5b7b7b-8hr97 1/1 Running 0 23m
postgresql-b75d769dd-dn2pt 1/1 Running 0 17h
redis-6c976f56dc-z7fsb 1/1 Running 0 55m
[root@master gitlab]#
(9)然后通过Kubernetesmaster节点的ip地址和设置的端口比如这里32765,就可以访问gitlab了
(10)然后使用gitlab中设置的管理员密码,比如这里admin321,用户名root,就可以登录了,如下所示,为一个全新的gitlab