1、环境准备

  1. # 查看repo仓库
  2. [root@hw10 ~]# helm repo list
  3. NAME URL
  4. github https://burdenbear.github.io/kube-charts-mirror/
  5. weiruan http://mirror.azure.cn/kubernetes/charts/
  6. aliyun https://kubernetes.oss-cn-hangzhou.aliyuncs.com/charts
  7. jenkins https://charts.jenkins.io
  8. stable https://charts.helm.sh/stable
  9. harbor https://helm.goharbor.io
  10. # 搜索 gitlab
  11. [root@hw10 ~]# helm search repo gitlab
  12. NAME CHART VERSION APP VERSION DESCRIPTION
  13. aliyun/gitlab-ce 0.2.1 GitLab Community Edition
  14. aliyun/gitlab-ee 0.2.1 GitLab Enterprise Edition
  15. github/gitlab-ce 0.2.3 9.4.1 GitLab Community Edition
  16. github/gitlab-ee 0.2.3 9.4.1 GitLab Enterprise Edition
  17. stable/gitlab-ce 0.2.3 9.4.1 GitLab Community Edition
  18. stable/gitlab-ee 0.2.3 9.4.1 GitLab Enterprise Edition
  19. weiruan/gitlab-ce 0.2.3 9.4.1 GitLab Community Edition
  20. weiruan/gitlab-ee 0.2.3 9.4.1 GitLab Enterprise Edition
  21. #选择了阿里云的
  22. helm pull aliyun/gitlab-ce
  23. # 解压
  24. tar xf gitlab-ce-0.2.1.tgz
  25. cd gitlab-ce
  26. # 修改gitlab ,postgresql,redis 的values.yaml
  27. # 安装
  28. helm install gitlab -n devops .
  29. NAME: gitlab
  30. LAST DEPLOYED: Mon Apr 19 20:59:58 2021
  31. NAMESPACE: devops
  32. STATUS: deployed
  33. REVISION: 1
  34. TEST SUITE: None
  35. NOTES:
  36. ##############################################################################
  37. This chart has been deprecated in favor of the official GitLab chart:
  38. http://docs.gitlab.com/ce/install/kubernetes/gitlab_omnibus.html
  39. ##############################################################################
  40. 1. Get your GitLab URL by running:
  41. export POD_NAME=$(kubectl get pods --namespace devops -l "app=gitlab-gitlab-ce" -o jsonpath="{.items[0].metadata.name}")
  42. echo http://127.0.0.1:8080/
  43. kubectl port-forward $POD_NAME 8080:80
  44. 2. Login as the root user:
  45. Username: root
  46. Password: ******
  47. 3. Point a DNS entry at your install to ensure that your specified
  48. external URL is reachable:
  49. 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" . }}

image.png

vim gitlab-ce/charts/postgresql/templates/deployment.yaml

添加:

  selector:
    matchLabels:
      app: {{ template "postgresql.fullname" . }}

image.png

vim gitlab-ce/charts/redis/templates/deployment.yaml

添加:

  selector:
    matchLabels:
      app: {{ template "redis.fullname" . }}

image.png

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、增加存活和就绪探针的时间
image.png
image.png
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

image.png

补充:
更换pg库镜像
使用的pg镜像是默认的postgresql:9.6.2
修改pg 的values.yaml 的镜像
image: “docker.io/bitnami/postgresql”
imageTag: “10.7.0”
image.png
修改 gitce的values.yaml 的镜像 imageTag: “10.7.0”

2.5 gitlab 启动 502

gitlab - 图8
原因:
关于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