Apache Airflow Kubernetes运算符允许您在Kubernetes集群中执行任务和DAG。以下是一些可用参数的示例:
in_cluster
: 这个参数确定运算符是否运行在Kubernetes集群内部。可以设置为False,以将运算符与集群外部的Kubernetes API交互。from airflow import DAG
from datetime import datetime, timedelta
from airflow.contrib.operators.kubernetes_pod_operator import KubernetesPodOperator
default_args = {
'owner': 'airflow',
'depends_on_past': False,
'start_date': datetime(2020, 1, 1),
'email_on_failure': False,
'email_on_retry': False,
'retries': 1,
'retry_delay': timedelta(minutes=5),
}
dag = DAG(
'kubernetes_sample',
default_args=default_args,
catchup=False,
schedule_interval='@once',
)
with dag:
k = KubernetesPodOperator(
namespace='default',
image="ubuntu:16.04",
cmds=["bash", "-cx"],
arguments=["echo", "10"],
labels={"foo": "bar"},
name="airflow-test-pod",
in_cluster=False, # set to True if running inside a kubernetes cluster
task_id="task",
get_logs=True
)
k
config_file
: 指向一个Kubernetes配置文件路径的字符串,此文件用于设置Kubernetes API的访问凭据等信息。from airflow import DAG
from datetime import datetime, timedelta
from airflow.contrib.operators.kubernetes_pod_operator import KubernetesPodOperator
default_args = {
'owner': 'airflow',
'depends_on_past': False,
'start_date': datetime(2020, 1, 1),
'email_on_failure': False,
'email_on_retry': False,
'retries': 1,
'retry_delay': timedelta(minutes=5),
}
dag = DAG(
'kubernetes_sample',
default_args=default_args,
catchup=False,
schedule_interval='@once',
)
with dag:
k = KubernetesPodOperator(
namespace='default',
image="ubuntu:16.04",
cmds=["bash", "-cx"],
arguments=["echo", "10"],
labels={"foo": "bar"},
name="airflow-test-pod",
config_file='/path/to/your/kubeconfig', # set to path to your kubeconfig file
task_id="task",
get_logs=True
)
k
config
: 一个Kubernetes客