1、环境准备
# 查看repo仓库
[root@hw10 ~]# helm repo list
NAME URL
github https://burdenbear.github.io/kube-charts-mirror/
weiruan http://mirror.azure.cn/kubernetes/charts/
aliyun https://kubernetes.oss-cn-hangzhou.aliyuncs.com/charts
jenkins https://charts.jenkins.io
stable https://charts.helm.sh/stable
harbor https://helm.goharbor.io
# 搜索 gitlab
[root@hw10 ~]# helm search repo gitlab
NAME CHART VERSION APP VERSION DESCRIPTION
aliyun/gitlab-ce 0.2.1 GitLab Community Edition
aliyun/gitlab-ee 0.2.1 GitLab Enterprise Edition
github/gitlab-ce 0.2.3 9.4.1 GitLab Community Edition
github/gitlab-ee 0.2.3 9.4.1 GitLab Enterprise Edition
stable/gitlab-ce 0.2.3 9.4.1 GitLab Community Edition
stable/gitlab-ee 0.2.3 9.4.1 GitLab Enterprise Edition
weiruan/gitlab-ce 0.2.3 9.4.1 GitLab Community Edition
weiruan/gitlab-ee 0.2.3 9.4.1 GitLab Enterprise Edition
#选择了阿里云的
helm pull aliyun/gitlab-ce
# 解压
tar xf gitlab-ce-0.2.1.tgz
cd gitlab-ce
# 修改gitlab ,postgresql,redis 的values.yaml
# 安装
helm install gitlab -n devops .
NAME: gitlab
LAST DEPLOYED: Mon Apr 19 20:59:58 2021
NAMESPACE: devops
STATUS: deployed
REVISION: 1
TEST SUITE: None
NOTES:
##############################################################################
This chart has been deprecated in favor of the official GitLab chart:
http://docs.gitlab.com/ce/install/kubernetes/gitlab_omnibus.html
##############################################################################
1. Get your GitLab URL by running:
export POD_NAME=$(kubectl get pods --namespace devops -l "app=gitlab-gitlab-ce" -o jsonpath="{.items[0].metadata.name}")
echo http://127.0.0.1:8080/
kubectl port-forward $POD_NAME 8080:80
2. Login as the root user:
Username: root
Password: ******
3. Point a DNS entry at your install to ensure that your specified
external URL is reachable:
http://8023i.icu/
2、错误解决
2.1 版本问题
Error: unable to build kubernetes objects from release manifest: unable to recognize “”: no matches for kind “Deployment” in version “extensions/v1beta1”
解决:
grep -irl "extensions/v1beta1" gitlab-ce | grep deployment
grep -irl "extensions/v1beta1" gitlab-ce | grep deploy | xargs sed -i 's#extensions/v1beta1#apps/v1#g'
2.2 deployment
错误原因是现有 k8s不支持gitlab-ce的deployment spec Error: unable to build kubernetes objects from release manifest: error validating “”: error validating data: ValidationError(Deployment.spec): missing required field “selector” in io.k8s.api.apps.v1.DeploymentSpec
解决:
[root@hw10 k8s_gitlab]# grep -irl "apps/v1" gitlab-ce | grep deployment
gitlab-ce/charts/redis/templates/deployment.yaml
gitlab-ce/charts/postgresql/templates/deployment.yaml
gitlab-ce/templates/deployment.yaml
依次修改三个配置文件
vim gitlab-ce/templates/deployment.yaml
添加:
replicas: 1
selector:
matchLabels:
app: {{ template "gitlab-ce.fullname" . }}
vim gitlab-ce/charts/postgresql/templates/deployment.yaml
添加:
selector:
matchLabels:
app: {{ template "postgresql.fullname" . }}
vim gitlab-ce/charts/redis/templates/deployment.yaml
添加:
selector:
matchLabels:
app: {{ template "redis.fullname" . }}
2.3 坑点
Error: unable to build kubernetes objects from release manifest: error validating “”: error validating data: apiVersion not set
/home/scripts/k8s_gitlab/gitlab-ce/charts/postgresql
[root@hw10 postgresql]# tree
.
├── Chart.yaml
├── README.md
├── templates
│ ├── deployment.yaml
│ ├── _helpers.tpl
│ ├── networkpolicy.yaml
│ ├── NOTES.txt
│ ├── pvc.yaml
│ ├── secrets.yaml
│ └── svc.yaml
└── values.yaml
networkpolicy.yaml中定义使用了 apiVersion: {{ template “postgresql.networkPolicy.apiVersion” . }}
但是 values.yaml 中未定义,如果开启设置true,需要手动 新增 apiVersion
2.4 postgresql 启动报错
[root@hw10 ~]# kc logs gitlab-postgresql-c876db9d7-xq4w2
...
LOG: autovacuum launcher started
FATAL: could not open relation mapping file "global/pg_filenode.map": No such file or directory
...
- 原因:
容器还未初始化成功,就被探活的指针给kill了
解决:
1、增加存活和就绪探针的时间
2、设置startupProbe 探针
livenessProbe:
exec:
command:
- sh
- -c
- exec pg_isready --host $POD_IP
initialDelaySeconds: 300
timeoutSeconds: 5
failureThreshold: 6
startupProbe:
exec:
command:
- sh
- -c
- exec pg_isready --host $POD_IP
initialDelaySeconds: 30
periodSeconds: 10
failureThreshold: 6
3、取消探活
- 再次启动失败:
chmod: changing permissions of ‘/var/lib/postgresql/data/pgdata’: Operation not permitted
PGDATA:此可选变量可用于为数据库文件定义另一个位置,例如子目录。默认值为/ var / lib / postgresql / data,但是如果您使用的数据量是文件系统挂载点(例如GCE永久磁盘),则Postgres initdb建议使用一个子目录(例如/ var / lib / postgresql / data / pgdata)被创建为包含数据。
解决:
cd /home/scripts/k8s_gitlab/gitlab-ce/charts/postgresql/templates
vim values.yaml
# 修改 volumeMounts 下的 mountPath,删除 pgdata
volumeMounts:
- name: data
mountPath: /var/lib/postgresql/data
- 再次启动失败:
permission denied to create extension “btree_gist”
原因:
默认创建的gitlab用户没有权限
解决:
修改 /home/scripts/k8s_gitlab/gitlab-ce/values.yaml 使用的账号和数据库
postgresUser: postgres
postgresPassword: postgres
postgresDatabase: postgres
补充:
更换pg库镜像
使用的pg镜像是默认的postgresql:9.6.2
修改pg 的values.yaml 的镜像
image: “docker.io/bitnami/postgresql”
imageTag: “10.7.0”
修改 gitce的values.yaml 的镜像 imageTag: “10.7.0”
2.5 gitlab 启动 502
原因:
关于Unicorn Workers:CPU cores + 1 = unicorn workers,一般情况下设置为2或者3就足够了使用了;但需要注意的是:如果unicorn workers只有1,那么将导致git只能通过ssh协议进行工作,因为使用http协议时,分别需要各一个worker来接收和发送数据。
解决:
修改workers数量
/data/share/devops-gitlab-gitlab-ce-etc-pvc-f1a9bbc9-fe1f-4e12-836d-71c5abf9eec0
vim gitlab.rb
puma['worker_processes'] = 4