【问题标题】:What's the difference between these approaches for scheduling tasks on Kubernetes?这些在 Kubernetes 上调度任务的方法有什么区别?
【发布时间】:2020-01-09 12:18:56
【问题描述】:

我遇到了几种在 Kubernetes pod 上调度气流任务的不同方法,但我无法弄清楚它们之间的区别是什么,以及何时我应该更喜欢一种风格而不是另一种风格。

就上下文而言,我的本地气流测试实例配置为使用 KubernetesExecutor,并且我正在本地 Kubernetes 集群上安排这些任务。

  1. 第一种风格(坦率地说,我没想到它会起作用 - 它是什么 用作基础图像?)
dag = DAG('ex1', default_args=default_args, schedule_interval=None)

# Single Operator DAG
BashOperator(
    task_id='print_date',
    bash_command='date',
    dag=dag)
  1. 第二种样式。我遇到了这个here
dag = DAG('ex2', default_args=default_args, schedule_interval=None)

# Why do you need to specify the executor when the executor is already configured via airflow.cfg?
BashOperator(
    task_id='print_date',
    bash_command='date',
    dag=dag,
    executor_config={"KubernetesExecutor": {"image": "ubuntu:1604"}})
  1. 第三种样式来自KubernetesPodOperator 这似乎是最灵活的(您可以指定任何容器,带有任何参数),所以也许这是唯一的优势?但是,考虑到我只是调用 bash 脚本或 python 脚本的场景,这与方法 1 或 2(使用 BashOperator 或 PythonOperator)有什么区别?
dag = DAG('ex3', default_args=default_args, schedule_interval=None)

KubernetesPodOperator(namespace='default',
                          image="ubuntu:1604",
                          cmds=["/bin/bash","-c"],
                          arguments=["echo hello world"],
                          labels={"foo": "bar"},
                          name="EchoInAUbuntuContainer",
                          task_id="testUbuntuEcho",
                          get_logs=True,
                          dag=dag)

【问题讨论】:

    标签: airflow


    【解决方案1】:
    1. KubernetesPodOperator 适用于您使用非 kubernetes 执行程序并希望在 Kubernetes 上运行映像的情况。
    2. 如果您选择使用KubernetesExecutor,那么BashOperatorPythonOperator 之类的操作符将被安排在Kubernetes 上(尽管如果您不指定它们则不清楚它们使用什么镜像)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-04-29
      • 2020-09-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-06-28
      相关资源
      最近更新 更多