Kubernetes Documentation

Note

This Kubernetes driver will be subject to change from community feedback. How to map the core assets (pods, clusters) to API entities will be subject to testing and further community feedback.

Kubernetes is an open source orchestration system for Docker containers. It handles scheduling onto nodes in a compute cluster and actively manages workloads to ensure that their state matches the users declared intentions. Using the concepts of “labels” and “pods”, it groups the containers which make up an application into logical units for easy management and discovery.

../../_images/kubernetes.png

Authentication

Authentication currently supported with the following methods:

Instantiating the driver

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

cls = get_driver(Provider.KUBERNETES)

conn = cls(key='my_username',
           secret='THIS_IS)+_MY_SECRET_KEY+I6TVkv68o4H',
           host='126.32.21.4')

for container in conn.list_containers():
    print(container.name)

for cluster in conn.list_clusters():
    print(cluster.name)

Deploying a container from Docker Hub

Docker Hub Client HubClient is a shared utility class for interfacing to the public Docker Hub Service.

You can use this class for fetching images to deploy to services like ECS

from libcloud.container.types import Provider
from libcloud.container.providers import get_driver
from libcloud.container.utils.docker import HubClient

cls = get_driver(Provider.KUBERNETES)

conn = cls(key='my_username',
           secret='THIS_IS)+_MY_SECRET_KEY+I6TVkv68o4H',
           host='126.32.21.4')
hub = HubClient()

image = hub.get_image('ubuntu', 'latest')

for cluster in conn.list_clusters():
    print(cluster.name)
    if cluster.name == 'default':
        container = conn.deploy_container(
            cluster=cluster,
            name='my-simple-app',
            image=image)

API Docs

class libcloud.container.drivers.kubernetes.KubernetesContainerDriver(key=None, secret=None, secure=False, host='localhost', port=4243)[source]
Parameters:
  • key (str) – API key or username to used (required)
  • secret (str) – Secret password to be used (required)
  • secure (bool) – Whether to use HTTPS or HTTP. Note: Some providers only support HTTPS, and it is on by default.
  • host (str) – Override hostname used for connections.
  • port (int) – Override port used for connections.
Returns:

None

create_cluster(name, location=None)[source]

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)[source]

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)[source]

Delete a cluster (namespace)

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

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)[source]

Delete a pod and the containers within it.

ex_list_pods()[source]

List available Pods

Return type:list of KubernetesPod
get_cluster(id)[source]

Get a cluster by ID

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

Get a container by ID

Parameters:id (str) – The ID of the container to get
Return type:libcloud.container.base.Container
install_image(path)

Install a container image from a remote path.

Parameters:path (str) – Path to the container image
Return type:ContainerImage
list_clusters()[source]

Get a list of namespaces that pods can be deployed into

Parameters:location (libcloud.container.base.ClusterLocation) – The location to search in
Return type:list of libcloud.container.base.ContainerCluster
list_containers(image=None, all=True)[source]

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