How can I set dns config in airflow kuber pod operator?

4/21/2021

I am scheduling some tasks on airflow using KubernetesPodOperator; I want to deploy my pod with custom dns configuration:

spec:
  dnsPolicy: "None"
  dnsConfig:
    nameservers:
    - 10.10.10.10

But the problem is I found no way to set dns config and nameserver KubernetesPodOperator. So does anybody have a solution to submit a task on k8s in airflow with custom dns config?

-- Mohsen Eimany
airflow
kube-dns
kubernetes
kubernetespodoperator

1 Answer

4/21/2021

Airflow expose the Kubernetes Pod object API so your configuration should work As listed dnsConfig in the Pod Spec.

apiVersion: v1
kind: Pod
metadata:
  namespace: default
  name: dns-example
spec:
  containers:
    - name: test
      image: nginx
  dnsPolicy: "None"
  dnsConfig:
    nameservers:
      - 10.10.10.10

Make sure you are importing the updated version of KubernetesPodOperator from providers.

For Airflow< 2.0.0: use backport providers.

For Airflow>= 2.0.0 use providers.

-- Elad Kalif
Source: StackOverflow