Launch a Pod in an AKS cluster on Azure
If some of your tasks require specific resources such as a GPU, you might want to run them in a different cluster than your Airflow instance. In setups where both clusters are used by the same AWS, Azure or GCP account, you can manage separate clusters with roles and permissions.
This example shows how to configure an Azure Managed Identity (MI) to run a Pod on an AKS cluster from an Airflow instance where cross-account access is not available.
Prerequisites
- A network connection between your Astro Deployment and your external cluster.
Setup
Set Up Azure Managed Identity
- Create a Microsoft Entra ID tenant with Global Administrator or Application Administrator privileges.
- Create a user-assigned managed identity on Azure.
- Authorize your Astro Deployment to Azure using Azure Managed Identity (MI) by following steps 1 and 2 described in the Deployment Workload identity set up.
- Confirm that the OIDC credentials appear in the Managed Identity’s Federated credentials tab.
- From the Managed Identity’s Properties tab, note the Client ID.
From your Azure Portal, go to Azure Active Directory (Microsoft Entra ID) and note the Tenant ID.
Both the Client ID and Tenant ID will be needed in Step 3 to configure your
kubeconfig
file.
Install dependencies in your Astro Runtime Docker Image
To trigger remote Pods on an Azure AKS Cluster, the following packages and dependencies need to be added to your Docker image.
- Azure CLI
- Kubectl
- Kubelogin
To do so, add the following commands to your Dockerfile:
Configure your kubeconfig
file
The following configuration file below is a sample Kubernetes kubeconfig
file that allows the Kubernetes command-line tool, kubectl
, or other clients to connect to a remote Kubernetes cluster, remote-kpo
, using Azure Workload Identity for authentication.
Create an Airflow Connection to use the kubeconfig
file
To use the kubeconfig
file, you will need to create a new Kubernetes Airflow Connection.
There are multiple ways to pass the kubeconfig
file to your Airflow Connection. If your kubeconfig
file contains any sensitive information, we recommend storing it as JSON inside the connection, described in option 3.
- External File in the default location
If the
kubeconfig
file resides in the default location on the machine (~/.kube/config), you can leave all fields empty in the connection configuration. Airflow will automatically use thekubeconfig
from the default location. Add the followingCOPY
command at the end of your Dockerfile to add yourkubeconfig
file inside your Astro Runtime Docker Image.
- External file with a Custom Path:
You can specify a custom path to the
kubeconfig
file by inserting the path into the Kube config path field of your Airflow Connection. Add the followingCOPY
command at the end of your Dockerfile to add yourkubeconfig
file inside your Astro Runtime Docker Image.
- JSON Format
You can convert the
kubeconfig
file to JSON format and paste it into the Kube config (JSON format) field in the connection configuration. Use an online converter like https://jsonformatter.org/yaml-to-json to convert YAML to JSON. Remove any sensitive information first.