使用KubernetesPodOperator从气流在GKE / Kubernetes上部署DBT pod错误



我正在尝试使用气流1.10.10中的KubernetesPodOperator包部署自定义DBT pod

当我尝试在我的气流中运行任务时,我得到这个错误:

文件"/home/气流。local/lib/python3.6/网站/kubernetes/config/incluster_config.py",第51行,在_load_config中抛出ConfigException("服务主机/端口未设置。")

我想我已经设置了端口。下面是我的KubernetesPodOperator任务:

uk_dbt_transform_task = KubernetesPodOperator(
name="dbt-test-processor",
namespace='prod',
project_id=PROJECT_ID,
cluster_name=CLUSTER_NAME,
location='europe-west2',
startup_timeout_seconds=120,
image=IMAGE_URL,
cmds=["run"],
arguments=["-s", "TABLE_NAME"],
get_logs=True,
image_pull_policy="Always",
ports=9090, <---- here is the port I attached
hostnetwork=False, <----- the host network is false as a default per the docs on airflow's site.
is_delete_operator_pod=False, 
config_file=KUBE_CONFIG,
service_account_name=SERVICE_ACCOUNT,
dag=dag,
task_id='uk_dbt_transform_task'
)

我已经将任务中的变量设置为'9090',与我在Dockerfile和hostnetwork中暴露的相同。

这是我用来构建容器的docker文件,它与DBT给出的完全相同,但有一个端口暴露:

# Top level build args
ARG build_for=linux/amd64

# FROM python:3.9.16-bullseye
FROM --platform=$build_for python:3.9.16-bullseye as base

ARG dbt_core_ref=dbt-core@v1.4.0b1
ARG dbt_bigquery_ref=dbt-bigquery@v1.4.0b1
# System setup
RUN apt-get update 
&& apt-get dist-upgrade -y 
&& apt-get install -y --no-install-recommends 
git 
ssh-client 
software-properties-common 
make 
build-essential 
ca-certificates 
libpq-dev 
&& apt-get clean 
&& rm -rf 
/var/lib/apt/lists/* 
/tmp/* 
/var/tmp/*
# Env vars
ENV PYTHONIOENCODING=utf-8
ENV LANG=C.UTF-8
# Update python
RUN python -m pip install --upgrade pip setuptools wheel --no-cache-dir
# Set docker basics
WORKDIR /usr/app/dbt/
VOLUME /usr/app
COPY . /usr/app/dbt/
ENTRYPOINT ["dbt"]
##
# dbt-core
##
FROM base as dbt-core
RUN python -m pip install --no-cache-dir "git+https://github.com/dbt-labs/${dbt_core_ref}#egg=dbt-core&subdirectory=core"
##
# dbt-bigquery
##
FROM base as dbt-bigquery
RUN python -m pip install --no-cache-dir "git+https://github.com/dbt-labs/${dbt_bigquery_ref}#egg=dbt-bigquery"
# Expose port for dbt docs
EXPOSE 9090

请帮帮我,我不知道我哪里错了。

正如@Paddy Alton提到的,您可以使用GKE操作符。

GKE操作员在一个特定的集群中运行pod,它可以是一个与自己的环境无关的单独集群

创建Google Kubernetes引擎集群的DAGGKECreateClusterOperator,使用GKEStartPodOperator和,然后将其删除GKEDeleteClusterOperator之后:

  1. 最小配置:只设置所需的参数。

  2. 模板配置:使用可以使用Jinja模板的参数。

  3. Pod亲和性配置:限制可调度的节点。

  4. Full configuration:包含所有配置

注意-使用最新版本的Cloud Composer

也检查这个Github链接来解决这个错误。

最新更新