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')

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, location=None)

Create a container cluster (a namespace)

Parameters:
  • name (str) – The name of the cluster
  • location (ClusterLocation) – The location to create the cluster in
Return type:

ContainerCluster

deploy_container(name, image, cluster=None, parameters=None, start=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
  • cluster (ContainerCluster) – The cluster to deploy to, None is default
  • parameters (str) – Container Image parameters
  • start (bool) – Start the container on deployment
Return type:

Container

destroy_cluster(cluster)

Delete a cluster (namespace)

Returns:True if the destroy was successful, otherwise False.
Return type:bool
destroy_container(container)

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_pod(namespace, pod_name)

Delete a pod and the containers within it.

ex_list_pods()

List available Pods

Return type:list of KubernetesPod
get_cluster(id)

Get a cluster by ID

Parameters:id (str) – The ID of the cluster to get
Return type:libcloud.container.base.ContainerCluster
get_container(id)

Get a container by ID

Parameters:id (str) – The ID of the container to get
Return type:libcloud.container.base.Container
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)

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 the deployed container images

Parameters:
Return type:

list of libcloud.container.base.Container

list_images()

List the installed container images

Return type:list of ContainerImage
list_locations()

Get a list of potential locations to deploy clusters into

Return type:list of ClusterLocation
restart_container(container)

Restart a deployed container

Parameters:container (Container) – The container to restart
Return type:Container
start_container(container)

Start a deployed container

Parameters:container (Container) – The container to start
Return type:Container
stop_container(container)

Stop a deployed container

Parameters:container (Container) – The container to stop
Return type:Container