CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-google-cloud-container

Google Cloud Container API client library for managing Google Kubernetes Engine clusters.

Pending
Overview
Eval results
Files

cluster-management.mddocs/

Cluster Management

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.

Capabilities

Listing Clusters

Retrieve all clusters owned by a project in a specified zone or across all zones.

def list_clusters(
    self,
    request=None, *,
    project_id=None,
    zone=None,
    parent=None,
    retry=gapic_v1.method.DEFAULT,
    timeout=None,
    metadata=()
) -> ListClustersResponse:
    """
    Lists all clusters owned by a project in either the specified zone or all zones.

    Args:
        project_id (str): Deprecated. The Google Developers Console project ID or project number.
        zone (str): Deprecated. The name of the Google Compute Engine zone.
        parent (str): The parent (project and location) where the clusters will be listed.
            Format: projects/{project_id}/locations/{location}
        retry: Retry configuration.
        timeout (float): Request timeout in seconds.
        metadata: Additional gRPC metadata.

    Returns:
        ListClustersResponse: Response containing the list of clusters.
    """

Usage example:

from google.cloud import container

client = container.ClusterManagerClient()

# List clusters in a specific zone
clusters = client.list_clusters(
    project_id="my-project",
    zone="us-central1-a"
)

# Or use the new parent format
clusters = client.list_clusters(
    parent="projects/my-project/locations/us-central1-a"
)

for cluster in clusters.clusters:
    print(f"Cluster: {cluster.name}")
    print(f"Status: {cluster.status}")
    print(f"Nodes: {cluster.current_node_count}")

Getting Cluster Details

Retrieve detailed information about a specific cluster.

def get_cluster(
    self,
    request=None, *,
    project_id=None,
    zone=None,
    cluster_id=None,
    name=None,
    retry=gapic_v1.method.DEFAULT,
    timeout=None,
    metadata=()
) -> Cluster:
    """
    Gets the details of a specific cluster.

    Args:
        project_id (str): Deprecated. The Google Developers Console project ID or project number.
        zone (str): Deprecated. The name of the Google Compute Engine zone.
        cluster_id (str): Deprecated. The name of the cluster to retrieve.
        name (str): The name (project, location, cluster) of the cluster to retrieve.
            Format: projects/{project_id}/locations/{location}/clusters/{cluster_id}
        retry: Retry configuration.
        timeout (float): Request timeout in seconds.
        metadata: Additional gRPC metadata.

    Returns:
        Cluster: The cluster information.
    """

Usage example:

cluster = client.get_cluster(
    project_id="my-project",
    zone="us-central1-a",
    cluster_id="my-cluster"
)

print(f"Cluster name: {cluster.name}")
print(f"Master version: {cluster.current_master_version}")
print(f"Node version: {cluster.current_node_version}")
print(f"Cluster endpoint: {cluster.endpoint}")
print(f"Network: {cluster.network}")
print(f"Subnetwork: {cluster.subnetwork}")

Creating Clusters

Create a new GKE cluster with specified configuration.

def create_cluster(
    self,
    request=None, *,
    project_id=None,
    zone=None,
    cluster=None,
    parent=None,
    retry=gapic_v1.method.DEFAULT,
    timeout=None,
    metadata=()
) -> Operation:
    """
    Creates a cluster, consisting of the specified number and type of Google Compute Engine instances.

    Args:
        project_id (str): Deprecated. The Google Developers Console project ID or project number.
        zone (str): Deprecated. The name of the Google Compute Engine zone.
        cluster (Cluster): Required. A cluster resource.
        parent (str): The parent (project and location) where the cluster will be created.
            Format: projects/{project_id}/locations/{location}
        retry: Retry configuration.
        timeout (float): Request timeout in seconds.
        metadata: Additional gRPC metadata.

    Returns:
        Operation: An operation representing the cluster creation.
    """

Usage example:

from google.cloud import container
from google.cloud.container_v1.types import Cluster, NodeConfig

client = container.ClusterManagerClient()

# Configure cluster
cluster_config = Cluster(
    name="my-new-cluster",
    description="Test cluster created via API",
    initial_node_count=3,
    node_config=NodeConfig(
        machine_type="e2-medium",
        disk_size_gb=100,
        oauth_scopes=[
            "https://www.googleapis.com/auth/cloud-platform"
        ]
    ),
    logging_service="logging.googleapis.com/kubernetes",
    monitoring_service="monitoring.googleapis.com/kubernetes"
)

# Create cluster
operation = client.create_cluster(
    project_id="my-project",
    zone="us-central1-a",
    cluster=cluster_config
)

print(f"Creating cluster. Operation: {operation.name}")

Updating Clusters

Update an existing cluster's configuration.

