Use the @task.kubernetes decorator
The @task.kubernetes
decorator provides a TaskFlow alternative to the traditional KubernetesPodOperator, which allows you to run a specified task in its own Kubernetes pod. Note that the Docker image provided to the @task.kubernetes
decorator’s image
parameter must support executing Python scripts in order to leverage the KubernetesPodOperator decorator.
Like regular @task
decorated functions, XComs can be passed to the Python script running in the dedicated Kubernetes pod. If do_xcom_push
is set to True
in the decorator parameters, the value returned by the decorated function is pushed to XCom.
Astronomer recommends using the @task.kubernetes
decorator instead of the KubernetesPodOperator when using XCom with Python scripts in a dedicated Kubernetes pod.