project_clusters.md 12,3 КБ
Newer Older
Mayra Cabrera's avatar
Mayra Cabrera включено в состав коммита
1
2
# Project clusters API

GitLab Bot's avatar
GitLab Bot включено в состав коммита
3
> [Introduced](https://gitlab.com/gitlab-org/gitlab-foss/-/merge_requests/23922) in GitLab 11.7.
Mayra Cabrera's avatar
Mayra Cabrera включено в состав коммита
4
5
6
7
8
9
10
11

NOTE: **Note:**
User will need at least maintainer access to use these endpoints.

## List project clusters

Returns a list of project clusters.

GitLab Bot's avatar
GitLab Bot включено в состав коммита
12
```plaintext
Mayra Cabrera's avatar
Mayra Cabrera включено в состав коммита
13
14
15
16
17
18
19
20
21
22
23
GET /projects/:id/clusters
```

Parameters:

| Attribute | Type | Required | Description |
| --------- | ---- | -------- | ----------- |
| `id` | integer | yes | The ID of the project owned by the authenticated user |

Example request:

GitLab Bot's avatar
GitLab Bot включено в состав коммита
24
```shell
Mayra Cabrera's avatar
Mayra Cabrera включено в состав коммита
25
26
27
28
29
30
31
32
33
34
curl --header 'Private-Token: <your_access_token>' https://gitlab.example.com/api/v4/projects/26/clusters
```

Example response:

```json
[
  {
    "id":18,
    "name":"cluster-1",
Mayra Cabrera's avatar
Mayra Cabrera включено в состав коммита
35
    "domain":"example.com",
Mayra Cabrera's avatar
Mayra Cabrera включено в состав коммита
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
    "created_at":"2019-01-02T20:18:12.563Z",
    "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-----"
GitLab Bot's avatar
GitLab Bot включено в состав коммита
56
57
58
59
60
61
62
63
64
65
    },
    "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"
Mayra Cabrera's avatar
Mayra Cabrera включено в состав коммита
66
67
68
69
70
71
72
73
74
75
76
77
78
79
    }
  },
  {
    "id":19,
    "name":"cluster-2",
    ...
  }
]
```

## Get a single project cluster

Gets a single project cluster.

GitLab Bot's avatar
GitLab Bot включено в состав коммита
80
```shell
Mayra Cabrera's avatar
Mayra Cabrera включено в состав коммита
81
82
83
84
85
86
87
88
GET /projects/:id/clusters/:cluster_id
```

Parameters:

| Attribute | Type | Required | Description |
| --------- | ---- | -------- | ----------- |
| `id` | integer | yes | The ID of the project owned by the authenticated user |
Marcel Amirault's avatar
Marcel Amirault включено в состав коммита
89
| `cluster_id` | integer | yes | The ID of the cluster |
Mayra Cabrera's avatar
Mayra Cabrera включено в состав коммита
90
91
92

Example request:

GitLab Bot's avatar
GitLab Bot включено в состав коммита
93
```shell
Mayra Cabrera's avatar
Mayra Cabrera включено в состав коммита
94
95
96
97
98
99
100
101
102
curl --header 'Private-Token: <your_access_token>' https://gitlab.example.com/api/v4/projects/26/clusters/18
```

Example response:

```json
{
  "id":18,
  "name":"cluster-1",
Mayra Cabrera's avatar
Mayra Cabrera включено в состав коммита
103
  "domain":"example.com",
Mayra Cabrera's avatar
Mayra Cabrera включено в состав коммита
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
  "created_at":"2019-01-02T20:18:12.563Z",
  "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-----"
  },
GitLab Bot's avatar
GitLab Bot включено в состав коммита
125
126
127
128
129
130
131
132
133
134
  "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"
  },
Mayra Cabrera's avatar
Mayra Cabrera включено в состав коммита
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
167
168
169
170
  "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,
    "tag_list":[],
    "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.

GitLab Bot's avatar
GitLab Bot включено в состав коммита
171
```shell
Mayra Cabrera's avatar
Mayra Cabrera включено в состав коммита
172
173
174
175
176
177
178
179
POST /projects/:id/clusters/user
```

Parameters:

| Attribute | Type | Required | Description |
| --------- | ---- | -------- | ----------- |
| `id` | integer | yes | The ID of the project owned by the authenticated user |
GitLab Bot's avatar
GitLab Bot включено в состав коммита
180
181
| `name` | string | yes | The name of the cluster |
| `domain` | string | no | The [base domain](../user/project/clusters/index.md#base-domain) of the cluster |
GitLab Bot's avatar
GitLab Bot включено в состав коммита
182
183
| `enabled` | boolean | no | Determines if cluster is active or not, defaults to true |
| `managed` | boolean | no | Determines if GitLab will manage namespaces and service accounts for this cluster, defaults to true |
GitLab Bot's avatar
GitLab Bot включено в состав коммита
184
185
186
187
188
189
| `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)** |
Mayra Cabrera's avatar
Mayra Cabrera включено в состав коммита
190
191
192

