2020-07-28 23:09:34 +05:30
---
stage: Configure
group: Configure
2021-02-22 17:27:13 +05:30
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-28 23:09:34 +05:30
---
2021-12-11 22:18:48 +05:30
# Project clusters API (certificate-based) (DEPRECATED) **(FREE)**
2019-02-15 15:39:39 +05:30
2021-12-11 22:18:48 +05:30
> - [Introduced](https://gitlab.com/gitlab-org/gitlab-foss/-/merge_requests/23922) in GitLab 11.7.
> - [Deprecated](https://gitlab.com/groups/gitlab-org/configure/-/epics/8) in GitLab 14.5.
WARNING:
This feature was [deprecated ](https://gitlab.com/groups/gitlab-org/configure/-/epics/8 ) in GitLab 14.5.
2019-02-15 15:39:39 +05:30
2022-04-04 11:22:00 +05:30
Users need at least the Maintainer role to use these endpoints.
2019-02-15 15:39:39 +05:30
## List project clusters
Returns a list of project clusters.
2020-04-08 14:13:33 +05:30
```plaintext
2019-02-15 15:39:39 +05:30
GET /projects/:id/clusters
```
Parameters:
2021-02-22 17:27:13 +05:30
| Attribute | Type | Required | Description |
| --------- | ------- | -------- | ----------------------------------------------------- |
2021-09-30 23:02:18 +05:30
| `id` | integer or string | yes | The ID or [URL-encoded path of the project ](index.md#namespaced-path-encoding ) owned by the authenticated user |
2019-02-15 15:39:39 +05:30
Example request:
2020-03-13 15:44:24 +05:30
```shell
2020-07-28 23:09:34 +05:30
curl --header "Private-Token: < your_access_token > " "https://gitlab.example.com/api/v4/projects/26/clusters"
2019-02-15 15:39:39 +05:30
```
Example response:
```json
[
{
"id":18,
"name":"cluster-1",
2019-07-07 11:18:12 +05:30
"domain":"example.com",
2019-02-15 15:39:39 +05:30
"created_at":"2019-01-02T20:18:12.563Z",
2021-02-22 17:27:13 +05:30
"managed": true,
"enabled": true,
2019-02-15 15:39:39 +05:30
"provider_type":"user",
"platform_type":"kubernetes",
"environment_scope":"*",
"cluster_type":"project_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",
"namespace":"cluster-1-namespace",
"authorization_type":"rbac",
"ca_cert":"-----BEGIN CERTIFICATE-----\r\nhFiK1L61owwDQYJKoZIhvcNAQELBQAw\r\nLzEtMCsGA1UEAxMkZDA1YzQ1YjctNzdiMS00NDY0LThjNmEtMTQ0ZDJkZjM4ZDBj\r\nMB4XDTE4MTIyNzIwMDM1MVoXDTIzMTIyNjIxMDM1MVowLzEtMCsGA1UEAxMkZDA1\r\nYzQ1YjctNzdiMS00NDY0LThjNmEtMTQ0ZDJkZjM.......-----END CERTIFICATE-----"
2019-12-26 22:10:19 +05:30
},
"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-02-15 15:39:39 +05:30
}
},
{
"id":19,
"name":"cluster-2",
...
}
]
```
## Get a single project cluster
Gets a single project cluster.
2020-03-13 15:44:24 +05:30
```shell
2019-02-15 15:39:39 +05:30
GET /projects/:id/clusters/:cluster_id
```
Parameters:
2021-02-22 17:27:13 +05:30
| Attribute | Type | Required | Description |
| ------------ | ------- | -------- | ----------------------------------------------------- |
2021-09-30 23:02:18 +05:30
| `id` | integer or string | yes | The ID or [URL-encoded path of the project ](index.md#namespaced-path-encoding ) owned by the authenticated user |
2021-02-22 17:27:13 +05:30
| `cluster_id` | integer | yes | The ID of the cluster |
2019-02-15 15:39:39 +05:30
Example request:
2020-03-13 15:44:24 +05:30
```shell
2020-06-23 00:09:42 +05:30
curl --header "Private-Token: < your_access_token > " "https://gitlab.example.com/api/v4/projects/26/clusters/18"
2019-02-15 15:39:39 +05:30
```
Example response:
```json
{
"id":18,
"name":"cluster-1",
2019-07-07 11:18:12 +05:30
"domain":"example.com",
2019-02-15 15:39:39 +05:30
"created_at":"2019-01-02T20:18:12.563Z",
2021-02-22 17:27:13 +05:30
"managed": true,
"enabled": true,
2019-02-15 15:39:39 +05:30
"provider_type":"user",
"platform_type":"kubernetes",
"environment_scope":"*",
"cluster_type":"project_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",
"namespace":"cluster-1-namespace",
"authorization_type":"rbac",
"ca_cert":"-----BEGIN CERTIFICATE-----\r\nhFiK1L61owwDQYJKoZIhvcNAQELBQAw\r\nLzEtMCsGA1UEAxMkZDA1YzQ1YjctNzdiMS00NDY0LThjNmEtMTQ0ZDJkZjM4ZDBj\r\nMB4XDTE4MTIyNzIwMDM1MVoXDTIzMTIyNjIxMDM1MVowLzEtMCsGA1UEAxMkZDA1\r\nYzQ1YjctNzdiMS00NDY0LThjNmEtMTQ0ZDJkZjM.......-----END CERTIFICATE-----"
},
2019-12-26 22:10:19 +05:30
"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-02-15 15:39:39 +05:30
"project":
{
"id":26,
"description":"",
"name":"project-with-clusters-api",
"name_with_namespace":"Administrator / project-with-clusters-api",
"path":"project-with-clusters-api",
"path_with_namespace":"root/project-with-clusters-api",
"created_at":"2019-01-02T20:13:32.600Z",
"default_branch":null,
2021-09-04 01:27:46 +05:30
"tag_list":[], //deprecated, use `topics` instead
"topics":[],
2019-02-15 15:39:39 +05:30
"ssh_url_to_repo":"ssh://gitlab.example.com/root/project-with-clusters-api.git",
"http_url_to_repo":"https://gitlab.example.com/root/project-with-clusters-api.git",
"web_url":"https://gitlab.example.com/root/project-with-clusters-api",
"readme_url":null,
"avatar_url":null,
"star_count":0,
"forks_count":0,
"last_activity_at":"2019-01-02T20:13:32.600Z",
"namespace":
{
"id":1,
"name":"root",
"path":"root",
"kind":"user",
"full_path":"root",
"parent_id":null
}
}
}
```
## Add existing cluster to project
Adds an existing Kubernetes cluster to the project.
2020-03-13 15:44:24 +05:30
```shell
2019-02-15 15:39:39 +05:30
POST /projects/:id/clusters/user
```
Parameters:
2021-02-22 17:27:13 +05:30
| Attribute | Type | Required | Description |
| ---------------------------------------------------- | ------- | -------- | ----------------------------------------------------------------------------------------------------- |
2021-09-30 23:02:18 +05:30
| `id` | integer or string | yes | The ID or [URL-encoded path of the project ](index.md#namespaced-path-encoding ) owned by the authenticated user |
2021-02-22 17:27:13 +05:30
| `name` | string | yes | The name of the cluster |
2021-09-30 23:02:18 +05:30
| `domain` | string | no | The [base domain ](../user/project/clusters/gitlab_managed_clusters.md#base-domain ) of the cluster |
2021-02-22 17:27:13 +05:30
| `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, defaults to `true` |
| `managed` | boolean | no | Determines if GitLab manages namespaces and service accounts for this cluster. Defaults to `true` |
| `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[namespace]` | string | no | The unique namespace related to the project |
| `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-02-15 15:39:39 +05:30
Example request:
2020-03-13 15:44:24 +05:30
```shell
2020-07-28 23:09:34 +05:30
curl --header "Private-Token: < your_access_token > " "https://gitlab.example.com/api/v4/projects/26/clusters/user" \
2019-02-15 15:39:39 +05:30
-H "Accept: application/json" \
-H "Content-Type:application/json" \
-X POST --data '{"name":"cluster-5", "platform_kubernetes_attributes":{"api_url":"https://35.111.51.20","token":"12345","namespace":"cluster-5-namespace","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",
2021-02-22 17:27:13 +05:30
"managed": true,
"enabled": true,
2019-02-15 15:39:39 +05:30
"provider_type":"user",
"platform_type":"kubernetes",
"environment_scope":"*",
"cluster_type":"project_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",
"namespace":"cluster-5-namespace",
"authorization_type":"rbac",
"ca_cert":"-----BEGIN CERTIFICATE-----\r\nhFiK1L61owwDQYJKoZIhvcNAQELBQAw\r\nLzEtMCsGA1UEAxMkZDA1YzQ1YjctNzdiMS00NDY0LThjNmEtMTQ0ZDJkZjM4ZDBj\r\nMB4XDTE4MTIyNzIwMDM1MVoXDTIzMTIyNjIxMDM1MVowLzEtMCsGA1UEAxMkZDA1\r\nYzQ1YjctNzdiMS00NDY0LThjNmEtMTQ0ZDJkZjM.......-----END CERTIFICATE-----"
},
2019-12-26 22:10:19 +05:30
"management_project":null,
2019-02-15 15:39:39 +05:30
"project":
{
"id":26,
"description":"",
"name":"project-with-clusters-api",
"name_with_namespace":"Administrator / project-with-clusters-api",
"path":"project-with-clusters-api",
"path_with_namespace":"root/project-with-clusters-api",
"created_at":"2019-01-02T20:13:32.600Z",
"default_branch":null,
2021-09-04 01:27:46 +05:30
"tag_list":[], //deprecated, use `topics` instead
"topics":[],
2019-02-15 15:39:39 +05:30
"ssh_url_to_repo":"ssh:://gitlab.example.com/root/project-with-clusters-api.git",
"http_url_to_repo":"https://gitlab.example.com/root/project-with-clusters-api.git",
"web_url":"https://gitlab.example.com/root/project-with-clusters-api",
"readme_url":null,
"avatar_url":null,
"star_count":0,
"forks_count":0,
"last_activity_at":"2019-01-02T20:13:32.600Z",
"namespace":
{
"id":1,
"name":"root",
"path":"root",
"kind":"user",
"full_path":"root",
"parent_id":null
}
}
}
```
## Edit project cluster
Updates an existing project cluster.
2020-03-13 15:44:24 +05:30
```shell
2019-02-15 15:39:39 +05:30
PUT /projects/:id/clusters/:cluster_id
```
Parameters:
2021-02-22 17:27:13 +05:30
| Attribute | Type | Required | Description |
| ------------------------------------------- | ------- | -------- | ------------------------------------------------------------------------------------------ |
2021-09-30 23:02:18 +05:30
| `id` | integer or string | yes | The ID or [URL-encoded path of the project ](index.md#namespaced-path-encoding ) owned by the authenticated user |
2021-02-22 17:27:13 +05:30
| `cluster_id` | integer | yes | The ID of the cluster |
| `name` | string | no | The name of the cluster |
2021-09-30 23:02:18 +05:30
| `domain` | string | no | The [base domain ](../user/project/clusters/gitlab_managed_clusters.md#base-domain ) of the cluster |
2021-02-22 17:27:13 +05:30
| `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 |
| `managed` | boolean | no | Determines if GitLab manages namespaces and service accounts for this cluster |
| `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. |
| `platform_kubernetes_attributes[namespace]` | string | no | The unique namespace related to the project |
2021-11-11 11:23:49 +05:30
| `environment_scope` | string | no | The associated environment to the cluster |
2021-02-22 17:27:13 +05:30
NOTE:
2019-02-15 15:39:39 +05:30
`name` , `api_url` , `ca_cert` and `token` can only be updated if the cluster was added
2019-12-26 22:10:19 +05:30
through the ["Add existing Kubernetes cluster" ](../user/project/clusters/add_remove_clusters.md#add-existing-cluster ) option or
2019-02-15 15:39:39 +05:30
through the ["Add existing cluster to project" ](#add-existing-cluster-to-project ) endpoint.
Example request:
2020-03-13 15:44:24 +05:30
```shell
2020-07-28 23:09:34 +05:30
curl --header "Private-Token: < your_access_token > " "https://gitlab.example.com/api/v4/projects/26/clusters/24" \
2019-02-15 15:39:39 +05:30
-H "Content-Type:application/json" \
2019-07-07 11:18:12 +05:30
-X PUT --data '{"name":"new-cluster-name","domain":"new-domain.com","api_url":"https://new-api-url.com"}'
2019-02-15 15:39:39 +05:30
```
Example response:
```json
{
"id":24,
"name":"new-cluster-name",
2019-07-07 11:18:12 +05:30
"domain":"new-domain.com",
2019-02-15 15:39:39 +05:30
"created_at":"2019-01-03T21:53:40.610Z",
2021-02-22 17:27:13 +05:30
"managed": true,
"enabled": true,
2019-02-15 15:39:39 +05:30
"provider_type":"user",
"platform_type":"kubernetes",
"environment_scope":"*",
"cluster_type":"project_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",
"namespace":"cluster-5-namespace",
"authorization_type":"rbac",
"ca_cert":null
},
2019-12-26 22:10:19 +05:30
"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-02-15 15:39:39 +05:30
"project":
{
"id":26,
"description":"",
"name":"project-with-clusters-api",
"name_with_namespace":"Administrator / project-with-clusters-api",
"path":"project-with-clusters-api",
"path_with_namespace":"root/project-with-clusters-api",
"created_at":"2019-01-02T20:13:32.600Z",
"default_branch":null,
2021-09-04 01:27:46 +05:30
"tag_list":[], //deprecated, use `topics` instead
"topics":[],
2019-02-15 15:39:39 +05:30
"ssh_url_to_repo":"ssh:://gitlab.example.com/root/project-with-clusters-api.git",
"http_url_to_repo":"https://gitlab.example.com/root/project-with-clusters-api.git",
"web_url":"https://gitlab.example.com/root/project-with-clusters-api",
"readme_url":null,
"avatar_url":null,
"star_count":0,
"forks_count":0,
"last_activity_at":"2019-01-02T20:13:32.600Z",
"namespace":
{
"id":1,
"name":"root",
"path":"root",
"kind":"user",
"full_path":"root",
"parent_id":null
}
}
}
```
## Delete project cluster
2022-06-21 17:19:12 +05:30
Deletes an existing project cluster. Does not remove existing resources within the connected Kubernetes cluster.
2019-02-15 15:39:39 +05:30
2020-04-08 14:13:33 +05:30
```plaintext
2019-02-15 15:39:39 +05:30
DELETE /projects/:id/clusters/:cluster_id
```
Parameters:
2021-02-22 17:27:13 +05:30
| Attribute | Type | Required | Description |
| ------------ | ------- | -------- | ----------------------------------------------------- |
2021-09-30 23:02:18 +05:30
| `id` | integer or string | yes | The ID or [URL-encoded path of the project ](index.md#namespaced-path-encoding ) owned by the authenticated user |
2021-02-22 17:27:13 +05:30
| `cluster_id` | integer | yes | The ID of the cluster |
2019-02-15 15:39:39 +05:30
Example request:
2020-03-13 15:44:24 +05:30
```shell
2020-07-28 23:09:34 +05:30
curl --request DELETE --header "Private-Token: < your_access_token > " "https://gitlab.example.com/api/v4/projects/26/clusters/23"
2019-02-15 15:39:39 +05:30
```