# Stackable Operator for Apache Airflow

> The Stackable operator for Apache Airflow manages Airflow clusters on Kubernetes, supporting custom workflows, executors, and external databases for efficient orchestration.

-   [GitHub](https://github.com/stackabletech/airflow-operator/)

-   [Feature Tracker](https://features.stackable.tech/unified)

-   [CRD documentation](https://crds.stackable.tech/airflow-operator/26.7.0/)


The Stackable operator for Apache Airflow manages [Apache Airflow](https://airflow.apache.org/) instances on Kubernetes. Apache Airflow is an open-source application for creating, scheduling, and monitoring workflows. Workflows are defined as code, with tasks that can be run on a variety of platforms, including Hadoop, Spark, and Kubernetes itself. Airflow is a popular choice to orchestrate ETL workflows and data pipelines.

## Getting started

Get started using Airflow with the Stackable operator by following the [Getting started](https://docs.stackable.tech/home/stable/airflow/getting_started/index.md) guide. It guides you through installing the operator alongside a PostgreSQL database and Redis instance, connecting to your Airflow instance and running your first workflow.

### Custom resources

The AirflowCluster is the resource for the configuration of the Airflow instance. The custom resource defines the following [roles](https://docs.stackable.tech/home/stable/concepts/stacklet/index.md): `webserver`, `worker`, `scheduler`, `dagProcessor` and `triggerer` (the `worker` role is embedded within `spec.celeryExecutors`: this is described in the next section). The `dagProcessor` and `triggerer` roles are optional. The various configuration options are explained in the [Usage guide](https://docs.stackable.tech/home/stable/airflow/usage-guide/index.md). It helps you tune your cluster to your needs by configuring [resource usage](https://docs.stackable.tech/home/stable/airflow/usage-guide/storage-resources/index.md), [security](https://docs.stackable.tech/home/stable/airflow/usage-guide/security/index.md), [logging](https://docs.stackable.tech/home/stable/airflow/usage-guide/logging/index.md) and more.

### Executors

The `worker` role is deployed when `spec.celeryExecutors` is specified (the alternative is `spec.kubernetesExecutors`, whereby pods are created dynamically as needed without jobs being routed through a redis queue to the workers). This means that for `kubernetesExecutors` there exists an implicit single role which does not appear in resource definition. This is illustrated below:

#### `celeryExecutors`

```yaml
spec:
...
celeryExecutors:
  roleGroups:
    default:
      envOverrides:
        ...
      configOverrides:
        ...
      replicas: 2
  config:
    logging:
          ...
```

#### `kubernetesExecutors`

```yaml
spec:
...
kubernetesExecutors:
  config:
    logging:
      ...
    resources:
      ...
```

### DAG-Processors

In Airflow 2.x, a DAG-Processor can be started either as a standalone process or a subprocess within the scheduler component. For Airflow 3.x+ it _must_ be started as a standalone process, either in a separate container or in the scheduler container. In each case the default will be applied (subprocess or combined in the scheduler container) if the role is not specified.

### Triggerers

DAGs using deferrable operators can be combined with the triggerer component to free up worker slots and/or provide high availability. For more information, please refer to the [documentation](https://airflow.apache.org/docs/apache-airflow/stable/authoring-and-scheduling/deferring.html#deferrable-operators-triggers) .

### Kubernetes resources

Based on the custom resources you define, the operator creates ConfigMaps, StatefulSets and Services.

![A diagram depicting the Kubernetes resources created by the operator](https://docs.stackable.tech/home/stable/airflow/_images/airflow_overview.drawio.svg)

The diagram above depicts all the Kubernetes resources created by the operator, and how they relate to each other.

For every [role group](https://docs.stackable.tech/home/stable/concepts/stacklet/index.md) you define, the operator creates a StatefulSet with the amount of replicas defined in the RoleGroup. Every Pod in the StatefulSet has two containers: the main container running Airflow and a sidecar container gathering metrics for [Monitoring](https://docs.stackable.tech/home/stable/operators/monitoring/index.md). The operator creates a Service per role group as well as a single service for the whole `webserver` role called `<clustername>-webserver`.

Additionally, a ConfigMap is created for each RoleGroup. These ConfigMaps contain two files, `log_config.py` and `webserver_config.py`, which contain logging and general Airflow configuration respectively.

## Required external components

Airflow requires an SQL database in which to store its metadata as well as Redis for job execution. The [required external components](https://docs.stackable.tech/home/stable/airflow/required-external-components/index.md) page lists all supported databases and Redis versions to use in production. You need to provide these components for production use, but the [Getting started](https://docs.stackable.tech/home/stable/airflow/getting_started/index.md) guides you through installing an example database and Redis instance with an Airflow instance that you can use to get started.

> **Note:** Redis is only needed if the executors have been set to `spec.celeryExecutors` as the jobs are queued via Redis before being assigned to a `worker` pod. When using `spec.kubernetesExecutors` the scheduler takes direct responsibility for this.

## Using custom workflows/DAGs

[Direct acyclic graphs (DAGs) of tasks](https://airflow.apache.org/docs/apache-airflow/stable/core-concepts/dags.html) are the core entities you use in Airflow. Take a look at the page on [Mounting DAGs](https://docs.stackable.tech/home/stable/airflow/usage-guide/mounting-dags/index.md) to learn about the different ways of loading your custom DAGs into Airflow.

## Demo

You can install the [airflow-scheduled-job](https://docs.stackable.tech/home/stable/demos/airflow-scheduled-job/index.md) demo and explore an Airflow installation, as well as how it interacts with [Apache Spark](https://docs.stackable.tech/home/stable/spark-k8s/index.md).

## Supported versions

The Stackable operator for Apache Airflow currently supports the Airflow versions listed below. To use a specific Airflow version in your AirflowCluster, you have to specify an image - this is explained in the [Product image selection](https://docs.stackable.tech/home/stable/concepts/product-image-selection/index.md) documentation. The operator also supports running images from a custom registry or running entirely customized images; both of these cases are explained under [Product image selection](https://docs.stackable.tech/home/stable/concepts/product-image-selection/index.md) as well.

-   3.2.2

-   3.1.6 (deprecated)

-   3.0.6 (LTS)

-   2.9.3 (deprecated)


## Useful links

-   The [airflow-operator](https://github.com/stackabletech/airflow-operator/) GitHub repository

-   The operator feature overview in the [feature tracker](https://features.stackable.tech/unified)

-   The [AirflowCluster](https://crds.stackable.tech/26.7.0/airflow.stackable.tech/airflowcluster/v1alpha2/) CRD documentation