def update_cluster(
    self,
    request=None, *,
    project_id=None,
    zone=None,
    cluster_id=None,
    update=None,
    name=None,
    retry=gapic_v1.method.DEFAULT,
    timeout=None,
    metadata=()
) -> Operation:
    """
    Updates the settings of a specific cluster.

    Args:
        project_id (str): Deprecated. The Google Developers Console project ID or project number.
        zone (str): Deprecated. The name of the Google Compute Engine zone.
        cluster_id (str): Deprecated. The name of the cluster to update.
        update (ClusterUpdate): Required. A description of the update.
        name (str): The name (project, location, cluster) of the cluster to update.
            Format: projects/{project_id}/locations/{location}/clusters/{cluster_id}
        retry: Retry configuration.
        timeout (float): Request timeout in seconds.
        metadata: Additional gRPC metadata.

    Returns:
        Operation: An operation representing the cluster update.
    """

Usage example:

from google.cloud.container_v1.types import ClusterUpdate

# Update cluster to enable network policy
update_config = ClusterUpdate(
    desired_network_policy=NetworkPolicy(
        enabled=True,
        provider=NetworkPolicy.Provider.CALICO
    )
)

operation = client.update_cluster(
    project_id="my-project",
    zone="us-central1-a",
    cluster_id="my-cluster",
    update=update_config
)

print(f"Updating cluster. Operation: {operation.name}")

Deleting Clusters

Delete an existing cluster and all its resources.

def delete_cluster(
    self,
    request=None, *,
    project_id=None,
    zone=None,
    cluster_id=None,
    name=None,
    retry=gapic_v1.method.DEFAULT,
    timeout=None,
    metadata=()
) -> Operation:
    """
    Deletes the cluster, including the Kubernetes endpoint and all worker nodes.

    Args:
        project_id (str): Deprecated. The Google Developers Console project ID or project number.
        zone (str): Deprecated. The name of the Google Compute Engine zone.
        cluster_id (str): Deprecated. The name of the cluster to delete.
        name (str): The name (project, location, cluster) of the cluster to delete.
            Format: projects/{project_id}/locations/{location}/clusters/{cluster_id}
        retry: Retry configuration.
        timeout (float): Request timeout in seconds.
        metadata: Additional gRPC metadata.

    Returns:
        Operation: An operation representing the cluster deletion.
    """

Usage example:

operation = client.delete_cluster(
    project_id="my-project",
    zone="us-central1-a",
    cluster_id="my-cluster"
)

print(f"Deleting cluster. Operation: {operation.name}")

Server Configuration

Get configuration information about the Google Kubernetes Engine service.

def get_server_config(
    self,
    request=None, *,
    project_id=None,
    zone=None,
    name=None,
    retry=gapic_v1.method.DEFAULT,
    timeout=None,
    metadata=()
) -> ServerConfig:
    """
    Returns configuration info about the Google Kubernetes Engine service.

    Args:
        project_id (str): Deprecated. The Google Developers Console project ID or project number.
        zone (str): Deprecated. The name of the Google Compute Engine zone.
        name (str): The name (project and location) of the server config to get.
            Format: projects/{project_id}/locations/{location}
        retry: Retry configuration.
        timeout (float): Request timeout in seconds.
        metadata: Additional gRPC metadata.

    Returns:
        ServerConfig: The server configuration.
    """

Usage example:

server_config = client.get_server_config(
    project_id="my-project",
    zone="us-central1-a"
)

print(f"Default cluster version: {server_config.default_cluster_version}")
print(f"Valid node versions: {list(server_config.valid_node_versions)}")
print(f"Valid master versions: {list(server_config.valid_master_versions)}")

Types

class ListClustersRequest:
    """ListClustersRequest lists clusters."""
    project_id: str  # Deprecated
    zone: str  # Deprecated  
    parent: str  # Required. Format: projects/{project}/locations/{location}

class ListClustersResponse:
    """ListClustersResponse is the result of ListClustersRequest."""
    clusters: MutableSequence[Cluster]
    missing_zones: MutableSequence[str]

class GetClusterRequest:
    """GetClusterRequest gets the settings of a cluster."""
    project_id: str  # Deprecated
    zone: str  # Deprecated
    cluster_id: str  # Deprecated
    name: str  # Required. Format: projects/{project}/locations/{location}/clusters/{cluster}

class CreateClusterRequest:
    """CreateClusterRequest creates a cluster."""
    project_id: str  # Deprecated
    zone: str  # Deprecated
    cluster: Cluster  # Required
    parent: str  # Required. Format: projects/{project}/locations/{location}

class UpdateClusterRequest:
    """UpdateClusterRequest updates the settings of a cluster."""
    project_id: str  # Deprecated
    zone: str  # Deprecated
    cluster_id: str  # Deprecated
    update: ClusterUpdate  # Required
    name: str  # Required. Format: projects/{project}/locations/{location}/clusters/{cluster}

