You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

MWAA(Airflow)在EKS(K8s)上的dbt任务Pod状态异常问询

问题排查:MWAA中Cosmos运行dbt Pod快速从Pending到Completed

环境信息

  • MWAA(Airflow)2.8.1
  • requirements.txt依赖:
    • astronomer-cosmos==1.3.2
    • apache-airflow-providers-cncf-kubernetes
  • EKS(K8s)1.27

DAG代码

from pathlib import Path

from airflow import DAG
from pendulum import datetime
from cosmos.config import ProjectConfig

from cosmos import (
    ProfileConfig,
    ExecutionConfig,
    ExecutionMode,
    DbtTaskGroup,
)
from cosmos.profiles import RedshiftUserPasswordProfileMapping
from airflow.operators.empty import EmptyOperator

PROJECT_DIR = Path("dags/dbt/dbtcicdnew/")


with DAG(
    dag_id="dbtcicdnew",
    start_date=datetime(2022, 11, 27),
    doc_md=__doc__,
    catchup=False,
) as dag:


    run_models = DbtTaskGroup(
        profile_config=ProfileConfig(
            profile_name="dbtcicdnew",
            target_name="dev",
            profile_mapping=RedshiftUserPasswordProfileMapping(
                conn_id="redshift_default",
                profile_args={
                    "schema": "public",
                },
            ),
        ),
        project_config=ProjectConfig(PROJECT_DIR),
        execution_config=ExecutionConfig(
            execution_mode=ExecutionMode.KUBERNETES,
        ),
        operator_args={
            "do_xcom_push": False,
            "project_dir":"/app",
            "image": "xxx.dkr.ecr.us-east-2.amazonaws.com/dbtcicdnew:1.0",
            "get_logs": True,
            "is_delete_operator_pod": False,
            "namespace": "mwaa",
            "config_file": "/usr/local/airflow/dags/kubeconfig",
            "in_cluster": False,
            "image_pull_policy": "Always",
        },
    )
    e1 = EmptyOperator(task_id="pre_dbt")
    e2 = EmptyOperator(task_id="post_dbt")
    e1 >> run_models >> e2

问题描述

触发DAG运行后,执行kubectl get po -A -w观察到Pod从Pending状态直接切换到Completed状态,耗时0秒。虽Pod显示运行正常,但该状态变化不符合预期,需排查异常原因。

补充信息:dbt项目为公开仓库中的dbtcicdnew项目

排查步骤

1. 查看Pod日志

直接查看Pod的标准输出和错误日志,确认是否有执行报错:

kubectl logs <pod-name> -n mwaa

重点排查是否存在dbt命令执行失败、项目文件缺失、权限不足等问题。

2. 验证容器镜像内容

当前配置指定project_dir="/app",需确认镜像内/app路径下是否有完整的dbt项目文件:

docker pull xxx.dkr.ecr.us-east-2.amazonaws.com/dbtcicdnew:1.0
docker run -it --rm xxx.dkr.ecr.us-east-2.amazonaws.com/dbtcicdnew:1.0 ls -la /app

若/app目录为空或缺少dbt核心文件(如dbt_project.yml),dbt会因无任务可执行直接退出,导致Pod快速完成。

3. 修正Kubernetes Operator配置

  • 挂载dbt项目目录:当前配置未将MWAA中的PROJECT_DIR(dags/dbt/dbtcicdnew/)挂载到容器内的/app路径,需在operator_args中添加volume_mounts和volumes配置:
    operator_args={
        # 原有参数...
        "volume_mounts": [{"name": "dbt-project", "mountPath": "/app"}],
        "volumes": [{"name": "dbt-project", "hostPath": {"path": "/usr/local/airflow/dags/dbt/dbtcicdnew"}}]
    }
    
  • 调整in_cluster参数:MWAA运行在EKS集群内部,建议将in_cluster设为True,无需指定config_file,避免kubeconfig路径或权限问题。

4. 检查dbt项目有效性

确认dbt项目的dbt_project.yml配置正确,且包含可执行的models、seeds或snapshot任务。若项目无有效任务,dbt会直接退出。

5. 查看MWAA任务日志

在MWAA控制台查看对应DAG任务的日志,确认Cosmos生成的dbt执行命令是否正确,是否有任务初始化失败的提示。


内容的提问来源于stack exchange,提问作者Lin

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.24 07:53:31