Google Container Driver Documentation

Google Container Platform is a Kubernetes hosting service, provided by Google. Docker-native tools and elastic hosts make deploying on Google Cloud as easy as running Docker on your laptop. There is no special software to install or configure. Mix Kubernetes containers with container-native Linux to extend the benefits of containerization to legacy applications and stateful services.

Examples

Additional example code can be found in the “demos” directory of Libcloud here: https://github.com/apache/libcloud/blob/trunk/demos/gce_demo.py

1. Getting Driver with Service Account authentication

from libcloud.compute.types import Provider
from libcloud.compute.providers import get_driver

ComputeEngine = get_driver(Provider.GCE)
# Note that the 'PEM file' argument can either be the JSON format or
# the P12 format.
driver = ComputeEngine(
    "your_service_account_email",
    "path_to_pem_file",
    project="your_project_id",
    datacenter="us-central1-a",
)

API Docs

class libcloud.container.drivers.gke.GKEContainerDriver(user_id, key=None, datacenter=None, project=None, auth_type=None, scopes=None, credential_file=None, host=None, port=443, **kwargs)[source]

GKE Container Driver class.

This is the primary driver for interacting with Google Container Engine. It contains all of the standard libcloud methods, plus additional ex_* methods for more features.

Note that many methods allow either objects or strings (or lists of objects/strings). In most cases, passing strings instead of objects will result in additional GKE API calls.

Parameters:
  • user_id (str) – The email address (for service accounts) or Client ID (for installed apps) to be used for authentication.

  • key (str) – The RSA Key (for service accounts) or file path containing key or Client Secret (for installed apps) to be used for authentication.

  • datacenter (str) – The name of the datacenter (zone) used for operations.

  • project (str) – Your GKE project name. (required)

  • auth_type (str) – Accepted values are “SA” or “IA” or “GKE” (“Service Account” or “Installed Application” or “GKE” if libcloud is being used on a GKE instance with service account enabled). If not supplied, auth_type will be guessed based on value of user_id or if the code is being executed in a GKE instance.

  • scopes (list) – List of authorization URLs. Default is empty and grants read/write to Compute, Storage, DNS.

  • credential_file (str) – Path to file for caching authentication information used by GKEConnection.

connectionCls

alias of GKEConnection

create_cluster(name: str, location: Optional[ClusterLocation] = None) ContainerCluster

Create a container cluster

Parameters:
  • name (str) – The name of the cluster

  • location (ClusterLocation) – The location to create the cluster in

Return type:

ContainerCluster

create_namespace(name: str) KubernetesNamespace

Create a namespace

Parameters:

name (str) – The name of the namespace

Return type:

KubernetesNamespace

delete_namespace(namespace: KubernetesNamespace) bool

Delete a namespace

Returns:

True if the destroy was successful, otherwise False.

Return type:

bool

deploy_container(name: str, image: ContainerImage, namespace: Optional[KubernetesNamespace] = None, parameters: Optional[str] = None, start: Optional[bool] = True)

Deploy an installed container image. In kubernetes this deploys a single container Pod. https://cloud.google.com/container-engine/docs/pods/single-container

Parameters:
  • name (str) – The name of the new container

  • image (ContainerImage) – The container image to deploy

  • namespace (KubernetesNamespace) – The namespace to deploy to, None is default

  • parameters (str) – Container Image parameters(unused)

  • start (bool) – Start the container on deployment(unused)

Return type:

Container

destroy_cluster(cluster: ContainerCluster) bool

Delete a cluster

Returns:

True if the destroy was successful, otherwise False.

Return type:

bool

destroy_container(container: Container) bool

Destroy a deployed container. Because the containers are single container pods, this will delete the pod.

Parameters:

container (Container) – The container to destroy

Return type:

bool

ex_destroy_node(node_name: str) bool

Destroy a node.

Parameters:

node_name (str) – Name of the node to destroy

Return type:

bool

ex_destroy_pod(namespace: str, pod_name: str) bool

Delete a pod and the containers within it.

Parameters:
  • namespace (str) – The pod’s namespace

  • pod_name (str) – Name of the pod to destroy

Return type:

bool

ex_get_version() str

Get Kubernetes version

Return type:

str

ex_list_deployments() List[KubernetesDeployment]

Get cluster deployments

Return type:

list of KubernetesDeployment

ex_list_nodes() List[Node]

List available Nodes

Return type:

list of Node

ex_list_nodes_metrics() List[Dict[str, Any]]

Get nodes metrics from Kubernetes Metrics Server

Return type:

list of dict

ex_list_pods(fetch_metrics: bool = False) List[KubernetesPod]

List available Pods

Parameters:

fetch_metrics (bool) – Fetch metrics for pods

Return type:

list of KubernetesPod

ex_list_pods_metrics() List[Dict[str, Any]]

Get pods metrics from Kubernetes Metrics Server

Return type:

list of dict

ex_list_services() List[Dict[str, Any]]

Get cluster services

Return type:

list of dict

get_cluster(id: str) ContainerCluster

Get a cluster by ID

Parameters:

id (str) – The ID of the cluster to get

Return type:

ContainerCluster

get_container(id: str) Container

Get a container by ID

Parameters:

id (str) – The ID of the container to get

Return type:

libcloud.container.base.Container

get_namespace(id: str) KubernetesNamespace

Get a namespace by ID

Parameters:

id (str) – The ID of the namespace to get

Return type:

KubernetesNamespace

get_server_config(ex_zone=None)[source]

Return configuration info about the Container Engine service.

Parameters:

ex_zone (str or GCEZone or NodeLocation or None) – Optional zone name or None

install_image(path: str) ContainerImage

Install a container image from a remote path.

Parameters:

path (str) – Path to the container image

Return type:

ContainerImage

list_clusters(ex_zone=None)[source]

Return a list of cluster information in the current zone or all zones.

Parameters:

ex_zone (str or GCEZone or NodeLocation or None) – Optional zone name or None

list_containers(image=None, all=True) List[Container]

List the deployed container images

Parameters:
Return type:

list of libcloud.container.base.Container

list_images() List[ContainerImage]

List the installed container images

Return type:

list of ContainerImage

list_locations() List[ClusterLocation]

Get a list of potential locations to deploy clusters into

Return type:

list of ClusterLocation

list_namespaces() List[KubernetesNamespace]

Get a list of namespaces that pods can be deployed into

Return type:

list of KubernetesNamespace

restart_container(container: Container) Container

Restart a deployed container

Parameters:

container (Container) – The container to restart

Return type:

Container

start_container(container: Container) Container

Start a deployed container

Parameters:

container (Container) – The container to start

Return type:

Container

stop_container(container: Container) Container

Stop a deployed container

Parameters:

container (Container) – The container to stop

Return type:

Container

supports_clusters = True

Whether the driver supports containers being deployed into clusters