class DeleteClusterRequest:
    """DeleteClusterRequest deletes a cluster."""
    project_id: str  # Deprecated
    zone: str  # Deprecated
    cluster_id: str  # Deprecated
    name: str  # Required. Format: projects/{project}/locations/{location}/clusters/{cluster}

class GetServerConfigRequest:
    """Gets the current Kubernetes Engine service configuration."""
    project_id: str  # Deprecated
    zone: str  # Deprecated
    name: str  # Required. Format: projects/{project}/locations/{location}

class ServerConfig:
    """Kubernetes Engine service configuration."""
    default_cluster_version: str
    valid_node_versions: MutableSequence[str]
    default_image_type: str
    valid_image_types: MutableSequence[str]
    valid_master_versions: MutableSequence[str]
    channels: MutableSequence[ServerConfig.ReleaseChannelConfig]

class ClusterUpdate:
    """ClusterUpdate describes an update to the cluster."""
    desired_node_version: str
    desired_monitoring_service: str
    desired_addons_config: AddonsConfig
    desired_node_pool_id: str
    desired_image_type: str
    desired_database_encryption: DatabaseEncryption
    desired_workload_identity_config: WorkloadIdentityConfig
    desired_shielded_nodes: ShieldedNodes
    desired_cost_management_config: CostManagementConfig
    desired_dns_config: DNSConfig
    desired_node_pool_autoscaling: NodePoolAutoscaling
    desired_locations: MutableSequence[str]
    desired_logging_service: str
    desired_resource_usage_export_config: ResourceUsageExportConfig
    desired_vertical_pod_autoscaling: VerticalPodAutoscaling
    desired_private_cluster_config: PrivateClusterConfig
    desired_intra_node_visibility_config: IntraNodeVisibilityConfig
    desired_default_snat_status: DefaultSnatStatus
    desired_cluster_autoscaling: ClusterAutoscaling
    desired_binary_authorization: BinaryAuthorization
    desired_logging_config: LoggingConfig
    desired_monitoring_config: MonitoringConfig
    desired_identity_service_config: IdentityServiceConfig
    desired_service_external_ips_config: ServiceExternalIPsConfig
    desired_mesh_certificates: MeshCertificates
    desired_notification_config: NotificationConfig
    desired_private_ipv6_google_access: PrivateIPv6GoogleAccess
    desired_authenticator_groups_config: AuthenticatorGroupsConfig
    desired_logging_config: LoggingConfig
    desired_monitoring_config: MonitoringConfig
    desired_master_authorized_networks_config: MasterAuthorizedNetworksConfig
    desired_cluster_autoscaling: ClusterAutoscaling
    desired_addons_config: AddonsConfig
    desired_node_pool_autoscaling: NodePoolAutoscaling
    desired_locations: MutableSequence[str]
    desired_master_version: str
    desired_gcfs_config: GcfsConfig
    desired_node_pool_auto_config_network_tags: NetworkTags
    desired_gateway_api_config: GatewayAPIConfig
    desired_protect_config: ProtectConfig
    desired_etag: str
    desired_fleet: Fleet
    desired_stack_type: StackType
    desired_in_transit_encryption_config: InTransitEncryptionConfig
    desired_datapath_provider: DatapathProvider
    desired_private_ipv6_google_access: PrivateIPv6GoogleAccess
    desired_notification_config: NotificationConfig
    desired_additional_pod_ranges_config: AdditionalPodRangesConfig
    desired_removed_additional_pod_ranges_config: AdditionalPodRangesConfig
    desired_enable_k8s_beta_apis: K8sBetaAPIConfig
    desired_security_posture_config: SecurityPostureConfig
    desired_network_performance_config: NetworkPerformanceConfig
    desired_enable_fqdn_network_policy: bool
    desired_autopilot_workload_policy_config: WorkloadPolicyConfig
    desired_k8s_beta_apis: K8sBetaAPIConfig
    desired_user_managed_keys_config: UserManagedKeysConfig
    desired_resource_manager_tags: ResourceManagerTags
    desired_node_pool_logging_config: NodePoolLoggingConfig
    desired_enterprise_config: EnterpriseConfig
    desired_secret_manager_config: SecretManagerConfig
    desired_compliance_posture_config: CompliancePostureConfig
    additional_pod_ranges_config: AdditionalPodRangesConfig
    removed_additional_pod_ranges_config: AdditionalPodRangesConfig

Install with Tessl CLI

npx tessl i tessl/pypi-google-cloud-container

docs

authentication-security.md

cluster-configuration.md

cluster-management.md

index.md

node-pool-operations.md

operations-management.md

tile.json