libcloud.container.drivers.kubernetes module

class libcloud.container.drivers.kubernetes.KubernetesContainerDriver(key=None, secret=None, secure=False, host='localhost', port=4243, key_file=None, cert_file=None, ca_cert=None, ex_token_bearer_auth=False)[source]

Bases: KubernetesDriverMixin, ContainerDriver

Parameters:
  • key (str) – API key or username to be 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.

  • key_file (str) – Path to the key file used to authenticate (when using key file auth).

  • cert_file (str) – Path to the cert file used to authenticate (when using key file auth).

  • ex_token_bearer_auth (bool) – True to use token bearer auth.

Returns:

None

connectionCls

alias of KubernetesBasicAuthConnection

create_namespace(name: str) KubernetesNamespace[source]

Create a namespace

Parameters:

name (str) – The name of the namespace

Return type:

KubernetesNamespace

delete_namespace(namespace: KubernetesNamespace) bool[source]

Delete a namespace

Returns:

True if the destroy was successful, otherwise False.

Return type:

bool

deploy_container(name: str, image: ContainerImage, namespace: KubernetesNamespace | None = None, parameters: str | None = None, start: bool | None = 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

  • 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_container(container: Container) bool[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_node(node_name: str) bool[source]

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

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

Get Kubernetes version

Return type:

str

ex_list_deployments() List[KubernetesDeployment][source]

Get cluster deployments

Return type:

list of KubernetesDeployment

ex_list_nodes() List[Node][source]

List available Nodes

Return type:

list of Node

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

Get nodes metrics from Kubernetes Metrics Server

Return type:

list of dict

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

List available Pods

Parameters:

fetch_metrics (bool) – Fetch metrics for pods

Return type:

list of KubernetesPod

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

Get pods metrics from Kubernetes Metrics Server

Return type:

list of dict

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

Get cluster services

Return type:

list of dict

get_container(id: str) Container[source]

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

Get a namespace by ID

Parameters:

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

Return type:

KubernetesNamespace

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

List the deployed container images

Parameters:
Return type:

list of libcloud.container.base.Container

list_namespaces() List[KubernetesNamespace][source]

Get a list of namespaces that pods can be deployed into

Return type:

list of KubernetesNamespace

name = 'Kubernetes'
supports_clusters = True

Whether the driver supports containers being deployed into clusters

type = 'kubernetes'
website = 'http://kubernetes.io'
libcloud.container.drivers.kubernetes.to_cpu_str(n_cpus: int | float) str[source]

Convert number of cpus to cpu string (e.g. 0.5 -> ‘500m’)

libcloud.container.drivers.kubernetes.to_memory_str(n_bytes: int, unit: str | None = None) str[source]

Convert number of bytes to k8s memory string (e.g. 1293942784 -> ‘1234Mi’)

libcloud.container.drivers.kubernetes.to_n_bytes(memory_str: str) int[source]

Convert memory string to number of bytes (e.g. ‘1234Mi’-> 1293942784)

libcloud.container.drivers.kubernetes.to_n_cpus(cpu_str: str) int | float[source]

Convert cpu string to number of cpus (e.g. ‘500m’ -> 0.5, ‘2000000000n’ -> 2)