Single machine deployment of Apache Airflow in Hetzner Cloud using Packer and OpenTofu
- Apache Airflow with Celery Executor.
- PostgreSQL as the metadata database.
- Redis as the Celery message broker.
- Systemd services to manage Airflow components 1 (Scheduler, Webserver, Celery Worker).
- User
admin
with passwordadmin
to log in the web interface.
cx22
server with the below specs:
- CPU:
2
- Memory:
4GB
- Disk:
40GB
For the server price check Hetzner Cloud documentation.
- Packer
- OpenTofu
- An active Hetzner Cloud account.
- A Hetzner Cloud API Token. You can create one from your Hetzner Cloud Console under
Security > API tokens
.
Summary of the steps:
- Export the environment variables required by Packer and OpenTofu.
- Create SSH Key in Hetzner. This key will be used by Packer provisioners to create the snapshot.
- Build Apache Airflow snapshot with Packer. The created snapshot will be available in Hetzner Cloud Console under
Servers > Images
. - Use the latest image built in step 2 to create a new server using OpenTofu.
Warning
The below commands will be visible in the shell history. To avoid exposing these secrets, one option is to disable the history before running the commands.
export PKR_VAR_hcloud_token=<your_hetzner_api_token>
export PKR_VAR_db_password=<airflow_db_user_password>
export TF_VAR_hcloud_token=<your_hetzner_api_token>
export TF_VAR_passphrase=<opentofu_state_encryption_passphrase>
Create SSH key pairs 2. Save the public key in a file named id_rsa.pub
, and add the private key to your SSH agent 3. After creating the SSH key, locally, run the following commands to create it in Hetzner Cloud:
cp id_rsa.pub ssh-key/ && cd ssh-key
tofu init && tofu apply
cd ../server-image
packer init . && packer build hetzner-apache-airflow.pkr.hcl
cd ../server
tofu init && tofu apply
Once the tofu apply
command is complete, it will output the URL for your Airflow web interface.
- URL:
http://<your-server-ip>:8080
- Username:
admin
- Password:
admin
Caution
Remember to change the password of the admin
user.
Assuming the private key was added to the SSH agent, it should be possible to SSH to the server using the command ssh root@<airflow-server-ip>
.
To avoid incurring further costs, you should destroy the created resources when you are finished.
-
Destroy the Server:
cd server tofu destroy --auto-approve
-
Destroy the SSH Key:
cd ../ssh-key tofu destroy --auto-approve
-
Delete the Snapshot:
- Go to your Hetzner Cloud Console.
- Navigate to
Images
. - Find the snapshot named
Apache Airflow - ...
and delete it.
Footnotes
-
https://airflow.apache.org/docs/apache-airflow/stable/core-concepts/overview.html ↩
-
https://docs.github.com/en/authentication/connecting-to-github-with-ssh/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent#generating-a-new-ssh-key ↩
-
https://docs.github.com/en/authentication/connecting-to-github-with-ssh/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent#adding-your-ssh-key-to-the-ssh-agent ↩