2020-07-13 17:09:24 -04:00
---
stage: Configure
group: Configure
2020-11-26 01:09:20 -05:00
info: To determine the technical writer assigned to the Stage/Group associated with this page, see https://about.gitlab.com/handbook/engineering/ux/technical-writing/#assignments
2020-07-13 17:09:24 -04:00
---
2021-02-08 13:09:49 -05:00
# Group clusters API **(FREE)**
2019-07-01 02:49:00 -04:00
2020-03-23 23:09:28 -04:00
> [Introduced](https://gitlab.com/gitlab-org/gitlab-foss/-/merge_requests/30213) in GitLab 12.1.
2019-07-01 02:49:00 -04:00
2021-05-03 02:10:30 -04:00
Similarly to [project-level ](../user/project/clusters/index.md ) and
2020-11-26 04:09:53 -05:00
[instance-level ](../user/instance/clusters/index.md ) Kubernetes clusters,
group-level Kubernetes clusters allow you to connect a Kubernetes cluster to
your group, enabling you to use the same cluster across multiple projects.
2021-05-31 14:09:56 -04:00
Users need at least the [Maintainer role ](../user/permissions.md ) for the group to use these endpoints.
2019-07-01 02:49:00 -04:00
## List group clusters
Returns a list of group clusters.
2020-02-27 04:09:01 -05:00
```plaintext
2019-07-01 02:49:00 -04:00
GET /groups/:id/clusters
```
Parameters:
2020-11-18 07:09:16 -05:00
| Attribute | Type | Required | Description |
| --------- | -------------- | -------- | ----------------------------------------------------------------------------- |
2021-06-28 11:08:03 -04:00
| `id` | integer/string | yes | The ID or [URL-encoded path of the group ](index.md#namespaced-path-encoding ) |
2019-07-01 02:49:00 -04:00
Example request:
2020-01-30 10:09:15 -05:00
```shell
2020-07-09 23:08:53 -04:00
curl --header "Private-Token: < your_access_token > " "https://gitlab.example.com/api/v4/groups/26/clusters"
2019-07-01 02:49:00 -04:00
```
Example response:
```json
[
{
"id":18,
"name":"cluster-1",
"domain":"example.com",
"created_at":"2019-01-02T20:18:12.563Z",
2020-11-18 07:09:16 -05:00
"managed": true,
"enabled": true,
2019-07-01 02:49:00 -04:00
"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-----"
2019-10-24 08:06:03 -04:00
},
"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"
2019-07-01 02:49:00 -04:00
}
},
{
"id":19,
"name":"cluster-2",
...
}
]
```
## Get a single group cluster
Gets a single group cluster.
2020-02-27 04:09:01 -05:00
```plaintext
2019-07-01 02:49:00 -04:00
GET /groups/:id/clusters/:cluster_id
```
Parameters:
2020-11-18 07:09:16 -05:00
| Attribute | Type | Required | Description |
| ------------ | -------------- | -------- | ----------------------------------------------------------------------------- |
2021-06-28 11:08:03 -04:00
| `id` | integer/string | yes | The ID or [URL-encoded path of the group ](index.md#namespaced-path-encoding ) |
2020-11-18 07:09:16 -05:00
| `cluster_id` | integer | yes | The ID of the cluster |
2019-07-01 02:49:00 -04:00
Example request:
2020-01-30 10:09:15 -05:00
```shell
2020-05-27 20:08:37 -04:00
curl --header "Private-Token: < your_access_token > " "https://gitlab.example.com/api/v4/groups/26/clusters/18"
2019-07-01 02:49:00 -04:00
```
Example response:
```json
{
"id":18,
"name":"cluster-1",
"domain":"example.com",
"created_at":"2019-01-02T20:18:12.563Z",
2020-11-18 07:09:16 -05:00
"managed": true,
"enabled": true,
2019-07-01 02:49:00 -04:00
"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-----"
},
2019-10-24 08:06:03 -04:00
"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"
},
2019-07-01 02:49:00 -04:00
"group":
{
"id":26,
"name":"group-with-clusters-api",
"web_url":"https://gitlab.example.com/group-with-clusters-api"
}
}
```
## Add existing cluster to group
Adds an existing Kubernetes cluster to the group.
2020-02-27 04:09:01 -05:00
```plaintext
2019-07-01 02:49:00 -04:00
POST /groups/:id/clusters/user
```
Parameters:
2020-11-18 07:09:16 -05:00
| Attribute | Type | Required | Description |
| ---------------------------------------------------- | -------------- | -------- | --------------------------------------------------------------------------------------------------- |
2021-06-28 11:08:03 -04:00
| `id` | integer/string | yes | The ID or [URL-encoded path of the group ](index.md#namespaced-path-encoding ) |
2020-11-18 07:09:16 -05:00
| `name` | string | yes | The name of the cluster |
| `domain` | string | no | The [base domain ](../user/group/clusters/index.md#base-domain ) of the cluster |
| `management_project_id` | integer | no | The ID of the [management project ](../user/clusters/management_project.md ) for the cluster |
2020-11-18 19:09:41 -05:00
| `enabled` | boolean | no | Determines if cluster is active or not, defaults to `true` |
| `managed` | boolean | no | Determines if GitLab manages namespaces and service accounts for this cluster. Defaults to `true` |
2020-11-18 07:09:16 -05:00
| `platform_kubernetes_attributes[api_url]` | string | yes | The URL to access the Kubernetes API |
| `platform_kubernetes_attributes[token]` | string | yes | The token to authenticate against Kubernetes |
| `platform_kubernetes_attributes[ca_cert]` | string | no | TLS certificate. Required if API is using a self-signed TLS certificate. |
| `platform_kubernetes_attributes[authorization_type]` | string | no | The cluster authorization type: `rbac` , `abac` or `unknown_authorization` . Defaults to `rbac` . |
| `environment_scope` | string | no | The associated environment to the cluster. Defaults to `*` ** (PREMIUM)** |
2019-07-01 02:49:00 -04:00
Example request:
2020-01-30 10:09:15 -05:00
```shell
2020-05-27 20:08:37 -04:00
curl --header "Private-Token: < your_access_token > " "https://gitlab.example.com/api/v4/groups/26/clusters/user" \
2019-07-01 02:49:00 -04:00
-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-----"}}'
```
Example response:
```json
{
"id":24,
"name":"cluster-5",
"created_at":"2019-01-03T21:53:40.610Z",
2020-11-18 07:09:16 -05:00
"managed": true,
"enabled": true,
2019-07-01 02:49:00 -04:00
"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-----"
},
2019-10-24 08:06:03 -04:00
"management_project":null,
2019-07-01 02:49:00 -04:00
"group":
{
"id":26,
"name":"group-with-clusters-api",
"web_url":"https://gitlab.example.com/root/group-with-clusters-api"
}
}
```
## Edit group cluster
Updates an existing group cluster.
2020-02-27 04:09:01 -05:00
```plaintext
2019-07-01 02:49:00 -04:00
PUT /groups/:id/clusters/:cluster_id
```
Parameters:
2020-11-18 07:09:16 -05:00
| Attribute | Type | Required | Description |
| ----------------------------------------- | -------------- | -------- | ------------------------------------------------------------------------------------------ |
2021-06-28 11:08:03 -04:00
| `id` | integer/string | yes | The ID or [URL-encoded path of the group ](index.md#namespaced-path-encoding ) |
2020-11-18 07:09:16 -05:00
| `cluster_id` | integer | yes | The ID of the cluster |
| `name` | string | no | The name of the cluster |
| `domain` | string | no | The [base domain ](../user/group/clusters/index.md#base-domain ) of the cluster |
| `management_project_id` | integer | no | The ID of the [management project ](../user/clusters/management_project.md ) for the cluster |
| `enabled` | boolean | no | Determines if cluster is active or not |
2020-11-18 19:09:41 -05:00
| `managed` | boolean | no | Determines if GitLab manages namespaces and service accounts for this cluster |
2020-11-18 07:09:16 -05:00
| `platform_kubernetes_attributes[api_url]` | string | no | The URL to access the Kubernetes API |
| `platform_kubernetes_attributes[token]` | string | no | The token to authenticate against Kubernetes |
| `platform_kubernetes_attributes[ca_cert]` | string | no | TLS certificate. Required if API is using a self-signed TLS certificate. |
| `environment_scope` | string | no | The associated environment to the cluster ** (PREMIUM)** |
2019-07-01 02:49:00 -04:00
2020-12-04 16:09:29 -05:00
NOTE:
2019-07-01 02:49:00 -04:00
`name` , `api_url` , `ca_cert` and `token` can only be updated if the cluster was added
2019-10-28 23:06:28 -04:00
through the ["Add existing Kubernetes cluster" ](../user/project/clusters/add_remove_clusters.md#add-existing-cluster ) option or
2019-07-01 02:49:00 -04:00
through the ["Add existing cluster to group" ](#add-existing-cluster-to-group ) endpoint.
Example request:
2020-01-30 10:09:15 -05:00
```shell
2020-07-09 23:08:53 -04:00
curl --header "Private-Token: < your_access_token > " "https://gitlab.example.com/api/v4/groups/26/clusters/24" \
2019-07-01 02:49:00 -04:00
-H "Content-Type:application/json" \
2021-06-18 11:10:16 -04:00
--request PUT --data '{"name":"new-cluster-name","domain":"new-domain.com","platform_kubernetes_attributes":{"api_url":"https://10.10.101.1:6433"}}'
2019-07-01 02:49:00 -04:00
```
Example response:
```json
{
"id":24,
"name":"new-cluster-name",
"domain":"new-domain.com",
"created_at":"2019-01-03T21:53:40.610Z",
2020-11-18 07:09:16 -05:00
"managed": true,
"enabled": true,
2019-07-01 02:49:00 -04:00
"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
},
2019-10-24 08:06:03 -04:00
"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"
},
2019-07-01 02:49:00 -04:00
"group":
{
"id":26,
"name":"group-with-clusters-api",
"web_url":"https://gitlab.example.com/group-with-clusters-api"
}
}
```
## Delete group cluster
Deletes an existing group cluster.
2020-02-27 04:09:01 -05:00
```plaintext
2019-07-01 02:49:00 -04:00
DELETE /groups/:id/clusters/:cluster_id
```
Parameters:
2020-11-18 07:09:16 -05:00
| Attribute | Type | Required | Description |
| ------------ | -------------- | -------- | ----------------------------------------------------------------------------- |
2021-06-28 11:08:03 -04:00
| `id` | integer/string | yes | The ID or [URL-encoded path of the group ](index.md#namespaced-path-encoding ) |
2020-11-18 07:09:16 -05:00
| `cluster_id` | integer | yes | The ID of the cluster |
2019-07-01 02:49:00 -04:00
Example request:
2020-01-30 10:09:15 -05:00
```shell
2020-05-27 20:08:37 -04:00
curl --request DELETE --header "Private-Token: < your_access_token > " "https://gitlab.example.com/api/v4/groups/26/clusters/23"
2019-07-01 02:49:00 -04:00
```