Help us learn about your current experience with the documentation. Take the survey.
实例集群 API(基于证书)(已弃用)
- Tier: Free, Premium, Ultimate
- Offering: GitLab Self-Managed
此功能在 GitLab 14.5 中已被弃用。
通过实例级 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 | 否 | 集群授权类型:rbac、abac 或 unknown_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 | 否 | 与项目相关的唯一命名空间 |
name、api_url、ca_cert 和 token 只有在集群是通过添加现有 Kubernetes 集群选项或通过添加现有实例集群端点添加时才能更新。
示例请求:
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"