299.md 9.7 KB
Newer Older
Lab机器人's avatar
readme  
Lab机器人 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166
# Group clusters API

> 原文:[https://docs.gitlab.com/ee/api/group_clusters.html](https://docs.gitlab.com/ee/api/group_clusters.html)

*   [List group clusters](#list-group-clusters)
*   [Get a single group cluster](#get-a-single-group-cluster)
*   [Add existing cluster to group](#add-existing-cluster-to-group)
*   [Edit group cluster](#edit-group-cluster)
*   [Delete group cluster](#delete-group-cluster)

# Group clusters API[](#group-clusters-api "Permalink")

在 GitLab 12.1 中[引入](https://gitlab.com/gitlab-org/gitlab-foss/-/merge_requests/30213) .

**注意:组**将至少需要用户具有维护者访问权限才能使用这些端点.

## List group clusters[](#list-group-clusters "Permalink")

返回组集群的列表.

```
GET /groups/:id/clusters 
```

Parameters:

| Attribute | Type | Required | Description |
| --- | --- | --- | --- |
| `id` | integer/string | yes | 组的 ID 或[URL 编码的路径](README.html#namespaced-path-encoding) |

请求示例:

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

响应示例:

```
[  {  "id":18,  "name":"cluster-1",  "domain":"example.com",  "created_at":"2019-01-02T20:18:12.563Z",  "provider_type":"user",  "platform_type":"kubernetes",  "environment_scope":"*",  "cluster_type":"group_type",  "user":  {  "id":1,  "name":"Administrator",  "username":"root",  "state":"active",  "avatar_url":"https://www.gravatar.com/avatar/4249f4df72b..",  "web_url":"https://gitlab.example.com/root"  },  "platform_kubernetes":  {  "api_url":"https://104.197.68.152",  "authorization_type":"rbac",  "ca_cert":"-----BEGIN CERTIFICATE-----\r\nhFiK1L61owwDQYJKoZIhvcNAQELBQAw\r\nLzEtMCsGA1UEAxMkZDA1YzQ1YjctNzdiMS00NDY0LThjNmEtMTQ0ZDJkZjM4ZDBj\r\nMB4XDTE4MTIyNzIwMDM1MVoXDTIzMTIyNjIxMDM1MVowLzEtMCsGA1UEAxMkZDA1\r\nYzQ1YjctNzdiMS00NDY0LThjNmEtMTQ0ZDJkZjM.......-----END CERTIFICATE-----"  },  "management_project":  {  "id":2,  "description":null,  "name":"project2",  "name_with_namespace":"John Doe8 / project2",  "path":"project2",  "path_with_namespace":"namespace2/project2",  "created_at":"2019-10-11T02:55:54.138Z"  }  },  {  "id":19,  "name":"cluster-2",  ...  }  ] 
```

## Get a single group cluster[](#get-a-single-group-cluster "Permalink")

获取单个组集群.

```
GET /groups/:id/clusters/:cluster_id 
```

Parameters:

| Attribute | Type | Required | Description |
| --- | --- | --- | --- |
| `id` | integer/string | yes | 组的 ID 或[URL 编码的路径](README.html#namespaced-path-encoding) |
| `cluster_id` | integer | yes | 集群的 ID |

请求示例:

```
curl --header "Private-Token: <your_access_token>" "https://gitlab.example.com/api/v4/groups/26/clusters/18" 
```

响应示例:

```
{  "id":18,  "name":"cluster-1",  "domain":"example.com",  "created_at":"2019-01-02T20:18:12.563Z",  "provider_type":"user",  "platform_type":"kubernetes",  "environment_scope":"*",  "cluster_type":"group_type",  "user":  {  "id":1,  "name":"Administrator",  "username":"root",  "state":"active",  "avatar_url":"https://www.gravatar.com/avatar/4249f4df72b..",  "web_url":"https://gitlab.example.com/root"  },  "platform_kubernetes":  {  "api_url":"https://104.197.68.152",  "authorization_type":"rbac",  "ca_cert":"-----BEGIN CERTIFICATE-----\r\nhFiK1L61owwDQYJKoZIhvcNAQELBQAw\r\nLzEtMCsGA1UEAxMkZDA1YzQ1YjctNzdiMS00NDY0LThjNmEtMTQ0ZDJkZjM4ZDBj\r\nMB4XDTE4MTIyNzIwMDM1MVoXDTIzMTIyNjIxMDM1MVowLzEtMCsGA1UEAxMkZDA1\r\nYzQ1YjctNzdiMS00NDY0LThjNmEtMTQ0ZDJkZjM.......-----END CERTIFICATE-----"  },  "management_project":  {  "id":2,  "description":null,  "name":"project2",  "name_with_namespace":"John Doe8 / project2",  "path":"project2",  "path_with_namespace":"namespace2/project2",  "created_at":"2019-10-11T02:55:54.138Z"  },  "group":  {  "id":26,  "name":"group-with-clusters-api",  "web_url":"https://gitlab.example.com/group-with-clusters-api"  }  } 
```

## Add existing cluster to group[](#add-existing-cluster-to-group "Permalink")

将现有的 Kubernetes 集群添加到组中.

```
POST /groups/:id/clusters/user 
```

Parameters:

| Attribute | Type | Required | Description |
| --- | --- | --- | --- |
| `id` | integer/string | yes | 组的 ID 或[URL 编码的路径](README.html#namespaced-path-encoding) |
| `name` | string | yes | 集群名称 |
| `domain` | string | no | 集群的[基础域](../user/group/clusters/index.html#base-domain) |
| `management_project_id` | integer | no | 集群[管理项目](../user/clusters/management_project.html)的 ID |
| `enabled` | boolean | no | 确定集群是否处于活动状态,默认为 true |
| `managed` | boolean | no | 确定 GitLab 是否将管理该集群的名称空间和服务帐户,默认为 true |
| `platform_kubernetes_attributes[api_url]` | string | yes | 访问 Kubernetes API 的 URL |
| `platform_kubernetes_attributes[token]` | string | yes | 针对 Kubernetes 进行身份验证的令牌 |
| `platform_kubernetes_attributes[ca_cert]` | string | no | TLS 证书. 如果 API 使用自签名 TLS 证书,则为必填. |
| `platform_kubernetes_attributes[authorization_type]` | string | no | 集群授权类型: `rbac``abac``unknown_authorization` . 默认为`rbac` . |
| `environment_scope` | string | no | 集群的关联环境. 默认为`*` |

请求示例:

```
curl --header "Private-Token: <your_access_token>" "https://gitlab.example.com/api/v4/groups/26/clusters/user" \
-H "Accept: application/json" \
-H "Content-Type:application/json" \
--request POST --data '{"name":"cluster-5", "platform_kubernetes_attributes":{"api_url":"https://35.111.51.20","token":"12345","ca_cert":"-----BEGIN CERTIFICATE-----\r\nhFiK1L61owwDQYJKoZIhvcNAQELBQAw\r\nLzEtMCsGA1UEAxMkZDA1YzQ1YjctNzdiMS00NDY0LThjNmEtMTQ0ZDJkZjM4ZDBj\r\nMB4XDTE4MTIyNzIwMDM1MVoXDTIzMTIyNjIxMDM1MVowLzEtMCsGA1UEAxMkZDA1\r\nYzQ1YjctNzdiMS00NDY0LThjNmEtMTQ0ZDJkZjM.......-----END CERTIFICATE-----"}}' 
```

响应示例:

```
{  "id":24,  "name":"cluster-5",  "created_at":"2019-01-03T21:53:40.610Z",  "provider_type":"user",  "platform_type":"kubernetes",  "environment_scope":"*",  "cluster_type":"group_type",  "user":  {  "id":1,  "name":"Administrator",  "username":"root",  "state":"active",  "avatar_url":"https://www.gravatar.com/avatar/4249f4df72b..",  "web_url":"https://gitlab.example.com/root"  },  "platform_kubernetes":  {  "api_url":"https://35.111.51.20",  "authorization_type":"rbac",  "ca_cert":"-----BEGIN CERTIFICATE-----\r\nhFiK1L61owwDQYJKoZIhvcNAQELBQAw\r\nLzEtMCsGA1UEAxMkZDA1YzQ1YjctNzdiMS00NDY0LThjNmEtMTQ0ZDJkZjM4ZDBj\r\nMB4XDTE4MTIyNzIwMDM1MVoXDTIzMTIyNjIxMDM1MVowLzEtMCsGA1UEAxMkZDA1\r\nYzQ1YjctNzdiMS00NDY0LThjNmEtMTQ0ZDJkZjM.......-----END CERTIFICATE-----"  },  "management_project":null,  "group":  {  "id":26,  "name":"group-with-clusters-api",  "web_url":"https://gitlab.example.com/root/group-with-clusters-api"  }  } 
```

## Edit group cluster[](#edit-group-cluster "Permalink")

更新现有的组群集.

```
PUT /groups/:id/clusters/:cluster_id 
```

Parameters:

| Attribute | Type | Required | Description |
| --- | --- | --- | --- |
| `id` | integer/string | yes | 组的 ID 或[URL 编码的路径](README.html#namespaced-path-encoding) |
| `cluster_id` | integer | yes | 集群的 ID |
| `name` | string | no | 集群名称 |
| `domain` | string | no | 集群的[基础域](../user/group/clusters/index.html#base-domain) |
| `management_project_id` | integer | no | 集群[管理项目](../user/clusters/management_project.html)的 ID |
| `platform_kubernetes_attributes[api_url]` | string | no | 访问 Kubernetes API 的 URL |
| `platform_kubernetes_attributes[token]` | string | no | 针对 Kubernetes 进行身份验证的令牌 |
| `platform_kubernetes_attributes[ca_cert]` | string | no | TLS 证书. 如果 API 使用自签名 TLS 证书,则为必填. |
| `environment_scope` | string | no | 集群的关联环境 |

**注意:**仅通过["添加现有 Kubernetes 群集"](../user/project/clusters/add_remove_clusters.html#add-existing-cluster)选项或通过["将现有群集添加到组"](#add-existing-cluster-to-group)端点[添加群集时,](#add-existing-cluster-to-group)才能更新`name``api_url``ca_cert``token` .

请求示例:

```
curl --header "Private-Token: <your_access_token>" "https://gitlab.example.com/api/v4/groups/26/clusters/24" \
-H "Content-Type:application/json" \
--request PUT --data '{"name":"new-cluster-name","domain":"new-domain.com","api_url":"https://new-api-url.com"}' 
```

响应示例:

```
{  "id":24,  "name":"new-cluster-name",  "domain":"new-domain.com",  "created_at":"2019-01-03T21:53:40.610Z",  "provider_type":"user",  "platform_type":"kubernetes",  "environment_scope":"*",  "cluster_type":"group_type",  "user":  {  "id":1,  "name":"Administrator",  "username":"root",  "state":"active",  "avatar_url":"https://www.gravatar.com/avatar/4249f4df72b..",  "web_url":"https://gitlab.example.com/root"  },  "platform_kubernetes":  {  "api_url":"https://new-api-url.com",  "authorization_type":"rbac",  "ca_cert":null  },  "management_project":  {  "id":2,  "description":null,  "name":"project2",  "name_with_namespace":"John Doe8 / project2",  "path":"project2",  "path_with_namespace":"namespace2/project2",  "created_at":"2019-10-11T02:55:54.138Z"  },  "group":  {  "id":26,  "name":"group-with-clusters-api",  "web_url":"https://gitlab.example.com/group-with-clusters-api"  }  } 
```

## Delete group cluster[](#delete-group-cluster "Permalink")

删除现有的组群集.

```
DELETE /groups/:id/clusters/:cluster_id 
```

Parameters:

| Attribute | Type | Required | Description |
| --- | --- | --- | --- |
| `id` | integer/string | yes | 组的 ID 或[URL 编码的路径](README.html#namespaced-path-encoding) |
| `cluster_id` | integer | yes | 集群的 ID |

请求示例:

```
curl --request DELETE --header "Private-Token: <your_access_token>" "https://gitlab.example.com/api/v4/groups/26/clusters/23" 
```