Example request:

GitLab Bot's avatar
GitLab Bot включено в состав коммита
193
```shell
Mayra Cabrera's avatar
Mayra Cabrera включено в состав коммита
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
curl --header 'Private-Token: <your_access_token>' https://gitlab.example.com/api/v4/projects/26/clusters/user \
-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",
  "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-----"
  },
GitLab Bot's avatar
GitLab Bot включено в состав коммита
227
  "management_project":null,
Mayra Cabrera's avatar
Mayra Cabrera включено в состав коммита
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
  "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,
    "tag_list":[],
    "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.

GitLab Bot's avatar
GitLab Bot включено в состав коммита
264
```shell
Mayra Cabrera's avatar
Mayra Cabrera включено в состав коммита
265
266
267
268
269
270
271
272
PUT /projects/:id/clusters/:cluster_id
```

Parameters:

| Attribute | Type | Required | Description |
| --------- | ---- | -------- | ----------- |
| `id` | integer | yes | The ID of the project owned by the authenticated user |
akkee's avatar
akkee включено в состав коммита
273
| `cluster_id` | integer | yes | The ID of the cluster |
GitLab Bot's avatar
GitLab Bot включено в состав коммита
274
275
| `name` | string | no | The name of the cluster |
| `domain` | string | no | The [base domain](../user/project/clusters/index.md#base-domain) of the cluster |
GitLab Bot's avatar
GitLab Bot включено в состав коммита
276
| `management_project_id` | integer | no | The ID of the [management project](../user/clusters/management_project.md) for the cluster |
GitLab Bot's avatar
GitLab Bot включено в состав коммита
277
278
279
280
281
| `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 |
| `environment_scope` | string | no | The associated environment to the cluster **(PREMIUM)** |
Mayra Cabrera's avatar
Mayra Cabrera включено в состав коммита
282
283
284

NOTE: **Note:**
`name`, `api_url`, `ca_cert` and `token` can only be updated if the cluster was added
GitLab Bot's avatar
GitLab Bot включено в состав коммита
285
through the ["Add existing Kubernetes cluster"](../user/project/clusters/add_remove_clusters.md#add-existing-cluster) option or
Mayra Cabrera's avatar
Mayra Cabrera включено в состав коммита
286
287
288
289
through the ["Add existing cluster to project"](#add-existing-cluster-to-project) endpoint.

Example request:

GitLab Bot's avatar
GitLab Bot включено в состав коммита
290
```shell
Mayra Cabrera's avatar
Mayra Cabrera включено в состав коммита
291
292
curl --header 'Private-Token: <your_access_token>' https://gitlab.example.com/api/v4/projects/26/clusters/24 \
-H "Content-Type:application/json" \
Mayra Cabrera's avatar
Mayra Cabrera включено в состав коммита
293
-X PUT --data '{"name":"new-cluster-name","domain":"new-domain.com","api_url":"https://new-api-url.com"}'
Mayra Cabrera's avatar
Mayra Cabrera включено в состав коммита
294
295
296
297
298
299
300
301
```

Example response:

```json
{
  "id":24,
  "name":"new-cluster-name",
Mayra Cabrera's avatar
Mayra Cabrera включено в состав коммита
302
  "domain":"new-domain.com",
Mayra Cabrera's avatar
Mayra Cabrera включено в состав коммита
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
  "created_at":"2019-01-03T21:53:40.610Z",
  "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
  },
GitLab Bot's avatar
GitLab Bot включено в состав коммита
324
325
326
327
328
329
330
331
332
333
  "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"
  },
Mayra Cabrera's avatar
Mayra Cabrera включено в состав коммита
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
  "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,
    "tag_list":[],
    "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

Deletes an existing project cluster.

GitLab Bot's avatar
GitLab Bot включено в состав коммита
371
```plaintext
Mayra Cabrera's avatar
Mayra Cabrera включено в состав коммита
372
373
374
375
376
377
378
379
380
381
382
383
DELETE /projects/:id/clusters/:cluster_id
```

Parameters:

| Attribute | Type | Required | Description |
| --------- | ---- | -------- | ----------- |
| `id` | integer | yes | The ID of the project owned by the authenticated user |
| `cluster_id` | integer | yes | The ID of the cluster |

Example request:

GitLab Bot's avatar
GitLab Bot включено в состав коммита
384
```shell
GitLab Bot's avatar
GitLab Bot включено в состав коммита
385
curl --request DELETE --header 'Private-Token: <your_access_token>' https://gitlab.example.com/api/v4/projects/26/clusters/23
Mayra Cabrera's avatar
Mayra Cabrera включено в состав коммита
386
```