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: ClusterLocation | None = None) ContainerCluster ¶
Create a container cluster
- Parameters:
name (
str
) – The name of the clusterlocation (
ClusterLocation
) – The location to create the cluster in
- Return type:
- 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, otherwiseFalse
.- Return type:
bool
- deploy_container(name: str, image: ContainerImage, namespace: KubernetesNamespace | None = None, parameters: str | None = None, start: bool | None = 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 containerimage (
ContainerImage
) – The container image to deploynamespace (
KubernetesNamespace
) – The namespace to deploy to, None is defaultparameters (
str
) – Container Image parameters(unused)start (
bool
) – Start the container on deployment(unused)
- Return type:
- destroy_cluster(cluster: ContainerCluster) bool ¶
Delete a cluster
- Returns:
True
if the destroy was successful, otherwiseFalse
.- 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 namespacepod_name (
str
) – Name of the pod to destroy
- Return type:
bool
- ex_list_deployments() List[KubernetesDeployment] ¶
Get cluster deployments
- Return type:
list
ofKubernetesDeployment
- ex_list_nodes_metrics() List[Dict[str, Any]] ¶
Get nodes metrics from Kubernetes Metrics Server
- Return type:
list
ofdict
- ex_list_pods(fetch_metrics: bool = False) List[KubernetesPod] ¶
List available Pods
- Parameters:
fetch_metrics (
bool
) – Fetch metrics for pods- Return type:
list
ofKubernetesPod
- ex_list_pods_metrics() List[Dict[str, Any]] ¶
Get pods metrics from Kubernetes Metrics Server
- Return type:
list
ofdict
- get_cluster(id: str) ContainerCluster ¶
Get a cluster by ID
- Parameters:
id (
str
) – The ID of the cluster to get- Return type:
- get_container(id: str) Container ¶
Get a container by ID
- Parameters:
id (
str
) – The ID of the container to get- Return type:
- 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
orGCEZone
orNodeLocation
orNone
) – 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:
- list_clusters(ex_zone=None)[source]¶
Return a list of cluster information in the current zone or all zones.
- Parameters:
ex_zone (
str
orGCEZone
orNodeLocation
orNone
) – Optional zone name or None
- list_containers(image=None, all=True) List[Container] ¶
List the deployed container images
- Parameters:
image (
libcloud.container.base.ContainerImage
) – Filter to containers with a certain image(unused)all (
bool
) – Show all container (unused)
- Return type:
- list_images() List[ContainerImage] ¶
List the installed container images
- Return type:
list
ofContainerImage
- list_locations() List[ClusterLocation] ¶
Get a list of potential locations to deploy clusters into
- Return type:
list
ofClusterLocation
- list_namespaces() List[KubernetesNamespace] ¶
Get a list of namespaces that pods can be deployed into
- Return type:
list
ofKubernetesNamespace
- supports_clusters = True¶
Whether the driver supports containers being deployed into clusters