airflow.providers.cncf.kubernetes.operators.pod_exec

Execute commands in existing Kubernetes pods.

Classes

KubernetesPodExecOperator

Execute a command in a running container of an existing Kubernetes pod.

Module Contents

class airflow.providers.cncf.kubernetes.operators.pod_exec.KubernetesPodExecOperator(*, pod_name, command, namespace=None, container_name=None, kubernetes_conn_id=KubernetesHook.default_conn_name, in_cluster=None, cluster_context=None, config_file=None, do_xcom_push=False, max_xcom_output_size=_DEFAULT_MAX_XCOM_OUTPUT_SIZE, **kwargs)[source]

Bases: airflow.sdk.BaseOperator

Execute a command in a running container of an existing Kubernetes pod.

The operator does not create, restart, or delete the target pod. Commands are executed directly, without a shell; include a shell explicitly in command when shell features are required.

Parameters:
  • pod_name (str) – Name of the existing Kubernetes pod. (templated)

  • command (collections.abc.Sequence[str]) – Command and arguments to execute in the container. (templated)

  • namespace (str | None) – Namespace containing the pod. Defaults to the namespace configured in the Kubernetes connection, then default. (templated)

  • container_name (str | None) – Name of the container in which to execute the command. When omitted, the kubectl.kubernetes.io/default-container annotation or the first container is used. (templated)

  • kubernetes_conn_id (str | None) – The Kubernetes connection to use. (templated)

  • in_cluster (bool | None) – Use in-cluster Kubernetes configuration.

  • cluster_context (str | None) – Context to use from the kubeconfig. (templated)

  • config_file (str | None) – Path to the kubeconfig file. (templated)

  • do_xcom_push (bool) – Return standard output through XCom when True. Defaults to False.

  • max_xcom_output_size (int) – Maximum UTF-8 byte size retained for XCom. Defaults to 49,344 bytes.

template_fields: collections.abc.Sequence[str] = ('pod_name', 'command', 'namespace', 'container_name', 'kubernetes_conn_id', 'cluster_context',...[source]
template_fields_renderers[source]
pod_name[source]
command[source]
namespace = None[source]
container_name = None[source]
kubernetes_conn_id = 'kubernetes_default'[source]
in_cluster = None[source]
cluster_context = None[source]
config_file = None[source]
max_xcom_output_size = 49344[source]
property hook: airflow.providers.cncf.kubernetes.hooks.kubernetes.KubernetesHook[source]
property client: kubernetes.client.CoreV1Api[source]
execute(context)[source]

Derive when creating an operator.

The main method to execute the task. Context is the same dictionary used as when rendering jinja templates.

Refer to get_template_context for more context.

on_kill()[source]

Close the active Kubernetes exec connection without modifying the target pod.

Was this entry helpful?