{{< details >}}

  • Tier: 基础版,专业版,旗舰版
  • Offering: 私有化部署

{{< /details >}}

{{< alert type=”warning” >}}

此功能在极狐GitLab 14.5 中已被弃用。

{{< /alert >}}

通过实例级 Kubernetes 群集,您可以将 Kubernetes 群集连接到极狐GitLab 实例,并在实例内的所有项目中使用相同的群集。

用户需要管理员访问权限才能使用这些端点。

列出实例群集

返回实例群集列表。

GET /admin/clusters

示例请求:

curl --header "Private-Token: <your_access_token>" "https://gitlab.example.com/api/v4/admin/clusters"

示例响应:

[
  {
    "id": 9,
    "name": "cluster-1",
    "created_at": "2020-07-14T18:36:10.440Z",
    "managed": true,
    "enabled": true,
    "domain": null,
    "provider_type": "user",
    "platform_type": "kubernetes",
    "environment_scope": "*",
    "cluster_type": "instance_type",
    "user": {
      "id": 1,
      "name": "Administrator",
      "username": "root",
      "state": "active",
      "avatar_url": "https://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon",
      "web_url": "https://gitlab.example.com/root"
    },
    "platform_kubernetes": {
      "api_url": "https://example.com",
      "namespace": null,
      "authorization_type": "rbac",
      "ca_cert":"-----BEGIN CERTIFICATE-----IxMDM1MV0ZDJkZjM...-----END CERTIFICATE-----"
    },
    "provider_gcp": null,
    "management_project": null
  },
  {
    "id": 10,
    "name": "cluster-2",
    "created_at": "2020-07-14T18:39:05.383Z",
    "domain": null,
    "provider_type": "user",
    "platform_type": "kubernetes",
    "environment_scope": "staging",
    "cluster_type": "instance_type",
    "user": {
      "id": 1,
      "name": "Administrator",
      "username": "root",
      "state": "active",
      "avatar_url": "https://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon",
      "web_url": "https://gitlab.example.com/root"
    },
    "platform_kubernetes": {
      "api_url": "https://example.com",
      "namespace": null,
      "authorization_type": "rbac",
      "ca_cert":"-----BEGIN CERTIFICATE-----LzEtMCadtaLGxcsGAZjM...-----END CERTIFICATE-----"
    },
    "provider_gcp": null,
    "management_project": null
  },
  {
    "id": 11,
    "name": "cluster-3",
    ...
  }
]

获取单个实例群集

返回单个实例群集。

参数:

属性 类型 必需 描述
cluster_id integer 群集的 ID
GET /admin/clusters/:cluster_id

示例请求:

curl --header "Private-Token: <your_access_token>" "https://gitlab.example.com/api/v4/admin/clusters/9"

示例响应:

{
  "id": 9,
  "name": "cluster-1",
  "created_at": "2020-07-14T18:36:10.440Z",
  "managed": true,
  "enabled": true,
  "domain": null,
  "provider_type": "user",
  "platform_type": "kubernetes",
  "environment_scope": "*",
  "cluster_type": "instance_type",
  "user": {
    "id": 1,
    "name": "Administrator",
    "username": "root",
    "state": "active",
    "avatar_url": "https://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon",
    "web_url": "https://gitlab.example.com/root"
  },
  "platform_kubernetes": {
    "api_url": "https://example.com",
    "namespace": null,
    "authorization_type": "rbac",
    "ca_cert":"-----BEGIN CERTIFICATE-----IxMDM1MV0ZDJkZjM...-----END CERTIFICATE-----"
  },
  "provider_gcp": null,
  "management_project": null
}

添加现有实例群集

添加现有 Kubernetes 实例群集。

POST /admin/clusters/add

参数:

属性 类型 必需 描述
name string 群集的名称
domain string 群集的基础域
environment_scope string 群集关联的环境。默认为 *
management_project_id integer 群集的管理项目的 ID
enabled boolean 确定群集是否活跃,默认为 true
managed boolean 确定极狐GitLab 是否管理此群集的命名空间和服务账户。默认为 true
platform_kubernetes_attributes[api_url] string 访问 Kubernetes API 的 URL
platform_kubernetes_attributes[token] string 用于对 Kubernetes 进行身份验证的令牌
platform_kubernetes_attributes[ca_cert] string TLS 证书。如果 API 使用自签名 TLS 证书,则必填。
platform_kubernetes_attributes[namespace] string 与项目相关的唯一命名空间
platform_kubernetes_attributes[authorization_type] string 群集授权类型:rbacabacunknown_authorization。默认为 rbac

