Manage DAGs files¶
When you create new or modify existing DAG files, it is necessary to deploy them into the environment. This section will describe some basic techniques you can use.
Bake DAGs in Docker image¶
The recommended way to update your DAGs with this chart is to build a new docker image with the latest DAG code:
Note
In airflow images prior to version 2.0.2, there was a bug that required you to use a bit longer Dockerfile, to make sure the image remains OpenShift-compatible (i.e dag has root group similarly as other files). In 2.0.2 this has been fixed.
Then publish it in the accessible registry:
Finally, update the Airflow pods with that image:
If you are deploying an image with a constant tag, you need to make sure that the image is pulled every time.
Mounting DAGs using Git-Sync sidecar with Persistence enabled¶
This option will use a Persistent Volume Claim with an access mode of ReadWriteMany
.
The scheduler pod will sync DAGs from a git repository onto the PVC every configured number of
seconds. The other pods will read the synced DAGs. Not all volume plugins have support for
ReadWriteMany
access mode.
Refer Persistent Volume Access Modes
for details.
Mounting DAGs using Git-Sync sidecar without Persistence¶
This option will use an always running Git-Sync sidecar on every scheduler, webserver (if airflowVersion < 2.0.0
)
and worker pods.
The Git-Sync sidecar containers will sync DAGs from a git repository every configured number of
seconds. If you are using the KubernetesExecutor
, Git-sync will run as an init container on your worker pods.
When using apache-airflow>=2.0.0
, DAG Serialization is enabled by default,
hence Webserver does not need access to DAG files, so git-sync
sidecar is not run on Webserver.
Mounting DAGs from an externally populated PVC¶
In this approach, Airflow will read the DAGs from a PVC which has ReadOnlyMany
or ReadWriteMany
access mode. You will have to ensure that the PVC is populated/updated with the required DAGs(this won’t be handled by the chart). You can pass in the name of the volume claim to the chart
Mounting DAGs from a private Github repo using Git-Sync sidecar¶
Create a private repo on Github if you have not created one already.
Then create your ssh keys:
Add the public key to your private repo (under Settings > Deploy keys
).
You have to convert the private ssh key to a base64 string. You can convert the private ssh key file like so:
Then copy the string from the temp.txt
file. You’ll add it to your override-values.yaml
next.
In this example, you will create a yaml file called override-values.yaml
to override values in the
values.yaml
file, instead of using --set
:
Don’t forget to copy in your private key base64 string.
Finally, from the context of your Airflow Helm chart directory, you can install Airflow:
If you have done everything correctly, Git-Sync will pick up the changes you make to the DAGs in your private Github repo.
You should take this a step further and set dags.gitSync.knownHosts
so you are not susceptible to man-in-the-middle
attacks. This process is documented in the production guide.