|
| 1 | +[🔗 Return to `Table of Contents` for more FAQ topics 🔗](https://github.com/airflow-helm/charts/tree/main/charts/airflow#frequently-asked-questions) |
| 2 | + |
| 3 | +> Note, this page was written for the [`User-Community Airflow Helm Chart`](https://github.com/airflow-helm/charts/tree/main/charts/airflow) |
| 4 | +
|
| 5 | +# How to load airflow plugins? |
| 6 | + |
| 7 | +There are multiple ways to load [airflow plugins](https://airflow.apache.org/docs/apache-airflow/stable/plugins.html) when using the chart. |
| 8 | + |
| 9 | +## Option 1 - embedded into container image (recommended) |
| 10 | + |
| 11 | +This chart uses the official [apache/airflow](https://hub.docker.com/r/apache/airflow) images, you may extend the airflow container image with your airflow plugins. |
| 12 | + |
| 13 | +For example, here is a Dockerfile that extends `airflow:2.1.4-python3.8` with custom plugins: |
| 14 | + |
| 15 | +```dockerfile |
| 16 | +FROM apache/airflow:2.1.4-python3.8 |
| 17 | + |
| 18 | +# plugin files can be copied under `/home/airflow/plugins` |
| 19 | +# (where `./plugins` is relative to the docker build context) |
| 20 | +COPY plugins/* /home/airflow/plugins/ |
| 21 | + |
| 22 | +# plugins exposed as python packages can be installed with pip |
| 23 | +RUN pip install --no-cache-dir \ |
| 24 | + example==1.0.0 |
| 25 | +``` |
| 26 | + |
| 27 | +After building and tagging your Dockerfile as `MY_REPO:MY_TAG`, you may use it with the chart by specifying `airflow.image.*`: |
| 28 | + |
| 29 | +```yaml |
| 30 | +airflow: |
| 31 | + image: |
| 32 | + repository: MY_REPO |
| 33 | + tag: MY_TAG |
| 34 | + |
| 35 | + ## WARNING: even if set to "Always" do not reuse tag names, as containers only pull the latest image when restarting |
| 36 | + pullPolicy: IfNotPresent |
| 37 | +``` |
| 38 | +
|
| 39 | +## Option 2 - git-sync dags repo |
| 40 | +
|
| 41 | +> 🟥 __Warning__ 🟥 |
| 42 | +> |
| 43 | +> With "Option 2", you must manually restart the webserver and scheduler pods for plugin changes to take effect. |
| 44 | +
|
| 45 | +If you are using git-sync to [load your DAG definitions](../dags/load-dag-definitions.md), you may also include your plugins in this repo. |
| 46 | +
|
| 47 | +For example, if your DAG git repo includes plugins under `./PATH/TO/PLUGINS`: |
| 48 | + |
| 49 | +```yaml |
| 50 | +airflow: |
| 51 | + configs: |
| 52 | + ## NOTE: there is an extra `/repo/` in the path |
| 53 | + AIRFLOW__CORE__PLUGINS_FOLDER: /opt/airflow/dags/repo/PATH/TO/PLUGINS |
| 54 | + |
| 55 | +dags: |
| 56 | + ## NOTE: this is the default value |
| 57 | + #path: /opt/airflow/dags |
| 58 | + |
| 59 | + gitSync: |
| 60 | + enabled: true |
| 61 | + repo: "[email protected]:USERNAME/REPOSITORY.git" |
| 62 | + branch: "master" |
| 63 | + revision: "HEAD" |
| 64 | + syncWait: 60 |
| 65 | + sshSecret: "airflow-ssh-git-secret" |
| 66 | + sshSecretKey: "id_rsa" |
| 67 | + |
| 68 | + # "known_hosts" verification can be disabled by setting to "" |
| 69 | + sshKnownHosts: |- |
| 70 | + github.com ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAq2A7hRGmdnm9tUDbO9IDSwBK6TbQa+PXYPCPy6rbTrTtw7PHkccKrpp0yVhp5HdEIcKr6pLlVDBfOLX9QUsyCOV0wzfjIJNlGEYsdlLJizHhbn2mUjvSAHQqZETYP81eFzLQNnPHt4EVVUh7VfDESU84KezmD5QlWpXLmvU31/yMf+Se8xhHTvKSCZIFImWwoG6mbUoWf9nzpIoaSjB+weqqUUmpaaasXVal72J+UX2B+2RPW3RcT0eOzQgqlJL3RKrTJvdsjE3JEAvGq3lGHSZXy28G3skua2SmVi/w4yCE6gbODqnTWlg7+wC604ydGXA8VJiS5ap43JXiUFFAaQ== |
| 71 | +``` |
| 72 | +
|
| 73 | +## Option 3 - persistent volume |
| 74 | +
|
| 75 | +> 🟥 __Warning__ 🟥 |
| 76 | +> |
| 77 | +> With "Option 3", you must manually restart the webserver and scheduler pods for plugin changes to take effect. |
| 78 | +
|
| 79 | +You may load airflow plugins that are stored in a Kubernetes [Persistent Volume](https://kubernetes.io/docs/concepts/storage/persistent-volumes/) by using the `airflow.extraVolumeMounts` and `airflow.extraVolumes` values. |
| 80 | + |
| 81 | +For example, to mount a PersistentVolumeClaim called `airflow-plugins` that contains airflow plugin files at its root: |
| 82 | + |
| 83 | +```yaml |
| 84 | +airflow: |
| 85 | + configs: |
| 86 | + ## NOTE: this is the default value |
| 87 | + #AIRFLOW__CORE__PLUGINS_FOLDER: /opt/airflow/plugins |
| 88 | +
|
| 89 | + extraVolumeMounts: |
| 90 | + - name: airflow-plugins |
| 91 | + mountPath: /opt/airflow/plugins |
| 92 | + ## NOTE: if plugin files are not at the root of the volume, you may set a subPath |
| 93 | + #subPath: "path/to/plugins" |
| 94 | + readOnly: true |
| 95 | +
|
| 96 | + extraVolumes: |
| 97 | + - name: airflow-plugins |
| 98 | + persistentVolumeClaim: |
| 99 | + claimName: airflow-plugins |
| 100 | +``` |
| 101 | + |
| 102 | +## Option 4 - ConfigMaps or Secrets |
| 103 | + |
| 104 | +> 🟥 __Warning__ 🟥 |
| 105 | +> |
| 106 | +> With "Option 4", you must manually restart the webserver and scheduler pods for plugin changes to take effect. |
| 107 | + |
| 108 | +You may load airflow plugins that are sored in Kubernetes Secrets or ConfigMaps by using the `airflow.extraVolumeMounts` and `airflow.extraVolumes` values. |
| 109 | + |
| 110 | +For example, to mount airflow plugin files from a ConfigMap called `airflow-plugins`: |
| 111 | + |
| 112 | +```yaml |
| 113 | +workers: |
| 114 | + configs: |
| 115 | + ## NOTE: this is the default value |
| 116 | + #AIRFLOW__CORE__PLUGINS_FOLDER: /opt/airflow/plugins |
| 117 | + |
| 118 | + extraVolumeMounts: |
| 119 | + - name: airflow-plugins |
| 120 | + mountPath: /opt/airflow/plugins |
| 121 | + readOnly: true |
| 122 | +
|
| 123 | + extraVolumes: |
| 124 | + - name: airflow-plugins |
| 125 | + configMap: |
| 126 | + name: airflow-plugins |
| 127 | +``` |
| 128 | + |
| 129 | +> 🟦 __Tip__ 🟦 |
| 130 | +> |
| 131 | +> Your `airflow-plugins` ConfigMap might look something like this. |
| 132 | +> |
| 133 | +> ```yaml |
| 134 | +> apiVersion: v1 |
| 135 | +> kind: ConfigMap |
| 136 | +> metadata: |
| 137 | +> name: airflow-plugins |
| 138 | +> data: |
| 139 | +> my_airflow_plugin.py: | |
| 140 | +> from airflow.plugins_manager import AirflowPlugin |
| 141 | +> |
| 142 | +> class MyAirflowPlugin(AirflowPlugin): |
| 143 | +> name = "my_airflow_plugin" |
| 144 | +> ... |
| 145 | +> ``` |
| 146 | + |
| 147 | +> 🟦 __Tip__ 🟦 |
| 148 | +> |
| 149 | +> You may include the ConfigMap as an [extra manifest](../kubernetes/extra-manifests.md) of the chart using the `extraManifests` value. |
| 150 | +> |
| 151 | +> ```yaml |
| 152 | +> extraManifests: |
| 153 | +> - | |
| 154 | +> apiVersion: v1 |
| 155 | +> kind: ConfigMap |
| 156 | +> metadata: |
| 157 | +> name: airflow-plugins |
| 158 | +> labels: |
| 159 | +> app: {{ include "airflow.labels.app" . }} |
| 160 | +> chart: {{ include "airflow.labels.chart" . }} |
| 161 | +> release: {{ .Release.Name }} |
| 162 | +> heritage: {{ .Release.Service }} |
| 163 | +> data: |
| 164 | +> my_airflow_plugin.py: | |
| 165 | +> from airflow.plugins_manager import AirflowPlugin |
| 166 | +> |
| 167 | +> class MyAirflowPlugin(AirflowPlugin): |
| 168 | +> name = "my_airflow_plugin" |
| 169 | +> ... |
| 170 | +> ``` |
0 commit comments