Gitlab是代码管理仓库,部署方式很多,这里依然部署在Kubernetes种。
注: 1、代码仓库是需要持久化存储的。 2、组件有Redis,PostgreSQL,Gitlab
部署Redis
配置清单:
gitlab-redis.yaml
apiVersion: apps/v1beta1kind: Deploymentmetadata:name: redisnamespace: kube-opslabels:name: redisspec:template:metadata:name: redislabels:name: redisspec:containers:- name: redisimage: sameersbn/redisimagePullPolicy: IfNotPresentports:- name: rediscontainerPort: 6379volumeMounts:- mountPath: /var/lib/redisname: datalivenessProbe:exec:command:- redis-cli- pinginitialDelaySeconds: 30timeoutSeconds: 5readinessProbe:exec:command:- redis-cli- pinginitialDelaySeconds: 5timeoutSeconds: 1volumes:- name: dataemptyDir: {}---apiVersion: v1kind: Servicemetadata:name: redisnamespace: kube-opslabels:name: redisspec:ports:- name: redisport: 6379targetPort: redisselector:name: redis
部署PostgreSQL
gitlab-postgresql.yaml
apiVersion: apps/v1beta1kind: Deploymentmetadata:name: postgresqlnamespace: kube-opslabels:name: postgresqlspec:template:metadata:name: postgresqllabels:name: postgresqlspec:containers:- name: postgresqlimage: sameersbn/postgresql:10imagePullPolicy: IfNotPresentenv:- name: DB_USERvalue: gitlab- name: DB_PASSvalue: passw0rd- name: DB_NAMEvalue: gitlab_production- name: DB_EXTENSIONvalue: pg_trgmports:- name: postgrescontainerPort: 5432volumeMounts:- mountPath: /var/lib/postgresqlname: datalivenessProbe:exec:command:- pg_isready- -h- localhost- -U- postgresinitialDelaySeconds: 30timeoutSeconds: 5readinessProbe:exec:command:- pg_isready- -h- localhost- -U- postgresinitialDelaySeconds: 5timeoutSeconds: 1volumes:- name: dataemptyDir: {}---apiVersion: v1kind: Servicemetadata:name: postgresqlnamespace: kube-opslabels:name: postgresqlspec:ports:- name: postgresport: 5432targetPort: postgresselector:name: postgresql
部署Gitlab
gitlab.yaml
apiVersion: apps/v1beta1kind: Deploymentmetadata:name: gitlabnamespace: kube-opslabels:name: gitlabspec:template:metadata:name: gitlablabels:name: gitlabspec:containers:- name: gitlabimage: sameersbn/gitlab:11.8.1imagePullPolicy: IfNotPresentenv:- name: TZvalue: Asia/Shanghai- name: GITLAB_TIMEZONEvalue: Beijing- name: GITLAB_SECRETS_DB_KEY_BASEvalue: long-and-random-alpha-numeric-string- name: GITLAB_SECRETS_SECRET_KEY_BASEvalue: long-and-random-alpha-numeric-string- name: GITLAB_SECRETS_OTP_KEY_BASEvalue: long-and-random-alpha-numeric-string- name: GITLAB_ROOT_PASSWORDvalue: admin321- name: GITLAB_ROOT_EMAILvalue: rookieops@163.com- name: GITLAB_HOSTvalue: git.rookieops.com- name: GITLAB_PORTvalue: "80"- name: GITLAB_SSH_PORTvalue: "22"- name: GITLAB_NOTIFY_ON_BROKEN_BUILDSvalue: "true"- name: GITLAB_NOTIFY_PUSHERvalue: "false"- name: GITLAB_BACKUP_SCHEDULEvalue: daily- name: GITLAB_BACKUP_TIMEvalue: 01:00- name: DB_TYPEvalue: postgres- name: DB_HOSTvalue: postgresql- name: DB_PORTvalue: "5432"- name: DB_USERvalue: gitlab- name: DB_PASSvalue: passw0rd- name: DB_NAMEvalue: gitlab_production- name: REDIS_HOSTvalue: redis- name: REDIS_PORTvalue: "6379"ports:- name: httpcontainerPort: 80- name: sshcontainerPort: 22volumeMounts:- mountPath: /home/git/dataname: datalivenessProbe:httpGet:path: /port: 80initialDelaySeconds: 180timeoutSeconds: 5readinessProbe:httpGet:path: /port: 80initialDelaySeconds: 5timeoutSeconds: 1volumes:- name: dataemptyDir: {}---apiVersion: v1kind: Servicemetadata:name: gitlabnamespace: kube-opslabels:name: gitlabspec:ports:- name: httpport: 80targetPort: http- name: sshport: 22targetPort: sshselector:name: gitlabtype: NodePort
然后创建配置清单:
# kubectl apply -f gitlab-postgresql.yaml# kubectl apply -f gitlab-redis.yaml# kubectl apply -f gitlab.yaml
然后就可以用root:admin321登录了。
由于平时使用的 ssh 默认是 22 端口,现在如果用默认的 22 端口去连接,是没办法和 Gitlab 容器中的 22 端口进行映射的,因为我们只是通过 Service 的 22 端口进行了映射,要想通过节点去进行 ssh 链接就需要在节点上一个端口和容器内部的22端口进行绑定,所以这里我们可以通过 NodePort 去映射 Gitlab 容器内部的22端口,比如我们将环境变量设置为GITLAB_SSH_PORT=30022,将 Gitlab 的 Service 也设置为 NodePort 类型:
apiVersion: v1kind: Servicemetadata:name: gitlabnamespace: kube-opslabels:name: gitlabspec:ports:- name: httpport: 80targetPort: http- name: sshport: 22nodePort: 30022targetPort: sshselector:name: gitlabtype: NodePort
然后就可以正式使用了。
