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.
Authentication¶
Authentication currently supported with the following methods:
- Basic HTTP Authentication - http://kubernetes.io/v1.1/docs/admin/authentication.html
- No authentication (testing only)
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
-
connectionCls
¶ alias of
KubernetesConnection
-
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
- name (
-
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
- name (
-
destroy_cluster
(cluster)[source]¶ Delete a cluster (namespace)
Returns: True
if the destroy was successful, otherwiseFalse
.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 destroyReturn type: bool
-
ex_list_pods
()[source]¶ List available Pods
Return type: list
ofKubernetesPod
-
get_cluster
(id)[source]¶ Get a cluster by ID
Parameters: id ( str
) – The ID of the cluster to getReturn type: libcloud.container.base.ContainerCluster
-
get_container
(id)[source]¶ Get a container by ID
Parameters: id ( str
) – The ID of the container to getReturn type: libcloud.container.base.Container
-
install_image
(path)¶ Install a container image from a remote path.
Parameters: path ( str
) – Path to the container imageReturn 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 inReturn type: list
oflibcloud.container.base.ContainerCluster
-
list_containers
(image=None, all=True)[source]¶ List the deployed container images
Parameters: - image (
libcloud.container.base.ContainerImage
) – Filter to containers with a certain image - all (
bool
) – Show all container (including stopped ones)
Return type: - image (
-
list_images
()¶ List the installed container images
Return type: list
ofContainerImage
-
list_locations
()¶ Get a list of potential locations to deploy clusters into
Return type: list
ofClusterLocation
-
restart_container
(container)¶ Restart a deployed container
Parameters: container ( Container
) – The container to restartReturn type: Container
-
start_container
(container)¶ Start a deployed container
Parameters: container ( Container
) – The container to startReturn type: Container
-
stop_container
(container)¶ Stop a deployed container
Parameters: container ( Container
) – The container to stopReturn type: Container
- key (