使用容器镜像仓库
- Tier: 基础版, 专业版, 旗舰版
- Offering: 私有化部署
registry 子 chart 提供了 Registry 组件,用于在 Kubernetes 上完成云原生极狐GitLab 部署。此子 chart 基于 上游 chart 并包含极狐GitLab 容器镜像仓库。
此 chart 由三个主要部分组成:
所有配置均根据 Registry 配置文档 使用提供给 Deployment 的 /etc/docker/registry/config.yml 变量进行处理,并从 ConfigMap 填充。ConfigMap 覆盖了上游默认值,但基于它们。详情如下:
设计选择
选择 Kubernetes Deployment 作为此 chart 的部署方法,以便于实例的简单扩展,同时允许滚动更新。
此 chart 使用了两个必需的密钥和一个可选的:
必需的
- global.registry.certificate.secret:一个全局密钥,包含用于验证由关联的极狐GitLab 实例提供的身份验证令牌的公共证书包。有关使用极狐GitLab 作为身份验证终端的文档,请参见文档。
- global.registry.httpSecret.secret:一个全局密钥,将包含镜像仓库 pod 之间的共享密钥。
可选的
- profiling.stackdriver.credentials.secret:如果启用了 Stackdriver 分析,并且您需要提供显式的服务帐户凭据,那么此密钥中的值(默认情况下在 credentials 键中)就是 GCP 服务帐户的 JSON 凭据。如果您正在使用 GKE 并使用 Workload Identity(或节点服务帐户,尽管不建议这样做)向工作负载提供服务帐户,则不需要此密钥,并且不应提供。在任何情况下,服务帐户都需要 roles/cloudprofiler.agent 或等效的手动权限。
配置
我们将在下面描述配置的所有主要部分。当从父 chart 配置时,这些值将为:
yaml1registry: 2 enabled: 3 maintenance: 4 readonly: 5 enabled: false 6 uploadpurging: 7 enabled: true 8 age: 168h 9 interval: 24h 10 dryrun: false 11 image: 12 tag: 'v4.15.2-gitlab' 13 pullPolicy: IfNotPresent 14 annotations: 15 service: 16 type: ClusterIP 17 name: registry 18 httpSecret: 19 secret: 20 key: 21 authEndpoint: 22 tokenIssuer: 23 certificate: 24 secret: gitlab-registry 25 key: registry-auth.crt 26 deployment: 27 terminationGracePeriodSeconds: 30 28 draintimeout: '0' 29 hpa: 30 minReplicas: 2 31 maxReplicas: 10 32 cpu: 33 targetAverageUtilization: 75 34 behavior: 35 scaleDown: 36 stabilizationWindowSeconds: 300 37 storage: 38 secret: 39 key: storage 40 extraKey: 41 validation: 42 disabled: true 43 manifests: 44 referencelimit: 0 45 payloadsizelimit: 0 46 urls: 47 allow: [] 48 deny: [] 49 notifications: {} 50 tolerations: [] 51 affinity: {} 52 ingress: 53 enabled: false 54 tls: 55 enabled: true 56 secretName: redis 57 annotations: 58 configureCertmanager: 59 proxyReadTimeout: 60 proxyBodySize: 61 proxyBuffering: 62 networkpolicy: 63 enabled: false 64 egress: 65 enabled: false 66 rules: [] 67 ingress: 68 enabled: false 69 rules: [] 70 serviceAccount: 71 create: false 72 automountServiceAccountToken: false 73 tls: 74 enabled: false 75 secretName: 76 verify: true 77 caSecretName: 78 cipherSuites:
如果您选择将此 chart 作为独立部署,则删除顶级的 registry。
安装参数
| 参数 | 默认值 | 描述 |
|---|---|---|
| annotations | Pod 注释 | |
| podLabels | 补充 Pod 标签。不会用于选择器。 | |
| common.labels | 补充标签,应用于此 chart 创建的所有对象。 | |
| authAutoRedirect | true | Auth 自动重定向(对于 Windows 客户端必须为 true) |
| authEndpoint | global.hosts.gitlab.name | Auth 终端(仅主机和端口) |
| certificate.secret | gitlab-registry | JWT 证书 |
| debug.addr.port | 5001 | 调试端口 |
| debug.tls.enabled | false | 启用调试端口的 TLS。这会影响活跃性和就绪性探测,以及指标端点(如果启用) |
| debug.tls.secretName | 包含镜像仓库调试端点有效证书和密钥的 Kubernetes TLS Secret 名称。如果未设置且 debug.tls.enabled=true - 调试 TLS 配置将默认为镜像仓库的 TLS 证书。 | |
| debug.prometheus.enabled | false | 已弃用 使用 metrics.enabled |
| debug.prometheus.path | "" | 已弃用 使用 metrics.path |
| metrics.enabled | false | 是否应提供用于抓取的指标端点 |
| metrics.path | /metrics | 指标端点路径 |
| metrics.serviceMonitor.enabled | false | 是否应创建 ServiceMonitor 以启用 Prometheus Operator 管理指标抓取,请注意,启用此功能会移除 prometheus.io 抓取注释 |
| metrics.serviceMonitor.additionalLabels | {} | 添加到 ServiceMonitor 的附加标签 |
| metrics.serviceMonitor.endpointConfig | {} | ServiceMonitor 的附加端点配置 |
| deployment.terminationGracePeriodSeconds | 30 | Pod 需要优雅终止的可选持续时间(以秒为单位)。 |
| deployment.strategy | {} | 允许配置部署使用的更新策略 |
| draintimeout | '0' | 在收到 SIGTERM 信号后等待 HTTP 连接排空的时间量(例如 '10s') |
| relativeurls | false | 启用镜像仓库在位置标头中返回相对 URL。 |
| enabled | true | 启用镜像仓库标志 |
| extraContainers | 包含要包括的容器列表的多行文字样式字符串 | |
| extraInitContainers | 包含要包括的额外初始化容器列表 | |
| hpa.behavior | {scaleDown: {stabilizationWindowSeconds: 300 }} | 行为包含用于上下缩放行为的规范(需要 autoscaling/v2beta2 或更高版本) |
| hpa.customMetrics | [] | 自定义指标包含用于计算所需副本计数的规格(覆盖在 targetAverageUtilization 中配置的默认平均 CPU 利用率) |
| hpa.cpu.targetType | Utilization | 设置自动缩放 CPU 目标类型,必须为 Utilization 或 AverageValue |
| hpa.cpu.targetAverageValue | 设置自动缩放 CPU 目标值 | |
| hpa.cpu.targetAverageUtilization | 75 | 设置自动缩放 CPU 目标利用率 |
| hpa.memory.targetType | 设置自动缩放内存目标类型,必须为 Utilization 或 AverageValue | |
| hpa.memory.targetAverageValue | 设置自动缩放内存目标值 | |
| hpa.memory.targetAverageUtilization | 设置自动缩放内存目标利用率 | |
| hpa.minReplicas | 2 | 副本的最小数量 |
| hpa.maxReplicas | 10 | 副本的最大数量 |
| httpSecret | Https 密钥 | |
| extraEnvFrom | 列出来自其他数据源的额外环境变量以暴露 | |
| image.pullPolicy | 镜像仓库图像的拉取策略 | |
| image.pullSecrets | 用于图像存储库的密钥 | |
| image.repository | registry.gitlab.com/gitlab-org/build/cng/gitlab-container-registry | 镜像仓库图像 |
| image.tag | v4.15.2-gitlab | 要使用的图像版本 |
| init.image.repository | initContainer 图像 | |
| init.image.tag | initContainer 图像标签 | |
| init.containerSecurityContext | initContainer 特定的 securityContext | |
| init.containerSecurityContext.runAsUser | 1000 | initContainer 特定:容器应以其启动的用户 ID |
| init.containerSecurityContext.allowPrivilegeEscalation | false | initContainer 特定:控制进程是否可以获得比其父进程更多的权限 |
| init.containerSecurityContext.runAsNonRoot | true | initContainer 特定:控制容器是否以非 root 用户运行 |
| init.containerSecurityContext.capabilities.drop | [ "ALL" ] | initContainer 特定:删除容器的 Linux 能力 |
| keda.enabled | false | 使用 KEDA ScaledObjects 而不是 HorizontalPodAutoscalers |
| keda.pollingInterval | 30 | 检查每个触发器的间隔 |
| keda.cooldownPeriod | 300 | 在上次触发器报告活动之后等待的时间段,然后将资源缩放回 0 |
| keda.minReplicaCount | KEDA 将资源缩小到的最小副本数量,默认为 hpa.minReplicas | |
| keda.maxReplicaCount | KEDA 将资源缩放到的最大副本数量,默认为 hpa.maxReplicas | |
| keda.fallback | KEDA 回退配置 | |
| keda.hpaName | KEDA 将创建的 HPA 资源的名称,默认为 keda-hpa-{scaled-object-name} | |
| keda.restoreToOriginalReplicaCount | 指定在删除 ScaledObject 后是否应将目标资源缩放回原始副本计数 | |
| keda.behavior | 上下缩放行为的规范,默认为 hpa.behavior | |
| keda.triggers | 触发器列表,用于激活目标资源的缩放,默认为从 hpa.cpu 和 hpa.memory 计算的触发器 | |
| log | {level: info, fields: {service: registry}} | 配置日志选项 |
| minio.bucket | global.registry.bucket | 旧版镜像仓库桶名称 |
| maintenance.readonly.enabled | false | 启用镜像仓库的只读模式 |
| maintenance.uploadpurging.enabled | true | 启用上传清理 |
| maintenance.uploadpurging.age | 168h | 清理指定年龄以上的上传 |
| maintenance.uploadpurging.interval | 24h | 执行上传清理的频率 |
| maintenance.uploadpurging.dryrun | false | 仅列出将被清理的上传而不删除 |
| priorityClassName | 分配给 pod 的 优先级类。 | |
| reporting.sentry.enabled | false | 启用使用 Sentry 的报告 |
| reporting.sentry.dsn | Sentry DSN(数据源名称) | |
| reporting.sentry.environment | Sentry 环境 | |
| profiling.stackdriver.enabled | false | 启用使用 Stackdriver 的连续分析 |
| profiling.stackdriver.credentials.secret | gitlab-registry-profiling-creds | 包含凭据的密钥名称 |
| profiling.stackdriver.credentials.key | credentials | 存储凭据的密钥 |
| profiling.stackdriver.service | RELEASE-registry(模板化服务名称) | 在其下记录配置文件的 Stackdriver 服务名称 |
| profiling.stackdriver.projectid | 运行所在的 GCP 项目 | 报告配置文件的 GCP 项目 |
| database.configure | false | 在不启用镜像仓库 chart 的情况下填充数据库配置。迁移现有镜像仓库时所需的。迁移现有镜像仓库。 |
| database.enabled | false | 启用元数据数据库。这是一个实验功能,不得在生产环境中使用。 |
| database.host | global.psql.host | 数据库服务器主机名。 |
| database.port | global.psql.port | 数据库服务器端口。 |
| database.user | 数据库用户名。 | |
| database.password.secret | RELEASE-registry-database-password | 包含数据库密码的密钥名称。 |
| database.password.key | password | 存储数据库密码的密钥。 |
| database.name | 数据库名称。 | |
| database.sslmode | SSL 模式。可以是 disable、allow、prefer、require、verify-ca 或 verify-full。 | |
| database.ssl.secret | global.psql.ssl.secret | 包含客户端证书、密钥和证书颁发机构的密钥。默认为主要的 PostgreSQL SSL 密钥。 |
| database.ssl.clientCertificate | global.psql.ssl.clientCertificate | 密钥中的密钥,指代客户端证书。 |
| database.ssl.clientKey | global.psql.ssl.clientKey | 密钥中的密钥,指代客户端密钥。 |
| database.ssl.serverCA | global.psql.ssl.serverCA | 密钥中的密钥,指代证书颁发机构(CA)。 |
| database.connecttimeout | 0 | 等待连接的最长时间。零或未指定表示无限期等待。 |
| database.draintimeout | 0 | 关闭时等待所有连接排空的最长时间。零或未指定表示无限期等待。 |
| database.preparedstatements | false | 启用预准备语句。默认情况下禁用以与 PgBouncer 兼容。 |
| database.primary | false | 目标主要数据库服务器。这用于指定在运行镜像仓库 database.migrations 时要定位的专用 FQDN。未指定时将使用 host 运行 database.migrations。 |
| database.pool.maxidle | 0 | 空闲连接池中的最大连接数。如果 maxopen 小于 maxidle,则 maxidle 会减少以匹配 maxopen 限制。零或未指定表示没有空闲连接。 |
| database.pool.maxopen | 0 | 数据库的最大打开连接数。如果 maxopen 小于 maxidle,则 maxidle 会减少以匹配 maxopen 限制。零或未指定表示无限制的打开连接。 |
| database.pool.maxlifetime | 0 | 连接可以重用的最长时间。过期的连接可能会在重用之前被懒惰地关闭。零或未指定表示无限制重用。 |
| database.pool.maxidletime | 0 | 连接可以空闲的最长时间。过期的连接可能会在重用之前被懒惰地关闭。零或未指定表示无限制持续时间。 |
| database.loadBalancing.enabled | false | 启用数据库负载均衡。这是一个实验功能,不得在生产环境中使用。 |
| database.loadBalancing.nameserver.host | localhost | 用于查找 DNS 记录的名称服务器的主机。 |
| database.loadBalancing.nameserver.port | 8600 | 用于查找 DNS 记录的名称服务器的端口。 |
| database.loadBalancing.record | 要查找的 SRV 记录。服务发现工作的此选项是必需的。 | |
| database.loadBalancing.replicaCheckInterval | 1m | 检查副本状态之间的最小时间量。 |
| database.migrations.enabled | true | 启用迁移作业以在初始部署和 chart 升级时自动运行迁移。请注意,迁移也可以从任何正在运行的镜像仓库 pod 手动运行。 |
| database.migrations.activeDeadlineSeconds | 3600 | 设置迁移作业的 activeDeadlineSeconds。 |
| database.migrations.annotations | {} | 要添加到迁移作业的附加注释。 |
| database.migrations.backoffLimit | 6 | 设置迁移作业的 backoffLimit。 |
| database.backgroundMigrations.enabled | false | 启用数据库的后台迁移。这是镜像仓库元数据数据库的实验功能。不要在生产中使用。有关其工作原理的详细说明,请参阅 specification。 |
| database.backgroundMigrations.jobInterval | 每个后台迁移作业工作运行之间的休眠间隔。未指定时,镜像仓库将设置默认值 一个默认值。 | |
| database.backgroundMigrations.maxJobRetries | 失败的后台迁移作业的最大重试次数。未指定时,镜像仓库将设置默认值 一个默认值。 | |
| gc.disabled | true | 设置为 true 时,在线 GC 工作程序将被禁用。 |
| gc.maxbackoff | 24h | 用于在发生错误时在工作程序运行之间休眠的最大指数退避持续时间。也适用于没有要处理的任务的情况,除非 gc.noidlebackoff 为 true。请注意,这不是绝对最大值,因为始终会添加高达 33% 的随机抖动因子。 |
| gc.noidlebackoff | false | 设置为 true 时,当没有任务要处理时禁用工作程序运行之间的指数退避。 |
| gc.transactiontimeout | 10s | 每次工作程序运行的数据库事务超时。每个工作程序在启动时启动数据库事务。如果超过此超时,将取消工作程序运行以避免停滞或长时间运行的事务。 |
| gc.blobs.disabled | false | 设置为 true 时,禁用用于 blob 的 GC 工作程序。 |
| gc.blobs.interval | 5s | 每次工作程序运行之间的初始休眠间隔。 |
| gc.blobs.storagetimeout | 5s | 存储操作的超时。用于限制删除存储后端悬挂 blob 的请求持续时间。 |
| gc.manifests.disabled | false | 设置为 true 时,禁用用于清单的 GC 工作程序。 |
| gc.manifests.interval | 5s | 每次工作程序运行之间的初始休眠间隔。 |
| gc.reviewafter | 24h | 垃圾收集器应拾取记录进行审核的最短时间。-1 表示无需等待。 |
| securityContext.fsGroup | 1000 | pod 应以其启动的组 ID |
| securityContext.runAsUser | 1000 | pod 应以其启动的用户 ID |
| securityContext.fsGroupChangePolicy | 改变卷的所有权和权限的策略(需要 Kubernetes 1.23) | |
| securityContext.seccompProfile.type | RuntimeDefault | 使用的 seccomp 配置文件 |
| containerSecurityContext | 覆盖容器 securityContext 以启动容器 | |
| containerSecurityContext.runAsUser | 1000 | 允许覆盖容器启动的特定安全上下文用户 ID |
| containerSecurityContext.allowPrivilegeEscalation | false | 控制 Gitaly 容器的进程是否可以获得比其父进程更多的权限 |
| containerSecurityContext.runAsNonRoot | true | 控制容器是否以非 root 用户运行 |
| containerSecurityContext.capabilities.drop | [ "ALL" ] | 删除 Gitaly 容器的 Linux 能力 |
| serviceAccount.automountServiceAccountToken | false | 指示是否应在 pod 中挂载默认 ServiceAccount 访问令牌 |
| serviceAccount.enabled | false | 指示是否使用 ServiceAccount |
| serviceLabels | {} | 补充服务标签 |
| tokenService | container_registry | JWT 令牌服务 |
| tokenIssuer | gitlab-issuer | JWT 令牌发行者 |
| tolerations | [] | pod 分配的容忍标签 |
| affinity | {} | pod 分配的亲和性规则 |
| middleware.storage | 中间件存储的配置层 | |
| redis.cache.enabled | false | 设置为 true 时,启用 Redis 缓存。此功能依赖于 metadata database 启用。存储库元数据将缓存在配置的 Redis 实例上。 |
| redis.cache.host | <Redis URL> | Redis 实例的主机名。如果为空,值将被填充为 global.redis.host:global.redis.port。 |
| redis.cache.port | 6379 | Redis 实例的端口。 |
| redis.cache.sentinels | [] | 列出带有主机和端口的哨兵。 |
| redis.cache.mainname | 主服务器名称。仅适用于哨兵。 | |
| redis.cache.password.enabled | false | 指示极狐GitLab 镜像仓库使用的 Redis 缓存是否受密码保护。 |
| redis.cache.password.secret | gitlab-redis-secret | 包含 Redis 密码的密钥名称。如果未提供,将自动创建此密钥,当启用 shared-secrets 功能时。 |
| redis.cache.password.key | redis-password | 存储 Redis 密码的密钥。 |
| redis.cache.sentinelpassword.enabled | false | 指示 Redis 哨兵是否受密码保护。如果 redis.cache.sentinelpassword 为空,将使用 global.redis.sentinelAuth 中的值。仅在定义 redis.cache.sentinels 时使用。 |
| redis.cache.sentinelpassword.secret | gitlab-redis-secret | 包含 Redis Sentinel 密码的密钥名称。 |
| redis.cache.sentinelpassword.key | redis-sentinel-password | 存储 Redis Sentinel 密码的密钥。 |
| redis.cache.db | 0 | 为每个连接使用的数据库名称。 |
| redis.cache.dialtimeout | 0s | 连接到 Redis 实例的超时。默认为无超时。 |
| redis.cache.readtimeout | 0s | 从 Redis 实例读取的超时。默认为无超时。 |
| redis.cache.writetimeout | 0s | 写入 Redis 实例的超时。默认为无超时。 |
| redis.cache.tls.enabled | false | 设置为 true 以启用 TLS。 |
| redis.cache.tls.insecure | false | 设置为 true 以在通过 TLS 连接时禁用服务器名称验证。 |
| redis.cache.pool.size | 10 | 最大套接字连接数。默认是 10 个连接。 |
| redis.cache.pool.maxlifetime | 1h | 客户端在此连接年龄时会放弃连接。默认是不会关闭已老化的连接。 |
| redis.cache.pool.idletimeout | 300s | 关闭不活动连接之前的等待时间。 |
| redis.rateLimiting.enabled | false | 设置为 true 时,启用 Redis 速率限制器。此功能正在开发中。 |
| redis.rateLimiting.host | <Redis URL> | Redis 实例的主机名。如果为空,值将被填充为 global.redis.host:global.redis.port。 |
| redis.rateLimiting.port | 6379 | Redis 实例的端口。 |
| redis.rateLimiting.cluster | [] | 列出带有主机和端口的地址。 |
| redis.rateLimiting.sentinels | [] | 列出带有主机和端口的哨兵。 |
| redis.rateLimiting.mainname | 主服务器名称。仅适用于哨兵。 | |
| redis.rateLimiting.username | 用于连接到 Redis 实例的用户名。 | |
| redis.rateLimiting.password.enabled | false | 指示 Redis 实例是否受密码保护。 |
| redis.rateLimiting.password.secret | gitlab-redis-secret | 包含 Redis 密码的密钥名称。如果未提供,将自动创建此密钥,当启用 shared-secrets 功能时。 |
| redis.rateLimiting.password.key | redis-password | 存储 Redis 密码的密钥。 |
| redis.rateLimiting.db | 0 | 为每个连接使用的数据库名称。 |
| redis.rateLimiting.dialtimeout | 0s | 连接到 Redis 实例的超时。默认为无超时。 |
| redis.rateLimiting.readtimeout | 0s | 从 Redis 实例读取的超时。默认为无超时。 |
| redis.rateLimiting.writetimeout | 0s | 写入 Redis 实例的超时。默认为无超时。 |
| redis.rateLimiting.tls.enabled | false | 设置为 true 以启用 TLS。 |
| redis.rateLimiting.tls.insecure | false | 设置为 true 以在通过 TLS 连接时禁用服务器名称验证。 |
| redis.rateLimiting.pool.size | 10 | 最大套接字连接数。 |
| redis.rateLimiting.pool.maxlifetime | 1h | 客户端在此连接年龄时会放弃连接。默认是不会关闭已老化的连接。 |
| redis.rateLimiting.pool.idletimeout | 300s | 关闭不活动连接之前的等待时间。 |
| redis.loadBalancing.enabled | false | 设置为 true 时,启用 Redis 连接以进行 负载均衡。 |
| redis.loadBalancing.host | <Redis URL> | Redis 实例的主机名。如果为空,值将被填充为 global.redis.host:global.redis.port。 |
| redis.loadBalancing.port | 6379 | Redis 实例的端口。 |
| redis.loadBalancing.cluster | [] | 列出带有主机和端口的地址。 |
| redis.loadBalancing.sentinels | [] | 列出带有主机和端口的哨兵。 |
| redis.loadBalancing.mainname | 主服务器名称。仅适用于哨兵。 | |
| redis.loadBalancing.username | 用于连接到 Redis 实例的用户名。 | |
| redis.loadBalancing.password.enabled | false | 指示 Redis 实例是否受密码保护。 |
| redis.loadBalancing.password.secret | gitlab-redis-secret | 包含 Redis 密码的密钥名称。如果未提供,将自动创建此密钥,当启用 shared-secrets 功能时。 |
| redis.loadBalancing.password.key | redis-password | 存储 Redis 密码的密钥。 |
| redis.loadBalancing.db | 0 | 为每个连接使用的数据库名称。 |
| redis.loadBalancing.dialtimeout | 0s | 连接到 Redis 实例的超时。默认为无超时。 |
| redis.loadBalancing.readtimeout | 0s | 从 Redis 实例读取的超时。默认为无超时。 |
| redis.loadBalancing.writetimeout | 0s | 写入 Redis 实例的超时。默认为无超时。 |
| redis.loadBalancing.tls.enabled | false | 设置为 true 以启用 TLS。 |
| redis.loadBalancing.tls.insecure | false | 设置为 true 以在通过 TLS 连接时禁用服务器名称验证。 |
| redis.loadBalancing.pool.size | 10 | 最大套接字连接数。 |
| redis.loadBalancing.pool.maxlifetime | 1h | 客户端在此连接年龄时会放弃连接。默认是不会关闭已老化的连接。 |
| redis.loadBalancing.pool.idletimeout | 300s | 关闭不活动连接之前的等待时间。 |
chart 配置示例
pullSecrets
pullSecrets 允许您通过身份验证到私有镜像仓库以拉取 pod 的图像。
以下是 pullSecrets 的一个示例用法:
yaml1image: 2 repository: my.registry.repository 3 tag: latest 4 pullPolicy: Always 5 pullSecrets: 6 - name: my-secret-name 7 - name: my-secondary-secret-name
serviceAccount
此部分控制是否应创建 ServiceAccount,以及是否应在 pod 中挂载默认访问令牌。
| 名称 | 类型 | 默认值 | 描述 |
|---|---|---|---|
| automountServiceAccountToken | Boolean | false | 控制是否应在 pod 中挂载默认 ServiceAccount 访问令牌。除非某些 sidecars 需要才能正常工作(例如 Istio),否则不应启用此选项。 |
| enabled | Boolean | false | 指示是否使用 ServiceAccount。 |
tolerations
tolerations 允许您在受污点的工作节点上调度 pod
以下是 tolerations 的一个示例用法:
yaml1tolerations: 2- key: "node_label" 3 operator: "Equal" 4 value: "true" 5 effect: "NoSchedule" 6- key: "node_label" 7 operator: "Equal" 8 value: "true" 9 effect: "NoExecute"
affinity
affinity 是一个可选参数,允许您设置一个或两个:
- podAntiAffinity 规则:
- 不在与表达式对应的 topology key 相同的域中调度 pod。
- 设置两种 podAntiAffinity 规则模式:必需(requiredDuringSchedulingIgnoredDuringExecution)和首选(preferredDuringSchedulingIgnoredDuringExecution)。使用 values.yaml 中的变量 antiAffinity,将设置设置为 soft 以应用首选模式,或设置为 hard 以应用必需模式。
- nodeAffinity 规则:
- 将 pod 调度到属于特定区域或多个区域的节点。
- 设置两种 nodeAffinity 规则模式:必需(requiredDuringSchedulingIgnoredDuringExecution)和首选(preferredDuringSchedulingIgnoredDuringExecution)。设置为 soft 时应用首选模式。设置为 hard 时应用必需模式。此规则仅对 registry chart 以及 gitlab chart 及其所有子 chart (webservice 和 sidekiq 除外)实施。
nodeAffinity 仅实现了 In 操作符。
有关更多信息,请参阅 相关 Kubernetes 文档。
以下示例设置 affinity,其中 nodeAffinity 和 antiAffinity 均设置为 hard:
yaml1nodeAffinity: "hard" 2antiAffinity: "hard" 3affinity: 4 nodeAffinity: 5 key: "test.com/zone" 6 values: 7 - us-east1-a 8 - us-east1-b 9 podAntiAffinity: 10 topologyKey: "test.com/hostname"
annotations
annotations 允许您向镜像仓库 pod 添加注释。
以下是 annotations 的一个示例用法:
yamlannotations: kubernetes.io/example-annotation: annotation-value
启用子 chart
我们选择的实现分隔子 chart 的方法包括禁用您可能不希望在给定部署中使用的组件的能力。因此,您应该决定的第一个设置是 enabled。
默认情况下,镜像仓库开箱即用。如果您希望禁用它,请设置 enabled: false。
配置 image
此部分详细说明此子 chart 的 Deployment 使用的容器图像的设置。您可以更改镜像仓库的包含版本和 pullPolicy。
默认设置:
- tag: 'v4.15.2-gitlab'
- pullPolicy: 'IfNotPresent'
配置 service
此部分控制 Service 的名称和类型。这些设置将由 values.yaml 填充。
默认情况下,服务配置如下:
| 名称 | 类型 | 默认值 | 描述 |
|---|---|---|---|
| name | String | registry | 配置服务的名称 |
| type | String | ClusterIP | 配置服务的类型 |
| externalPort | Int | 5000 | 服务公开的端口 |
| internalPort | Int | 5000 | Pod 用于接受服务请求的端口 |
| clusterIP | String | null | 允许根据需要配置自定义集群 IP |
| loadBalancerIP | String | null | 允许根据需要配置自定义负载均衡器 IP 地址 |
配置 ingress
此部分控制镜像仓库 Ingress。
| 名称 | 类型 | 默认值 | 描述 |
|---|---|---|---|
| apiVersion | String | 在 apiVersion 字段中使用的值。 | |
| annotations | String | 此字段与 Kubernetes Ingress 的标准 annotations 完全匹配。 | |
| configureCertmanager | Boolean | 切换 Ingress 注释 cert-manager.io/issuer 和 acme.cert-manager.io/http01-edit-in-place。有关更多信息,请参见 GitLab Pages 的 TLS 要求。 | |
| enabled | Boolean | false | 控制是否为支持它们的服务创建 Ingress 对象的设置。当 false 时,使用 global.ingress.enabled 设置。 |
| tls.enabled | Boolean | true | 当设置为 false 时,您会为镜像仓库子 chart 禁用 TLS。这主要适用于您无法在 ingress-level 使用 TLS 终止的情况,例如当您在 Ingress 控制器之前有 TLS 终止代理时。 |
| tls.secretName | String | 包含镜像仓库 URL 的有效证书和密钥的 Kubernetes TLS Secret 的名称。未设置时,使用 global.ingress.tls.secretName。默认为未设置。 | |
| tls.cipherSuites | Array | [] | 在 TLS 握手期间容器镜像仓库应向客户端提供的密码套件列表。 |
配置 TLS
容器镜像仓库支持 TLS,可以保护其与其他组件的通信,包括 nginx-ingress。
配置 TLS 的先决条件:
- TLS 证书必须在公共名称(CN)或主题备用名称(SAN)中包含镜像仓库服务主机名(例如 RELEASE-registry.default.svc)。
- 生成 TLS 证书后:
- 创建一个 Kubernetes TLS Secret
- 创建另一个仅包含 TLS 证书的 CA 证书的 Secret,密钥为 ca.crt。
启用 TLS:
- 设置 registry.tls.enabled 为 true。
- 设置 global.hosts.registry.protocol 为 https。
- 将 Secret 名称相应地传递给 registry.tls.secretName 和 global.certificates.customCAs。
当 registry.tls.verify 为 true 时,您必须将 CA 证书 Secret 的名称传递给 registry.tls.caSecretName。对于自签名证书和自定义证书颁发机构,这一点很重要。NGINX 使用此 Secret 来验证镜像仓库的 TLS 证书。
例如:
yaml1global: 2 certificates: 3 customCAs: 4 - secret: registry-tls-ca 5 hosts: 6 registry: 7 protocol: https 8 9registry: 10 tls: 11 enabled: true 12 secretName: registry-tls 13 verify: true 14 caSecretName: registry-tls-ca
容器镜像仓库密码套件
通常,tls.cipherSuites 选项应仅在镜像仓库以独立模式部署且/或使用不支持现代密码套件的非默认 Ingress 时使用。在标准的极狐GitLab 部署中,NGINX Ingress 将选择容器镜像仓库后端支持的最高 TLS 版本,目前为 TLS1.3。TLS1.3 不允许配置密码,并且默认情况下是安全的。如果由于某种原因 TLS1.3 不可用,容器镜像仓库使用的默认 TLS1.2 密码列表也与 NGINX Ingress 默认设置兼容并且也是安全的。
配置调试端口的 TLS
镜像仓库调试端口也支持 TLS。调试端口用于 Kubernetes 的活跃性和就绪性检查以及(如果启用)暴露 Prometheus 的 /metrics 端点。
可以通过将 registry.debug.tls.enabled 设置为 true 来启用 TLS。可以在 registry.debug.tls.secretName 中为调试端口的 TLS 配置提供专用的 Kubernetes TLS Secret。如果未指定专用密钥,调试配置将默认共享 registry.tls.secretName 与镜像仓库的常规 TLS 配置。
为了让 Prometheus 使用 https 抓取 /metrics/ 端点 - 需要为证书的 CommonName 属性或 SubjectAlternativeName 条目进行其他配置。请参阅 配置 Prometheus 以抓取 TLS 启用的端点 以获取这些要求。
配置 networkpolicy
此部分控制镜像仓库 NetworkPolicy。此配置是可选的,用于限制镜像仓库的出口和入口到特定端点。
| 名称 | 类型 | 默认值 | 描述 |
|---|---|---|---|
| enabled | Boolean | false | 此设置启用镜像仓库的 NetworkPolicy |
| ingress.enabled | Boolean | false | 设置为 true 时,将激活 Ingress 网络策略。这将阻止所有入口连接,除非指定了规则。 |
| ingress.rules | Array | [] | 入口策略的规则,详细信息请参见 https://kubernetes.io/docs/concepts/services-networking/network-policies/#the-networkpolicy-resource 和下面的示例 |
| egress.enabled | Boolean | false | 设置为 true 时,将激活 Egress 网络策略。这将阻止所有出口连接,除非指定了规则。 |
| egress.rules | 数组 | [] | 出口策略的规则,详细信息请参见 Kubernetes 官方文档和下方示例 |
防止连接到所有内部端点的示例策略
镜像仓库服务通常需要到对象存储的出口连接,从 Docker 客户端的入口连接,以及用于 DNS 查找的 kube-dns。这为镜像仓库服务添加了以下网络限制:
- 允许入口请求:
- 从 sidekiq、webservice 和 nginx-ingress pod 到端口 5000
- 从 Prometheus pod 到端口 9235
- 允许出口请求:
- 到 kube-dns 的端口 53
- 到 AWS VPC 端点之类的端点,针对 S3 或 STS 172.16.1.0/24 的端口 443
- 到互联网 0.0.0.0/0 的端口 443
请注意,如果未使用端点,镜像仓库服务需要到公共互联网的出站连接以获取外部对象存储上的镜像
示例基于以下假设:kube-dns 部署在命名空间 kube-system 中,prometheus 部署在命名空间 monitoring 中,nginx-ingress 部署在命名空间 nginx-ingress 中。
yaml1networkpolicy: 2 enabled: true 3 ingress: 4 enabled: true 5 rules: 6 - from: 7 - namespaceSelector: 8 matchLabels: 9 kubernetes.io/metadata.name: nginx-ingress 10 podSelector: 11 matchLabels: 12 app: nginx-ingress 13 component: controller 14 ports: 15 - port: 5000 16 - from: 17 - namespaceSelector: 18 matchLabels: 19 kubernetes.io/metadata.name: monitoring 20 podSelector: 21 matchLabels: 22 app: prometheus 23 component: server 24 release: gitlab 25 ports: 26 - port: 9235 27 - from: 28 - podSelector: 29 matchLabels: 30 app: sidekiq 31 ports: 32 - port: 5000 33 - from: 34 - podSelector: 35 matchLabels: 36 app: webservice 37 ports: 38 - port: 5000 39 egress: 40 enabled: true 41 rules: 42 - to: 43 - namespaceSelector: 44 matchLabels: 45 kubernetes.io/metadata.name: kube-system 46 podSelector: 47 matchLabels: 48 k8s-app: kube-dns 49 ports: 50 - port: 53 51 protocol: UDP 52 - to: 53 - ipBlock: 54 cidr: 172.16.1.0/24 55 ports: 56 - port: 443 57 - to: 58 - ipBlock: 59 cidr: 0.0.0.0/0 60 except: 61 - 10.0.0.0/8
配置 KEDA
此 keda 部分启用 KEDA ScaledObjects 的安装,而不是常规的 HorizontalPodAutoscalers。此配置是可选的,可在需要基于自定义或外部指标进行自动缩放时使用。
大多数设置默认为在 hpa 部分中设置的值(如果适用)。
如果以下条件为真,则根据在 hpa 部分中设置的 CPU 和内存阈值自动添加 CPU 和内存触发器:
- 未设置 triggers。
- 相应的 request.cpu.request 或 request.memory.request 设置也设置为非零值。
如果未设置任何触发器,则不会创建 ScaledObject。
| 名称 | 类型 | 默认值 | 描述 |
|---|---|---|---|
| enabled | 布尔值 | false | 使用 KEDA 的 ScaledObjects 替代 HorizontalPodAutoscalers |
| pollingInterval | 整数 | 30 | 检查每个触发器的时间间隔 |
| cooldownPeriod | 整数 | 300 | 在最后一个触发器报告为活跃后,等待多长时间再将资源缩容到 0 |
| minReplicaCount | 整数 | KEDA 缩容时的最小副本数,默认为 hpa.minReplicas | |
| maxReplicaCount | 整数 | KEDA 扩容时的最大副本数,默认为 hpa.maxReplicas | |
| fallback | 映射 | KEDA 回退配置,详见官方文档 | |
| hpaName | 字符串 | KEDA 创建的 HPA 资源名称,默认为 keda-hpa-{scaled-object-name} | |
| restoreToOriginalReplicaCount | 布尔值 | 指定在删除 ScaledObject 后,目标资源是否恢复到原始副本数 | |
| behavior | 映射 | 扩缩容行为的详细配置,默认为 hpa.behavior | |
| triggers | 数组 | 激活目标资源自动扩缩容的触发器列表,默认为根据 hpa.cpu 和 hpa.memory 计算的触发器 |
防止连接到所有内部端点的示例策略
镜像仓库服务通常需要到对象存储的出口连接,从 Docker 客户端的入口连接,以及用于 DNS 查找的 kube-dns。这为镜像仓库服务添加了以下网络限制:
- 允许到本地网络 10.0.0.0/8 端口 53 的所有出口请求(用于 kubeDNS)
- 限制对本地网络 10.0.0.0/8 的其他出口请求
- 允许对 10.0.0.0/8 之外的出口请求
请注意,镜像仓库服务需要到公共互联网的出站连接以获取外部对象存储上的镜像
yaml1networkpolicy: 2 enabled: true 3 egress: 4 enabled: true 5 # The following rules enable traffic to all external 6 # endpoints, except the local 7 # network (except DNS requests) 8 rules: 9 - to: 10 - ipBlock: 11 cidr: 10.0.0.0/8 12 ports: 13 - port: 53 14 protocol: UDP 15 - to: 16 - ipBlock: 17 cidr: 0.0.0.0/0 18 except: 19 - 10.0.0.0/8
定义镜像仓库配置
此 chart 的以下属性与底层镜像仓库容器的配置有关。仅公开与极狐GitLab 集成的最关键值。对于此集成,我们使用 Docker 分发的 auth.token.x 设置,通过 JWT 身份验证令牌控制对镜像仓库的身份验证。
httpSecret
字段 httpSecret 是一个包含两个项目的映射:secret 和 key。
此引用的键的内容与镜像仓库的 http.secret 值相关联。此值应填充为加密生成的随机字符串。
如果未提供,shared-secrets 任务将自动创建此密钥。它将填充一个安全生成的 128 个字符的字母数字字符串,并进行 base64 编码。
手动创建此密钥:
shellkubectl create secret generic gitlab-registry-httpsecret --from-literal=secret=strongrandomstring
通知密钥
通知密钥用于以各种方式回调极狐GitLab 应用程序,例如用于 Geo 帮助管理主站点和次站点之间的容器镜像仓库数据同步。
如果未提供,当启用 shared-secrets 功能时,notificationSecret 密钥对象将自动创建。
手动创建此密钥:
shellkubectl create secret generic gitlab-registry-notification --from-literal=secret=[\"strongrandomstring\"]
然后继续设置
yaml1global: 2 # To provide your own secret 3 registry: 4 notificationSecret: 5 secret: gitlab-registry-notification 6 key: secret 7 8 # If utilising Geo, and wishing to sync the container registry. 9 # Define this in the primary site configs only. 10 geo: 11 registry: 12 replication: 13 enabled: true 14 primaryApiUrl: <URL to primary registry>
确保 secret 值设置为上述创建的密钥的名称
Redis 缓存密钥
当 global.redis.auth.enabled 设置为 true 时,将使用 Redis 缓存密钥。
当启用 shared-secrets 功能时,如果未提供,gitlab-redis-secret 密钥对象会自动创建。
要手动创建此密钥,请参阅 Redis 密码说明。
authEndpoint
authEndpoint 字段是一个字符串,提供极狐GitLab 实例的 URL,这些实例将由镜像仓库进行身份验证。
该值应仅包含协议和主机名。chart 模板将自动附加必要的请求路径。生成的值将填充到容器内的 auth.token.realm。例如:authEndpoint: "https://gitlab.example.com"
默认情况下,此字段填充为全局设置中设置的极狐GitLab 主机名配置。
证书
certificate 字段是一个包含两个项目的映射:secret 和 key。
secret 是一个字符串,包含Kubernetes Secret的名称,该密钥存储用于验证由极狐GitLab 实例创建的令牌的证书包。
key 是 Secret 中存储证书包的 key 的名称,该证书包将作为 auth.token.rootcertbundle 提供给镜像仓库容器。
默认示例:
yamlcertificate: secret: gitlab-registry key: registry-auth.crt
就绪和存活探测
默认情况下配置了就绪和存活探测,以检查端口 5001 上的 /debug/health,这是调试端口。
验证
validation 字段是一个映射,用于控制镜像仓库中 Docker 镜像的验证过程。当启用镜像验证时,镜像仓库会拒绝具有外部层的 Windows 镜像,除非显式设置了验证节中的 manifests.urls.allow 字段以允许那些层的 URL。
验证仅在清单推送期间发生,因此镜像仓库中已存在的镜像不受此部分中的值更改的影响。
默认情况下,图像验证是关闭的。
要启用图像验证,需要显式设置 registry.validation.disabled: false。
manifests
manifests 字段允许配置特定于清单的验证策略。
urls 部分包含 allow 和 deny 字段。对于包含 URL 的清单层以通过验证,该层必须匹配 allow 字段中的正则表达式之一,同时不匹配 deny 字段中的任何正则表达式。
| 名称 | 类型 | 默认值 | 描述 |
|---|---|---|---|
| referencelimit | 整数 | 0 | 单个清单(manifest)允许的最大引用数量,例如层(layers)、镜像配置和其他清单。当设置为 0(默认)时,此验证被禁用。 |
| payloadsizelimit | 整数 | 0 | 清单(manifest)有效载荷的最大数据字节数。当设置为 0(默认)时,此验证被禁用。 |
| urls.allow | 数组 | [] | 允许清单层中 URL 的正则表达式列表。留空(默认)时,包含任意 URL 的层将被拒绝。 |
| urls.deny | 数组 | [] | 限制清单层中 URL 的正则表达式列表。留空(默认)时,未被 urls.allow 列表拒绝的 URL 不会被拒绝。 |
通知
notifications 字段用于配置镜像仓库通知。默认值为空哈希。
| 名称 | 类型 | 默认值 | 描述 |
|---|---|---|---|
| endpoints | 数组 | [] | 每个条目对应一个 endpoint 的条目列表 |
| events | 哈希 | {} | 在 event 通知中提供的信息 |
一个示例设置如下所示:
yaml1notifications: 2 endpoints: 3 - name: FooListener 4 url: https://foolistener.com/event 5 timeout: 500ms 6 # DEPRECATED: use `maxretries` instead https://gitlab.com/gitlab-org/container-registry/-/issues/1243. 7 # When using `maxretries`, `threshold` is ignored: https://gitlab.com/gitlab-org/container-registry/-/blob/master/docs/configuration.md?ref_type=heads#endpoints 8 threshold: 10 9 maxretries: 10 10 backoff: 1s 11 - name: BarListener 12 url: https://barlistener.com/event 13 timeout: 100ms 14 # DEPRECATED: use `maxretries` instead https://gitlab.com/gitlab-org/container-registry/-/issues/1243. 15 # When using `maxretries`, `threshold` is ignored: https://gitlab.com/gitlab-org/container-registry/-/blob/master/docs/configuration.md?ref_type=heads#endpoints 16 threshold: 3 17 maxretries: 5 18 backoff: 1s 19 events: 20 includereferences: true
hpa
hpa 字段是一个对象,控制要创建为集合一部分的镜像仓库实例的数量。默认情况下,minReplicas 值为 2,maxReplicas 值为 10,并将 cpu.targetAverageUtilization 配置为 75%。
存储
yamlstorage: secret: key: config extraKey:
storage 字段是对 Kubernetes Secret 和关联键的引用。此密钥的内容直接取自镜像仓库配置:storage。请参阅该文档以获取更多详细信息。
对于 S3,请确保您授予正确的镜像仓库存储权限。有关存储配置的更多信息,请参阅管理文档中的容器镜像仓库存储驱动程序。
将 storage 块的 内容 放入密钥中,并提供以下作为 storage 映射的项目:
- secret:Kubernetes Secret 的名称,存放 YAML 块。
- key:密钥中要使用的键的名称。默认为 config。
- extraKey:(可选) 密钥中的额外键的名称,将挂载到容器内的 /etc/docker/registry/storage/${extraKey}。这可以用于为 gcs 驱动程序提供 keyfile。
shell1# Example using S3 2kubectl create secret generic registry-storage \ 3 --from-file=config=registry-storage.yaml 4 5# Example using GCS with JSON key 6# - Note: `registry.storage.extraKey=gcs.json` 7kubectl create secret generic registry-storage \ 8 --from-file=config=registry-storage.yaml \ 9 --from-file=gcs.json=example-project-382839-gcs-bucket.json
您可以禁用存储驱动程序的重定向,确保所有流量都通过镜像仓库服务,而不是重定向到另一个后端:
yamlstorage: secret: example-secret key: config redirect: disable: true
如果您选择使用 filesystem 驱动程序:
- 您需要为此数据提供持久卷。
- hpa.minReplicas 应设置为 1
- hpa.maxReplicas 应设置为 1
为了简化和提高弹性,建议使用外部服务,例如 s3、gcs、azure 或其他兼容的对象存储。
如果用户未指定,chart 会默认将 delete.enabled: true 填充到此配置中。这与默认使用 MinIO 以及 Linux 软件包的预期行为保持一致。任何用户提供的值将优先于此默认值。
middleware.storage
middleware.storage 的配置遵循上游约定:
配置相当通用,遵循类似的模式:
yaml1middleware: 2 # See https://gitlab.com/gitlab-org/container-registry/-/blob/master/docs/configuration.md#middleware 3 storage: 4 - name: cloudfront 5 options: 6 baseurl: https://abcdefghijklmn.cloudfront.net/ 7 # `privatekey` is auto-populated with the content from the privatekey Secret. 8 privatekeySecret: 9 secret: cloudfront-secret-name 10 # "key" value is going to be used to generate filename for PEM storage: 11 # /etc/docker/registry/middleware.storage/<index>/<key> 12 key: private-key-ABC.pem 13 keypairid: ABCEDFGHIJKLMNOPQRST
在上面的代码中,options.privatekeySecret 是一个 generic Kubernetes 密钥,其内容对应于 PEM 文件内容:
shellkubectl create secret generic cloudfront-secret-name --type=kubernetes.io/ssh-auth --from-file=private-key-ABC.pem=pk-ABCEDFGHIJKLMNOPQRST.pem
上游使用的 privatekey 将由 chart 从 privatekey Secret 自动填充,如果指定将被忽略。
keypairid 变体
不同供应商对相同结构使用不同的字段名称:
| 供应商 | 字段名称 |
|---|---|
| Google CDN | keyname |
| CloudFront | keypairid |
目前仅支持 middleware.storage 部分的配置。
调试
默认情况下,调试端口已启用,并用于存活/就绪探测。此外,可以通过 metrics 值启用 Prometheus 指标。
yaml1debug: 2 addr: 3 port: 5001 4 5metrics: 6 enabled: true
健康检查
health 属性是可选的,包含有关存储驱动程序后端存储的定期健康检查的偏好。
yamlhealth: storagedriver: enabled: false interval: 10s threshold: 3
报告
reporting 属性是可选的,启用报告
yamlreporting: sentry: enabled: true dsn: 'https://<key>@sentry.io/<project>' environment: 'production'
分析
profiling 属性是可选的,启用持续分析
yaml1profiling: 2 stackdriver: 3 enabled: true 4 credentials: 5 secret: gitlab-registry-profiling-creds 6 key: credentials 7 service: gitlab-registry
数据库
History
- 在极狐GitLab 16.4 中引入为测试版功能。
- 在极狐GitLab 17.3 中 GA。
database 属性是可选的,启用元数据数据库。
在启用此功能之前,请参阅管理文档。
此功能需要 PostgreSQL 13 或更高版本。
yaml1database: 2 enabled: true 3 host: registry.db.example.com 4 port: 5432 5 user: registry 6 password: 7 secret: gitlab-postgresql-password 8 key: postgresql-registry-password 9 dbname: registry 10 sslmode: verify-full 11 ssl: 12 secret: gitlab-registry-postgresql-ssl 13 clientKey: client-key.pem 14 clientCertificate: client-cert.pem 15 serverCA: server-ca.pem 16 connecttimeout: 5s 17 draintimeout: 2m 18 preparedstatements: false 19 primary: 'primary.record.fqdn' 20 pool: 21 maxidle: 25 22 maxopen: 25 23 maxlifetime: 5m 24 maxidletime: 5m 25 migrations: 26 enabled: true 27 activeDeadlineSeconds: 3600 28 backoffLimit: 6 29 backgroundMigrations: 30 enabled: true 31 maxJobRetries: 3 32 jobInterval: 10s
负载均衡
这是一个实验性功能,正在积极开发中,不能用于生产环境。
loadBalancing 部分允许配置数据库负载均衡。必须启用相应的Redis 连接才能使此功能正常工作。
管理数据库
有关创建和维护数据库的更多信息,请参阅容器镜像仓库元数据数据库页面。
gc 属性
gc 属性提供在线垃圾收集选项。
在线垃圾收集需要启用元数据数据库。使用数据库时,您必须使用在线垃圾收集,尽管您可以暂时禁用在线垃圾收集以进行维护和调试。
yaml1gc: 2 disabled: false 3 maxbackoff: 24h 4 noidlebackoff: false 5 transactiontimeout: 10s 6 reviewafter: 24h 7 manifests: 8 disabled: false 9 interval: 5s 10 blobs: 11 disabled: false 12 interval: 5s 13 storagetimeout: 5s
Redis 缓存
Redis 缓存是从版本 16.4 开始的测试版功能。
redis.cache 属性是可选的,提供与Redis 缓存相关的选项。要在镜像仓库中使用 redis.cache,必须启用元数据数据库。
例如:
yaml1redis: 2 cache: 3 enabled: true 4 host: localhost 5 port: 16379 6 password: 7 secret: gitlab-redis-secret 8 key: redis-password 9 db: 0 10 dialtimeout: 10ms 11 readtimeout: 10ms 12 writetimeout: 10ms 13 tls: 14 enabled: true 15 insecure: true 16 pool: 17 size: 10 18 maxlifetime: 1h 19 idletimeout: 300s
集群
redis.rateLimiting.cluster 属性是要连接到 Redis 集群的主机和端口列表。例如:
yaml1redis: 2 cache: 3 enabled: true 4 host: redis.example.com 5 cluster: 6 - host: host1.example.com 7 port: 6379 8 - host: host2.example.com 9 port: 6379
Sentinel
redis.cache 可以使用 global.redis.sentinels 配置。可以提供本地值,这些值将优先于全局值。例如:
yaml1redis: 2 cache: 3 enabled: true 4 host: redis.example.com 5 sentinels: 6 - host: sentinel1.example.com 7 port: 16379 8 - host: sentinel2.example.com 9 port: 16379
Sentinel 密码支持
History
- 在极狐GitLab 17.2 中引入。
redis.cache 还可以使用global.redis.sentinelAuth 配置来使用 Redis Sentinel 的身份验证密码。可以提供本地值,并优先于全局值。例如:
yaml1redis: 2 cache: 3 enabled: true 4 host: redis.example.com 5 sentinels: 6 - host: sentinel1.example.com 7 port: 16379 8 - host: sentinel2.example.com 9 port: 16379 10 sentinelpassword: 11 enabled: true 12 secret: registry-redis-sentinel 13 key: password
Redis 速率限制器
Redis 速率限制正在开发中。随着功能细节的可用,将添加到此部分中。
redis.rateLimiting 属性是可选的,提供与Redis 速率限制器相关的选项。
例如:
yaml1redis: 2 rateLimiting: 3 enabled: true 4 host: localhost 5 port: 16379 6 username: registry 7 password: 8 secret: gitlab-redis-secret 9 key: redis-password 10 db: 0 11 dialtimeout: 10ms 12 readtimeout: 10ms 13 writetimeout: 10ms 14 tls: 15 enabled: true 16 insecure: true 17 pool: 18 size: 10 19 maxlifetime: 1h 20 idletimeout: 300s
数据库负载均衡的 Redis
状态:实验
History
- 在 Charts 8.11 中引入。
数据库负载均衡是一个正在积极开发中的实验性功能,不能用于生产环境。
redis.loadBalancing 属性是可选的,提供与数据库负载均衡的 Redis 连接相关的选项。
例如:
yaml1redis: 2 loadBalancing: 3 enabled: true 4 host: localhost 5 port: 16379 6 username: registry 7 password: 8 secret: gitlab-redis-secret 9 key: redis-password 10 db: 0 11 dialtimeout: 10ms 12 readtimeout: 10ms 13 writetimeout: 10ms 14 tls: 15 enabled: true 16 insecure: true 17 pool: 18 size: 10 19 maxlifetime: 1h 20 idletimeout: 300s
垃圾收集
Docker 镜像仓库会随着时间的推移积累多余的数据,可以使用垃圾收集释放这些数据。
使用元数据数据库时,必须使用在线垃圾收集。使用元数据数据库进行手动垃圾收集将导致数据丢失。在线垃圾收集完全替代了手动运行垃圾收集的需要。
手动垃圾收集
手动垃圾收集首先需要将镜像仓库置于只读模式。假设您已经使用 Helm 安装了极狐GitLab chart,将其命名为 mygitlab,并安装在命名空间 gitlabns 中。根据您的实际配置替换以下命令中的这些值。
shell1# 因为 https://github.com/helm/helm/issues/2948,我们不能依赖 --reuse-values,所以让我们获取当前配置。 2helm get values mygitlab > mygitlab.yml 3# 升级 Helm 安装并配置镜像仓库为只读。 4# --wait 参数使 Helm 等到所有资源处于就绪状态,因此我们可以安全地继续。 5helm upgrade mygitlab gitlab/gitlab -f mygitlab.yml --set registry.maintenance.readonly.enabled=true --wait 6# 我们的镜像仓库现在处于 r/o 模式,所以让我们获取一个镜像仓库 Pod 的名称。 7# 记下 Pod 名称,并用该值替换下面的 '<registry-pod>' 占位符。 8# 如果您在 Windows 的 cmd.exe 中使用此命令,请将单引号替换为双引号(' => ")。 9kubectl get pods -n gitlabns -l app=registry -o jsonpath='{.items[0].metadata.name}' 10# 运行实际的垃圾收集。如果您真的想要 '-m' 参数,请检查镜像仓库的手册。 11kubectl exec -n gitlabns <registry-pod> -- /bin/registry garbage-collect -m /etc/docker/registry/config.yml 12# 将镜像仓库重置为原始状态。 13helm upgrade mygitlab gitlab/gitlab -f mygitlab.yml --wait 14# 完成 :)
运行针对容器镜像仓库的管理命令
管理命令只能从镜像仓库 Pod 中运行,其中 registry 二进制文件以及必要的配置可用。
要运行管理命令:
-
连接到镜像仓库 Pod:
shellkubectl exec -it <registry-pod> -- bash -
一旦进入镜像仓库 Pod,registry 二进制文件在 PATH 中可用,可以直接使用。配置文件位于 /etc/docker/registry/config.yml。以下示例检查数据库迁移的状态:
shellregistry database migrate status /etc/docker/registry/config.yml