示例请求:

curl --header "Private-Token:<your_access_token>" "http://gitlab.example.com/api/v4/admin/clusters/add" \
-H "Accept:application/json" \
-H "Content-Type:application/json" \
-X POST --data '{"name":"cluster-3", "environment_scope":"production", "platform_kubernetes_attributes":{"api_url":"https://example.com", "token":"12345",  "ca_cert":"-----BEGIN CERTIFICATE-----qpoeiXXZafCM0ZDJkZjM...-----END CERTIFICATE-----"}}'

示例响应:

{
  "id": 11,
  "name": "cluster-3",
  "created_at": "2020-07-14T18:42:50.805Z",
  "managed": true,
  "enabled": true,
  "domain": null,
  "provider_type": "user",
  "platform_type": "kubernetes",
  "environment_scope": "production",
  "cluster_type": "instance_type",
  "user": {
    "id": 1,
    "name": "Administrator",
    "username": "root",
    "state": "active",
    "avatar_url": "https://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon",
    "web_url": "http://gitlab.example.com:3000/root"
  },
  "platform_kubernetes": {
    "api_url": "https://example.com",
    "namespace": null,
    "authorization_type": "rbac",
    "ca_cert":"-----BEGIN CERTIFICATE-----qpoeiXXZafCM0ZDJkZjM...-----END CERTIFICATE-----"
  },
  "provider_gcp": null,
  "management_project": null
}

编辑实例群集

更新现有实例群集。

PUT /admin/clusters/:cluster_id

参数:

属性 类型 必需 描述
cluster_id integer 群集的 ID
name string 群集的名称
domain string 群集的基础域
environment_scope string 群集关联的环境
management_project_id integer 群集的管理项目的 ID
enabled boolean 确定群集是否活跃
managed boolean 确定极狐GitLab 是否管理此群集的命名空间和服务账户
platform_kubernetes_attributes[api_url] string 访问 Kubernetes API 的 URL
platform_kubernetes_attributes[token] string 用于对 Kubernetes 进行身份验证的令牌
platform_kubernetes_attributes[ca_cert] string TLS 证书。如果 API 使用自签名 TLS 证书,则必填。
platform_kubernetes_attributes[namespace] string 与项目相关的唯一命名空间

{{< alert type=”note” >}}

只有在通过添加现有 Kubernetes 群集选项或通过添加现有实例群集端点添加群集时,才能更新 nameapi_urlca_certtoken

{{< /alert >}}

示例请求:

curl --header "Private-Token: <your_access_token>" "http://gitlab.example.com/api/v4/admin/clusters/9" \
-H "Content-Type:application/json" \
-X PUT --data '{"name":"update-cluster-name", "platform_kubernetes_attributes":{"api_url":"https://new-example.com","token":"new-token"}}'

示例响应:

{
  "id": 9,
  "name": "update-cluster-name",
  "created_at": "2020-07-14T18:36:10.440Z",
  "managed": true,
  "enabled": true,
  "domain": null,
  "provider_type": "user",
  "platform_type": "kubernetes",
  "environment_scope": "*",
  "cluster_type": "instance_type",
  "user": {
    "id": 1,
    "name": "Administrator",
    "username": "root",
    "state": "active",
    "avatar_url": "https://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon",
    "web_url": "https://gitlab.example.com/root"
  },
  "platform_kubernetes": {
    "api_url": "https://new-example.com",
    "namespace": null,
    "authorization_type": "rbac",
    "ca_cert":"-----BEGIN CERTIFICATE-----IxMDM1MV0ZDJkZjM...-----END CERTIFICATE-----"
  },
  "provider_gcp": null,
  "management_project": null,
  "project": null
}

删除实例群集

删除现有实例群集。不会移除连接的 Kubernetes 群集中的现有资源。

DELETE /admin/clusters/:cluster_id

参数:

属性 类型 必需 描述
cluster_id integer 群集的 ID

示例请求:

curl --request DELETE --header "Private-Token: <your_access_token>" "https://gitlab.example.com/api/v4/admin/clusters/11"