这是因为在使用 Kubernetes Executor 的 Airflow 任务中,您不能同时使用多个 kubeconfig 选项。您可以使用以下代码示例在 Dag 中指定正确的选项:
from kubernetes import client, config
from airflow.contrib.operators import KubernetesOperator
# Load the Kubernetes configuration
config.load_kube_config()
# Build the Kubernetes client from the loaded configuration
k8s_client = client.api_client.ApiClient()
# Define the Kubernetes Operator with in-cluster configuration
in_cluster_op = KubernetesOperator(
task_id='in_cluster_op',
namespace='default',
image='nginx:latest',
cmds=["echo"],
arguments=["Hello World!"],
labels={"foo": "bar"},
in_cluster=True
)
# Define the Kubernetes Operator with the kubeconfig path
kube_config_path_op = KubernetesOperator(
task_id='kube_config_path_op',
namespace='default',
image='nginx:latest',
cmds=["echo"],
arguments=["Hello World!"],
labels={"foo": "bar"},
kube_config_path='/path/to/kubeconfig'
)
# Define the Kubernetes Operator with the kubeconfig file contents
kube_config_op = KubernetesOperator(
task_id='kube_config_op',
namespace='default',
image='nginx:latest',
cmds=["echo"],
arguments=["Hello World!"],
labels={"foo": "bar"},
kube_config=''
)
这样您就可以根据需要使用一个选项来执行 Kubernetes Dag 了。