airflow.providers.cncf.kubernetes.hooks.kubernetes
¶
Module Contents¶
Classes¶
Creates Kubernetes API connection. |
|
Hook to use Kubernetes SDK asynchronously. |
Attributes¶
- airflow.providers.cncf.kubernetes.hooks.kubernetes.LOADING_KUBE_CONFIG_FILE_RESOURCE = 'Loading Kubernetes configuration file kube_config from {}...'[source]¶
- class airflow.providers.cncf.kubernetes.hooks.kubernetes.KubernetesHook(conn_id=default_conn_name, client_configuration=None, cluster_context=None, config_file=None, in_cluster=None, disable_verify_ssl=None, disable_tcp_keepalive=None)[source]¶
Bases:
airflow.hooks.base.BaseHook
Creates Kubernetes API connection.
use in cluster configuration by using extra field
in_cluster
in connectionuse custom config by providing path to the file using extra field
kube_config_path
in connection- use custom configuration by providing content of kubeconfig file via
extra field
kube_config
in connection
use default config by providing no extras
This hook check for configuration option in the above order. Once an option is present it will use this configuration.
See also
For more information about Kubernetes connection: Kubernetes cluster Connection
- Parameters
conn_id (str | None) – The kubernetes connection to Kubernetes cluster.
client_configuration (client.Configuration | None) – Optional dictionary of client configuration params. Passed on to kubernetes client.
cluster_context (str | None) – Optionally specify a context to use (e.g. if you have multiple in your kubeconfig.
config_file (str | None) – Path to kubeconfig file.
in_cluster (bool | None) – Set to
True
if running from within a kubernetes cluster.disable_verify_ssl (bool | None) – Set to
True
if SSL verification should be disabled.disable_tcp_keepalive (bool | None) – Set to
True
if you want to disable keepalive logic.
- property is_in_cluster: bool[source]¶
Expose whether the hook is configured with
load_incluster_config
or not
- create_custom_object(group, version, plural, body, namespace=None)[source]¶
Creates custom resource definition object in Kubernetes :param group: api group :param version: api version :param plural: api plural :param body: crd object definition :param namespace: kubernetes namespace
- get_custom_object(group, version, plural, name, namespace=None)[source]¶
Get custom resource definition object from Kubernetes
- delete_custom_object(group, version, plural, name, namespace=None, **kwargs)[source]¶
Delete custom resource definition object from Kubernetes
- get_namespace()[source]¶
Returns the namespace defined in the connection or ‘default’.
TODO: in provider version 6.0, return None when namespace not defined in connection
- get_xcom_sidecar_container_image()[source]¶
Returns the xcom sidecar image that defined in the connection
- get_xcom_sidecar_container_resources()[source]¶
Returns the xcom sidecar resources that defined in the connection
- get_pod_log_stream(pod_name, container='', namespace=None)[source]¶
Retrieves a log stream for a container in a kubernetes pod.
- get_pod_logs(pod_name, container='', namespace=None)[source]¶
Retrieves a container’s log from the specified pod.
- get_namespaced_pod_list(label_selector='', namespace=None, watch=False, **kwargs)[source]¶
Retrieves a list of Kind pod which belong default kubernetes namespace :param label_selector: A selector to restrict the list of returned objects by their labels :param namespace: kubernetes namespace :param watch: Watch for changes to the described resources and return them as a stream
- class airflow.providers.cncf.kubernetes.hooks.kubernetes.AsyncKubernetesHook(config_dict=None, *args, **kwargs)[source]¶
Bases:
KubernetesHook
Hook to use Kubernetes SDK asynchronously.
- async read_logs(name, namespace)[source]¶
Reads logs inside the pod while starting containers inside. All the logs will be outputted with its timestamp to track the logs after the execution of the pod is completed. The method is used for async output of the logs only in the pod failed it execution or the task was cancelled by the user.