一、GitLab简介

二、安装GitLab

添加helm源

  1. helm repo add stable https://charts.helm.sh/stable
  2. helm repo add aliyun https://kubernetes.oss-cn-hangzhou.aliyuncs.com/charts
  3. helm repo add apphub https://apphub.aliyuncs.com/

拉取chart

通过helm拉取chart:

  1. helm pull stable/gitlab-ce

查看一下拉取的chart,看到多了一个 tgz 文件:

  1. $ ls
  2. gitlab-ce-0.2.3.tgz

将其解压,并进入目录:

  1. $ tar -zxvf gitlab-ce-0.2.3.tgz
  2. $ ls
  3. gitlab-4.5.3.tgz gitlab-ce gitlab-ce-0.2.3.tgz
  4. $ cd gitlab-ce/
  5. $ ls
  6. charts Chart.yaml README.md requirements.lock requirements.yaml templates values.yaml

修改values

修改 values.yaml 的相关配置:

  1. externalUrl: http://gitlab.vmware.com/
  2. gitlabRootPassword: "123456"
  3. serviceType: ClusterIP

其中:

  • externalUrl 为之后需要配置的域名映射
  • gitlabRootPassword 为管理员密码,也可以不设置,这样就会在第一次打开gitlab时提示设置
  • serviceType 可以设置为NodePort或LoadBalancer,以暴露其内部/外部端口。如果使用Traefik等服务发现,可以设置为ClusterIP,后面不通过端口访问,只通过域名访问

修改apiVersion

由于我的Kubernetes版本为v18.8,需要将 extensions/v1beta1 修改为 extensions/v1
gitlab-ce 的外层目录执行:

  1. $ grep -irl "extensions/v1beta1" gitlab-ce | grep deployment
  2. gitlab-ce/templates/deployment.yaml
  3. gitlab-ce/charts/postgresql/templates/deployment.yaml
  4. gitlab-ce/charts/redis/templates/deployment.yaml

可以看到有三个文件包含这样的apiVersion,使用下面的命令将其全部替换即可:

  1. $ grep -irl "extensions/v1beta1" gitlab-ce | grep deployment | xargs sed -i 's#extensions/v1beta1#apps/v1#g'

添加selector

同样地,由于Kubernetes版本比较高,还需要添加selector。
xia先找出需要修改的文件:

  1. $ grep -irl "apps/v1" gitlab-ce | grep deployment
  2. gitlab-ce/templates/deployment.yaml
  3. gitlab-ce/charts/postgresql/templates/deployment.yaml
  4. gitlab-ce/charts/redis/templates/deployment.yaml

然后只能一个一个地修改了。将 selector 添加到 template 的同级。
gitlab-ce/templates/deployment.yaml

  1. spec:
  2. replicas: 1
  3. selector:
  4. matchLabels:
  5. app: {{ template "gitlab-ce.fullname" . }}
  6. template:
  7. metadata:
  8. labels:
  9. app: {{ template "gitlab-ce.fullname" . }}

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

  1. spec:
  2. selector:
  3. matchLabels:
  4. app: {{ template "postgresql.fullname" . }}
  5. template:
  6. metadata:
  7. labels:
  8. app: {{ template "postgresql.fullname" . }}

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

  1. spec:
  2. selector:
  3. matchLabels:
  4. app: {{ template "redis.fullname" . }}
  5. template:
  6. metadata:
  7. labels:
  8. app: {{ template "redis.fullname" . }}