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, otherwiseFalse
.- 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 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_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 namespacepod_name (
str
) – Name of the pod to destroy
- Return type:
bool
- ex_list_deployments() List[KubernetesDeployment] [source]
Get cluster deployments
- Return type:
list
ofKubernetesDeployment
- ex_list_nodes_metrics() List[Dict[str, Any]] [source]
Get nodes metrics from Kubernetes Metrics Server
- Return type:
list
ofdict
- ex_list_pods(fetch_metrics: bool = False) List[KubernetesPod] [source]
List available Pods
- Parameters:
fetch_metrics (
bool
) – Fetch metrics for pods- Return type:
list
ofKubernetesPod
- ex_list_pods_metrics() List[Dict[str, Any]] [source]
Get pods metrics from Kubernetes Metrics Server
- Return type:
list
ofdict
- get_container(id: str) Container [source]
Get a container by ID
- Parameters:
id (
str
) – The ID of the container to get- Return type:
- 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:
image (
libcloud.container.base.ContainerImage
) – Filter to containers with a certain image(unused)all (
bool
) – Show all container (unused)
- Return type:
- list_namespaces() List[KubernetesNamespace] [source]
Get a list of namespaces that pods can be deployed into
- Return type:
list
ofKubernetesNamespace
- 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’)