chapter ten

10 Running tasks in containers

 

This chapter covers:

  • Identifying some challenges involved in managing Airflow deployments that use many different operators, complex dependencies, etc.
  • Examining how containerized approaches can help simplify Airflow deployments by providing a uniform way of building and running tasks, whilst also simplifying dependency management.
  • Running containerized tasks in Airflow on Docker using the DockerOperator and on Kubernetes clusters using the KubernetesPodOperator.
  • Establishing a high-level overview of the workflows involved in developing containerized DAGs based on Docker and Kubernetes.

In previous chapters, we have implemented several DAGs using different Airflow operators, each specialized to perform a specific type of task. In this chapter, we touch upon some of the drawbacks of using many different operators, especially with an eye on creating Airflow DAGs that are easy to build, deploy, and maintain. In light of these issues, we take a look at how we can use Airflow to run tasks in containers using Docker and Kubernetes and some of the benefits that this containerized approach can bring.

10.1  Challenges of many different operators

Operators are arguably one of the strong features of Airflow, as they provide great flexibility to coordinate jobs across many different types of systems. However, creating and managing DAGs with many different operators can be quite challenging due to the complexity involved.

10.1.1    Operator interfaces and implementations

10.1.2    Complex and conflicting dependencies

10.1.3    Moving towards a generic operator

10.2  Introducing containers

10.2.1    What are containers?

10.2.2    Running our first Docker container

10.2.3    Creating a Docker image

10.2.4    Persisting data using volumes

10.3  Containers and Airflow

10.3.1    Tasks in containers

10.3.2    Why use containers?

10.3.3    Easier dependency management

10.3.4    Uniform approach for running different tasks

10.3.5    Improved testability

10.4  Running tasks in Docker

10.4.1    Introducing the DockerOperator

10.4.2    Creating container images for tasks

10.4.3    Building a DAG with dockerized tasks

10.4.4    Docker-based workflow

10.5  Running tasks in Kubernetes

10.5.1    Introducing Kubernetes

10.5.2    Setting up Kubernetes