Help us learn about your current experience with the documentation. Take the survey.

每个项目使用多个集群及集群证书(已弃用)

  • Tier: Free, Premium, Ultimate
  • Offering: GitLab.com, GitLab Self-Managed

使用多个 Kubernetes 集群为单个项目配置集群证书的功能在 GitLab 14.5 中已弃用。 要将集群连接到 GitLab,请使用 GitLab agent for Kubernetes

您可以将多个 Kubernetes 集群关联到您的项目中。 这样,您可以为不同的环境(如开发、预发布、生产等)使用不同的集群。 像第一次添加集群那样添加另一个集群,并确保设置环境范围来区分新集群与其他集群。

设置环境范围

当向项目中添加多个 Kubernetes 集群时,您需要使用环境范围来区分它们。 环境范围将集群与环境关联,类似于环境特定的 CI/CD 变量的工作方式。

默认环境范围是 *,这意味着所有作业(无论其环境如何)都使用该集群。 每个范围只能由项目中的单个集群使用,否则会出现验证错误。 此外,没有设置环境关键字的作业无法访问任何集群。

例如,一个项目可能具有以下 Kubernetes 集群:

集群 环境范围
Development *
Production production

并且在 .gitlab-ci.yml 文件中设置了以下环境:

stages:
  - test
  - deploy

test:
  stage: test
  script: sh test

deploy to staging:
  stage: deploy
  script: make deploy
  environment:
    name: staging
    url: https://staging.example.com/

deploy to production:
  stage: deploy
  script: make deploy
  environment:
    name: production
    url: https://example.com/

结果:

  • Development 集群详情在 deploy to staging 作业中可用。
  • Production 集群详情在 deploy to production 作业中可用。
  • test 作业中没有可用的集群详情,因为它没有定义任何环境。