在前面的文章中分别演示了如何用安装包、 docker 在不同 OS(Ubuntu、CentOS)上安装和运行极狐 GitLab 实例,以及极狐 GitLab Runner 的各种花式玩法。详细内容可以查看公众号文章极狐GitLab安装系列教程大合集(附视频)。
每一种玩法都有相应的视频,而且相应的文章、视频都在极狐 GitLab 相关的媒体账号下,感兴趣的小伙伴可以扫描下面的极狐 GitLab 媒体账号合集,来关注不同的内容呈现形式:
写在前面
前提条件
- 一个运行良好的 Kubernetes 集群,版本为 1.16 到 1.21(本文用单节点集群)
- kubectl 的版本为 1.16 或更高
- Helm v3(3.3.1 或更高版本)
- 极狐GitLab Helm Chart(已经上线,可查看 https://artifacthub.io/packag...,同时在官网文档 https://docs.gitlab.cn/charts 中有详细使用指南)
本文演示的环境信息如下:
$ kubectl get nodes
NAME STATUS ROLES AGE VERSION
10.0.0.16 Ready <none> 24h v1.20.6-tke.12
$ kubectl version
Client Version: version.Info{Major:"1", Minor:"21", GitVersion:"v1.21.5", GitCommit:"aea7bbadd2fc0cd689de94a54e5b7b758869d691", GitTreeState:"clean", BuildDate:"2021-09-15T21:10:45Z", GoVersion:"go1.16.8", Compiler:"gc", Platform:"darwin/amd64"}
Server Version: version.Info{Major:"1", Minor:"20+", GitVersion:"v1.20.6-tke.12", GitCommit:"1cb721e6058b081fee879989b8616081cf147bb6", GitTreeState:"clean", BuildDate:"2022-01-14T02:05:16Z", GoVersion:"go1.15.10", Compiler:"gc", Platform:"linux/amd64"}
$ helm version
version.BuildInfo{Version:"v3.6.3", GitCommit:"d506314abfb5d21419df8c7e7e68012379db2354", GitTreeState:"clean", GoVersion:"go1.16.5"}
Chart 准备
先要添加极狐 GitLab 的 Helm Repo:
$ helm repo add jh-gitlab https://charts.gitlab.cn/
"jh-gitlab" has been added to your repositories
查看是否添加成功:
$ helm repo list
NAME URL
jh-gitlab https://charts.gitlab.cn/
查看极狐 GitLab Helm Repo 包含的内容:
$ helm search repo jh-gitlab
NAME CHART VERSION APP VERSION DESCRIPTION
jh-gitlab/gitlab 5.7.0 14.7.0 Web-based Git-repository manager with wiki and ...
可以看到极狐 GitLab Chart 的版本是 5.7.0,对应的极狐 GitLab 版本是 14.7.0。
values.yaml 定制
由于极狐 GitLab 包含多个组件,包括核心组件(诸如 Registry、Gitaly 等)、可选依赖组件(诸如 PostgreSQL、Redis 等)、可选附件组件(Prometheus、Grafana 等),整体的 values.yaml 文件比较复杂,详细内容可以查看极狐GitLab Helm Chart values.yaml 文件。
本次演示所用的 values.yaml 文件内容如下:
gitlab:
gitaly:
persistence:
size: 10Gi
postgresql:
persistence:
size: 10Gi
image:
tag: 12.7.0
redis:
master:
persistence:
size: 10Gi
minio:
persistence:
size: 10Gi
prometheus:
install: false
gitlab-runner:
install: false
文件对于要做数据持久化的一些组件的 PVC 做了一些限制,同时 disable 了 prometheus 和 Runner 的安装(Runner 的安装非常灵活,可以查看文章开头所提的极狐 GitLab 安装大合集文章)。接下来就可以用这个 values.yaml 文件来安装极狐 GitLab 实例了。
Helm 安装
先创建一个名为 jh 的 namespace:
$ kubectl create ns jh
使用 helm install 命令即可完成安装:
$ helm install jh jh-gitlab/gitlab --namespace jh --version 5.7.0 --set global.hosts.domain=xiaomage.cn,[email protected] -f jh-values.yaml
NAME: jh
LAST DEPLOYED: Thu Jan 27 21:24:23 2022
NAMESPACE: jh
STATUS: deployed
REVISION: 1
NOTES:
NOTICE: The minimum required version of PostgreSQL is now 12. See https://gitlab.com/gitlab-org/charts/gitlab/-/blob/master/doc/installation/upgrade.md for more details.
Help us improve the installation experience, let us know how we did with a 1 minute survey:
https://gitlab.fra1.qualtrics.com/jfe/form/SV_6kVqZANThUQ1bZb?installation=helm&release=14-7
NOTICE: The in-chart NGINX Ingress Controller has the following requirements:
- Kubernetes version must be 1.19 or newer.
- Ingress objects must be in group/version `networking.k8s.io/v1`.
上述命令在 jh namespace 下,以 jh-gitlab/gitlab 为 Chart 安装了一个名为 jh 的 Release,可以查看极狐 GitLab 相关组件的 pod 状态:
$ kubectl -n jh get pods
NAME READY STATUS RESTARTS AGE
jh-certmanager-65f6db7b98-cs28b 1/1 Running 0 2m34s
jh-certmanager-cainjector-7547dc9f6c-mktb6 1/1 Running 0 2m34s
jh-certmanager-webhook-f5f7cb774-n4m5f 1/1 Running 0 2m34s
jh-gitaly-0 1/1 Running 0 2m31s
jh-gitlab-exporter-578fcbd446-vc2sv 1/1 Running 0 2m34s
jh-gitlab-shell-79656578b-4xcfg 1/1 Running 0 2m34s
jh-gitlab-shell-79656578b-m8zg7 1/1 Running 0 2m16s
jh-issuer-1-svljr 0/1 Completed 0 2m31s
jh-migrations-1-4nm4m 0/1 Completed 0 2m30s
jh-minio-7749cb9b5f-6mvgq 1/1 Running 0 2m33s
jh-minio-create-buckets-1-cvzgk 0/1 Completed 0 2m30s
jh-nginx-ingress-controller-7c755cdd7f-kgmg4 1/1 Running 0 2m33s
jh-nginx-ingress-controller-7c755cdd7f-zvh8t 1/1 Running 0 2m33s
jh-nginx-ingress-defaultbackend-7c9dc8695b-w6mfj 1/1 Running 0 2m33s
jh-postgresql-0 2/2 Running 0 2m31s
jh-redis-master-0 2/2 Running 0 2m31s
jh-registry-69687b758b-2c5z4 1/1 Running 0 2m32s
jh-registry-69687b758b-gvt6f 1/1 Running 0 2m16s
jh-sidekiq-all-in-1-v2-58ff448759-gpp62 1/1 Running 0 2m34s
jh-toolbox-78b4b78498-qtlnv 1/1 Running 0 2m33s
jh-webservice-default-6db8bc57d9-cdpmh 2/2 Running 0 2m33s
jh-webservice-default-6db8bc57d9-flh2k 2/2 Running 0 2m16s
查看 ing:
$ kubectl -n jh get ing
NAME CLASS HOSTS ADDRESS PORTS AGE
jh-minio jh-nginx minio.xiaomage.cn 124.156.122.184 80, 443 2m51s
jh-registry jh-nginx registry.xiaomage.cn 124.156.122.184 80, 443 2m51s
jh-webservice-default jh-nginx gitlab.xiaomage.cn 124.156.122.184 80, 443 2m51s
可以用 https://gitlab.xiaomage.cn 来登陆拉起的极狐 GitLab 实例:
使用上述密码以及 root 用户名即可登录极狐 GitLab 实例:
接下来需要修改初始密码:
https://www.bilibili.com/vide...
至此,在 Kubernetes 上成功安装了极狐 GitLab 实例,接下来就可以开启极狐 GitLab DevOps 之旅了。