0
# Cluster Management
1
2
Core cluster lifecycle operations for Google Kubernetes Engine. This module provides comprehensive functionality for creating, reading, updating, and deleting GKE clusters, along with cluster-specific configuration management.
3
4
## Capabilities
5
6
### Listing Clusters
7
8
Retrieve all clusters owned by a project in a specified zone or across all zones.
9
10
```python { .api }
11
def list_clusters(
12
self,
13
request=None, *,
14
project_id=None,
15
zone=None,
16
parent=None,
17
retry=gapic_v1.method.DEFAULT,
18
timeout=None,
19
metadata=()
20
) -> ListClustersResponse:
21
"""
22
Lists all clusters owned by a project in either the specified zone or all zones.
23
24
Args:
25
project_id (str): Deprecated. The Google Developers Console project ID or project number.
26
zone (str): Deprecated. The name of the Google Compute Engine zone.
27
parent (str): The parent (project and location) where the clusters will be listed.
28
Format: projects/{project_id}/locations/{location}
29
retry: Retry configuration.
30
timeout (float): Request timeout in seconds.
31
metadata: Additional gRPC metadata.
32
33
Returns:
34
ListClustersResponse: Response containing the list of clusters.
35
"""
36
```
37
38
Usage example:
39
40
```python
41
from google.cloud import container
42
43
client = container.ClusterManagerClient()
44
45
# List clusters in a specific zone
46
clusters = client.list_clusters(
47
project_id="my-project",
48
zone="us-central1-a"
49
)
50
51
# Or use the new parent format
52
clusters = client.list_clusters(
53
parent="projects/my-project/locations/us-central1-a"
54
)
55
56
for cluster in clusters.clusters:
57
print(f"Cluster: {cluster.name}")
58
print(f"Status: {cluster.status}")
59
print(f"Nodes: {cluster.current_node_count}")
60
```
61
62
### Getting Cluster Details
63
64
Retrieve detailed information about a specific cluster.
65
66
```python { .api }
67
def get_cluster(
68
self,
69
request=None, *,
70
project_id=None,
71
zone=None,
72
cluster_id=None,
73
name=None,
74
retry=gapic_v1.method.DEFAULT,
75
timeout=None,
76
metadata=()
77
) -> Cluster:
78
"""
79
Gets the details of a specific cluster.
80
81
Args:
82
project_id (str): Deprecated. The Google Developers Console project ID or project number.
83
zone (str): Deprecated. The name of the Google Compute Engine zone.
84
cluster_id (str): Deprecated. The name of the cluster to retrieve.
85
name (str): The name (project, location, cluster) of the cluster to retrieve.
86
Format: projects/{project_id}/locations/{location}/clusters/{cluster_id}
87
retry: Retry configuration.
88
timeout (float): Request timeout in seconds.
89
metadata: Additional gRPC metadata.
90
91
Returns:
92
Cluster: The cluster information.
93
"""
94
```
95
96
Usage example:
97
98
```python
99
cluster = client.get_cluster(
100
project_id="my-project",
101
zone="us-central1-a",
102
cluster_id="my-cluster"
103
)
104
105
print(f"Cluster name: {cluster.name}")
106
print(f"Master version: {cluster.current_master_version}")
107
print(f"Node version: {cluster.current_node_version}")
108
print(f"Cluster endpoint: {cluster.endpoint}")
109
print(f"Network: {cluster.network}")
110
print(f"Subnetwork: {cluster.subnetwork}")
111
```
112
113
### Creating Clusters
114
115
Create a new GKE cluster with specified configuration.
116
117
```python { .api }
118
def create_cluster(
119
self,
120
request=None, *,
121
project_id=None,
122
zone=None,
123
cluster=None,
124
parent=None,
125
retry=gapic_v1.method.DEFAULT,
126
timeout=None,
127
metadata=()
128
) -> Operation:
129
"""
130
Creates a cluster, consisting of the specified number and type of Google Compute Engine instances.
131
132
Args:
133
project_id (str): Deprecated. The Google Developers Console project ID or project number.
134
zone (str): Deprecated. The name of the Google Compute Engine zone.
135
cluster (Cluster): Required. A cluster resource.
136
parent (str): The parent (project and location) where the cluster will be created.
137
Format: projects/{project_id}/locations/{location}
138
retry: Retry configuration.
139
timeout (float): Request timeout in seconds.
140
metadata: Additional gRPC metadata.
141
142
Returns:
143
Operation: An operation representing the cluster creation.
144
"""
145
```
146
147
Usage example:
148
149
```python
150
from google.cloud import container
151
from google.cloud.container_v1.types import Cluster, NodeConfig
152
153
client = container.ClusterManagerClient()
154
155
# Configure cluster
156
cluster_config = Cluster(
157
name="my-new-cluster",
158
description="Test cluster created via API",
159
initial_node_count=3,
160
node_config=NodeConfig(
161
machine_type="e2-medium",
162
disk_size_gb=100,
163
oauth_scopes=[
164
"https://www.googleapis.com/auth/cloud-platform"
165
]
166
),
167
logging_service="logging.googleapis.com/kubernetes",
168
monitoring_service="monitoring.googleapis.com/kubernetes"
169
)
170
171
# Create cluster
172
operation = client.create_cluster(
173
project_id="my-project",
174
zone="us-central1-a",
175
cluster=cluster_config
176
)
177
178
print(f"Creating cluster. Operation: {operation.name}")
179
```
180
181
### Updating Clusters
182
183
Update an existing cluster's configuration.
184
185
```python { .api }
186
def update_cluster(
187
self,
188
request=None, *,
189
project_id=None,
190
zone=None,
191
cluster_id=None,
192
update=None,
193
name=None,
194
retry=gapic_v1.method.DEFAULT,
195
timeout=None,
196
metadata=()
197
) -> Operation:
198
"""
199
Updates the settings of a specific cluster.
200
201
Args:
202
project_id (str): Deprecated. The Google Developers Console project ID or project number.
203
zone (str): Deprecated. The name of the Google Compute Engine zone.
204
cluster_id (str): Deprecated. The name of the cluster to update.
205
update (ClusterUpdate): Required. A description of the update.
206
name (str): The name (project, location, cluster) of the cluster to update.
207
Format: projects/{project_id}/locations/{location}/clusters/{cluster_id}
208
retry: Retry configuration.
209
timeout (float): Request timeout in seconds.
210
metadata: Additional gRPC metadata.
211
212
Returns:
213
Operation: An operation representing the cluster update.
214
"""
215
```
216
217
Usage example:
218
219
```python
220
from google.cloud.container_v1.types import ClusterUpdate
221
222
# Update cluster to enable network policy
223
update_config = ClusterUpdate(
224
desired_network_policy=NetworkPolicy(
225
enabled=True,
226
provider=NetworkPolicy.Provider.CALICO
227
)
228
)
229
230
operation = client.update_cluster(
231
project_id="my-project",
232
zone="us-central1-a",
233
cluster_id="my-cluster",
234
update=update_config
235
)
236
237
print(f"Updating cluster. Operation: {operation.name}")
238
```
239
240
### Deleting Clusters
241
242
Delete an existing cluster and all its resources.
243
244
```python { .api }
245
def delete_cluster(
246
self,
247
request=None, *,
248
project_id=None,
249
zone=None,
250
cluster_id=None,
251
name=None,
252
retry=gapic_v1.method.DEFAULT,
253
timeout=None,
254
metadata=()
255
) -> Operation:
256
"""
257
Deletes the cluster, including the Kubernetes endpoint and all worker nodes.
258
259
Args:
260
project_id (str): Deprecated. The Google Developers Console project ID or project number.
261
zone (str): Deprecated. The name of the Google Compute Engine zone.
262
cluster_id (str): Deprecated. The name of the cluster to delete.
263
name (str): The name (project, location, cluster) of the cluster to delete.
264
Format: projects/{project_id}/locations/{location}/clusters/{cluster_id}
265
retry: Retry configuration.
266
timeout (float): Request timeout in seconds.
267
metadata: Additional gRPC metadata.
268
269
Returns:
270
Operation: An operation representing the cluster deletion.
271
"""
272
```
273
274
Usage example:
275
276
```python
277
operation = client.delete_cluster(
278
project_id="my-project",
279
zone="us-central1-a",
280
cluster_id="my-cluster"
281
)
282
283
print(f"Deleting cluster. Operation: {operation.name}")
284
```
285
286
### Server Configuration
287
288
Get configuration information about the Google Kubernetes Engine service.
289
290
```python { .api }
291
def get_server_config(
292
self,
293
request=None, *,
294
project_id=None,
295
zone=None,
296
name=None,
297
retry=gapic_v1.method.DEFAULT,
298
timeout=None,
299
metadata=()
300
) -> ServerConfig:
301
"""
302
Returns configuration info about the Google Kubernetes Engine service.
303
304
Args:
305
project_id (str): Deprecated. The Google Developers Console project ID or project number.
306
zone (str): Deprecated. The name of the Google Compute Engine zone.
307
name (str): The name (project and location) of the server config to get.
308
Format: projects/{project_id}/locations/{location}
309
retry: Retry configuration.
310
timeout (float): Request timeout in seconds.
311
metadata: Additional gRPC metadata.
312
313
Returns:
314
ServerConfig: The server configuration.
315
"""
316
```
317
318
Usage example:
319
320
```python
321
server_config = client.get_server_config(
322
project_id="my-project",
323
zone="us-central1-a"
324
)
325
326
print(f"Default cluster version: {server_config.default_cluster_version}")
327
print(f"Valid node versions: {list(server_config.valid_node_versions)}")
328
print(f"Valid master versions: {list(server_config.valid_master_versions)}")
329
```
330
331
## Types
332
333
```python { .api }
334
class ListClustersRequest:
335
"""ListClustersRequest lists clusters."""
336
project_id: str # Deprecated
337
zone: str # Deprecated
338
parent: str # Required. Format: projects/{project}/locations/{location}
339
340
class ListClustersResponse:
341
"""ListClustersResponse is the result of ListClustersRequest."""
342
clusters: MutableSequence[Cluster]
343
missing_zones: MutableSequence[str]
344
345
class GetClusterRequest:
346
"""GetClusterRequest gets the settings of a cluster."""
347
project_id: str # Deprecated
348
zone: str # Deprecated
349
cluster_id: str # Deprecated
350
name: str # Required. Format: projects/{project}/locations/{location}/clusters/{cluster}
351
352
class CreateClusterRequest:
353
"""CreateClusterRequest creates a cluster."""
354
project_id: str # Deprecated
355
zone: str # Deprecated
356
cluster: Cluster # Required
357
parent: str # Required. Format: projects/{project}/locations/{location}
358
359
class UpdateClusterRequest:
360
"""UpdateClusterRequest updates the settings of a cluster."""
361
project_id: str # Deprecated
362
zone: str # Deprecated
363
cluster_id: str # Deprecated
364
update: ClusterUpdate # Required
365
name: str # Required. Format: projects/{project}/locations/{location}/clusters/{cluster}
366
367
class DeleteClusterRequest:
368
"""DeleteClusterRequest deletes a cluster."""
369
project_id: str # Deprecated
370
zone: str # Deprecated
371
cluster_id: str # Deprecated
372
name: str # Required. Format: projects/{project}/locations/{location}/clusters/{cluster}
373
374
class GetServerConfigRequest:
375
"""Gets the current Kubernetes Engine service configuration."""
376
project_id: str # Deprecated
377
zone: str # Deprecated
378
name: str # Required. Format: projects/{project}/locations/{location}
379
380
class ServerConfig:
381
"""Kubernetes Engine service configuration."""
382
default_cluster_version: str
383
valid_node_versions: MutableSequence[str]
384
default_image_type: str
385
valid_image_types: MutableSequence[str]
386
valid_master_versions: MutableSequence[str]
387
channels: MutableSequence[ServerConfig.ReleaseChannelConfig]
388
389
class ClusterUpdate:
390
"""ClusterUpdate describes an update to the cluster."""
391
desired_node_version: str
392
desired_monitoring_service: str
393
desired_addons_config: AddonsConfig
394
desired_node_pool_id: str
395
desired_image_type: str
396
desired_database_encryption: DatabaseEncryption
397
desired_workload_identity_config: WorkloadIdentityConfig
398
desired_shielded_nodes: ShieldedNodes
399
desired_cost_management_config: CostManagementConfig
400
desired_dns_config: DNSConfig
401
desired_node_pool_autoscaling: NodePoolAutoscaling
402
desired_locations: MutableSequence[str]
403
desired_logging_service: str
404
desired_resource_usage_export_config: ResourceUsageExportConfig
405
desired_vertical_pod_autoscaling: VerticalPodAutoscaling
406
desired_private_cluster_config: PrivateClusterConfig
407
desired_intra_node_visibility_config: IntraNodeVisibilityConfig
408
desired_default_snat_status: DefaultSnatStatus
409
desired_cluster_autoscaling: ClusterAutoscaling
410
desired_binary_authorization: BinaryAuthorization
411
desired_logging_config: LoggingConfig
412
desired_monitoring_config: MonitoringConfig
413
desired_identity_service_config: IdentityServiceConfig
414
desired_service_external_ips_config: ServiceExternalIPsConfig
415
desired_mesh_certificates: MeshCertificates
416
desired_notification_config: NotificationConfig
417
desired_private_ipv6_google_access: PrivateIPv6GoogleAccess
418
desired_authenticator_groups_config: AuthenticatorGroupsConfig
419
desired_logging_config: LoggingConfig
420
desired_monitoring_config: MonitoringConfig
421
desired_master_authorized_networks_config: MasterAuthorizedNetworksConfig
422
desired_cluster_autoscaling: ClusterAutoscaling
423
desired_addons_config: AddonsConfig
424
desired_node_pool_autoscaling: NodePoolAutoscaling
425
desired_locations: MutableSequence[str]
426
desired_master_version: str
427
desired_gcfs_config: GcfsConfig
428
desired_node_pool_auto_config_network_tags: NetworkTags
429
desired_gateway_api_config: GatewayAPIConfig
430
desired_protect_config: ProtectConfig
431
desired_etag: str
432
desired_fleet: Fleet
433
desired_stack_type: StackType
434
desired_in_transit_encryption_config: InTransitEncryptionConfig
435
desired_datapath_provider: DatapathProvider
436
desired_private_ipv6_google_access: PrivateIPv6GoogleAccess
437
desired_notification_config: NotificationConfig
438
desired_additional_pod_ranges_config: AdditionalPodRangesConfig
439
desired_removed_additional_pod_ranges_config: AdditionalPodRangesConfig
440
desired_enable_k8s_beta_apis: K8sBetaAPIConfig
441
desired_security_posture_config: SecurityPostureConfig
442
desired_network_performance_config: NetworkPerformanceConfig
443
desired_enable_fqdn_network_policy: bool
444
desired_autopilot_workload_policy_config: WorkloadPolicyConfig
445
desired_k8s_beta_apis: K8sBetaAPIConfig
446
desired_user_managed_keys_config: UserManagedKeysConfig
447
desired_resource_manager_tags: ResourceManagerTags
448
desired_node_pool_logging_config: NodePoolLoggingConfig
449
desired_enterprise_config: EnterpriseConfig
450
desired_secret_manager_config: SecretManagerConfig
451
desired_compliance_posture_config: CompliancePostureConfig
452
additional_pod_ranges_config: AdditionalPodRangesConfig
453
removed_additional_pod_ranges_config: AdditionalPodRangesConfig
454
```