Search code examples
google-cloud-platformairflowairflow-schedulergoogle-cloud-composer

Can you access the Airflow CLI within Google Cloud Composer?


I'm aware that many of the common Airflow management commands are made available through the gcloud CLI. However, I'm troubleshooting some DAG scheduling and would like to use the schedule and next_execution commands directly on the cluster.

Is there an easy way to do this?


Solution

  • It's possible to access the full Airflow CLI by using kubectl exec to SSH into Composer pods. To do so, obtain the name of the GKE cluster associated with your environment, and get cluster credentials for it:

    gcloud container clusters get-credentials $CLUSTER_NAME --zone=$ZONE
    

    Then, use kubectl to check for the Composer namespace, and then find a pod and SSH to it:

    kubectl get namespaces | grep composer
    kubectl get pods --namespace=$NAMESPACE | grep airflow
    kubectl exec -it --namespace=$NAMESPACE $POD_NAME -- bash
    

    From within a pod, you can use airflow with any command supported by that version of Airflow. However, it should also be noted that this also provides full access to commands that can make your environment permanently unusable (such as resetdb), so they should be used with care.