> For the complete documentation index, see [llms.txt](https://wiki.halfcoffee.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://wiki.halfcoffee.com/gitlab/gitlab-bu-shu-jie-shao.md).

# Gitlab 部署介绍

### 目录

1. [Gitlab 部署介绍](broken://pages/I4lsieKIitwnPgjDf5FO)
2. [安装简介](broken://pages/I4lsieKIitwnPgjDf5FO)
   1. [本文参考资料](broken://pages/I4lsieKIitwnPgjDf5FO)
3. [组件介绍](broken://pages/I4lsieKIitwnPgjDf5FO)
4. [获取部署文件](broken://pages/I4lsieKIitwnPgjDf5FO)

### 安装简介

Gitlab 在 Kubernetes 中有三种安装方式：

* 单节点运行：Gitlab CE 提供官方单节点 docker 镜像，使用 docker run 便可跑起来，在 Kubernetes 上只需要使用相同的镜像，设置合适的环境变量便可跑起来，这种架构所有组件（gitlab、gitlab-runner、postgresql、redis）都在一个镜像中，比较重，启动时间也很慢，个人在部署时发现时不时遇到初始化问题，刷新页面十几次才能解决，如果环境资源有限可以使用这种部署方式。
* 三节点运行：有位大神在 gitlab 出了三节点 Docker 部署的镜像和方式<https://github.com/sameersbn/docker-gitlab>，将 gitlab、redis、postgresql 分开部署，github 加星6k，同时作者提供了 Kubernetes 部署yaml。测试这种部署很稳，而且作者更新很快，release 速度和官方发布齐平。推荐这种部署方式。
* 官方 Helm charts 部署：这种方式架构最复杂，但是据官方说易于扩展。

### 本文参考资料

官方部署指南：

<https://docs.gitlab.com/charts/installation/deployment.html>

命令参考：

<https://docs.gitlab.com/charts/installation/command-line-options.html>

伪架构师博客：

<https://blog.fleeto.us/courses/gitlab-notes/01-01-gitlab-deployment-k8s/>

### 组件介绍

安装官方文档，Gitlab 共有以下组件：

**Core：**

* [NGINX Ingress](https://docs.gitlab.com/charts/charts/nginx/index.html)：原生 helm 部署依赖于 loadbalancer，此 nginx ingress 会通过 4 层 LB 进行发布。
* [Registry](https://docs.gitlab.com/charts/charts/registry/index.html)：集成的镜像仓库。
* GitLab/[Gitaly](https://docs.gitlab.com/charts/charts/gitlab/gitaly/index.html)：提供 gitaly 服务。
* GitLab/[GitLab Exporter](https://docs.gitlab.com/charts/charts/gitlab/gitlab-exporter/index.html)：提供 Prometheus 监控指标。 此服务依赖于 Redis 和 PostgreSQ 。
* GitLab/[GitLab Grafana](https://docs.gitlab.com/charts/charts/gitlab/gitlab-grafana/index.html)
* GitLab/[GitLab Shell](https://docs.gitlab.com/charts/charts/gitlab/gitlab-shell/index.html)：提供 SSH 服务，让用户可以通过 ssh 访问 gitlab。
* GitLab/[Migrations](https://docs.gitlab.com/charts/charts/gitlab/migrations/index.html)：是一个一次性 job，用于查找并迁移 gitlab 数据库。 此服务依赖于 Redis 和 PostgreSQL。
* GitLab/[Sidekiq](https://docs.gitlab.com/charts/charts/gitlab/sidekiq/index.html)： sidekiq 是个独立可配置的队列工具。此服务依赖于 Redis, PostgreSQL 和 Gitaly。
* GitLab/[Webservice](https://docs.gitlab.com/charts/charts/gitlab/webservice/index.html)：提供 gitlab webserver，每个 pod 中会有两个 webserver worker，同时pod内也会运行 gitlab workhorse。此服务依赖于 Redis, PostgreSQL, Gitaly, 和 Registry。

**可外置的依赖：**

* [PostgreSQL](https://hub.helm.sh/charts/bitnami/postgresql)
* [Redis](https://hub.helm.sh/charts/bitnami/redis)
* [MinIO](https://docs.gitlab.com/charts/charts/minio/index.html)：提供对象存储 API，必须安装

**其他可选组件：**

* [Prometheus](https://hub.helm.sh/charts/stable/prometheus)
* [Grafana](https://hub.helm.sh/charts/stable/grafana)
* [GitLab Runner](https://docs.gitlab.com/runner/) ：运行 Gitlab CI 任务
* 借助 [Let’s Encrypt](https://letsencrypt.org/) 和 [cert-manager](https://cert-manager.io/docs/) 自动生成证书

### 获取部署文件

在客户端安装 helm 3，配置好 kubectl ，运行下列命令获取所有 gitlab charts：

```
helm repo add gitlab https://charts.gitlab.io/
helm repo update
helm fetch --untar gitlab/gitlab
```
