Home > Software design >  How to import Secret in airflow?
How to import Secret in airflow?

Time:05-13

I was trying to use a module in airflow called Secrets to pass secrets to KubernetesOperator in Airflow. It should be imported as from airflow.contrib.kubernetes.secret import Secret

But I'm getting an error ModuleNotFoundError: No module named 'airflow.contrib.kubernetes'

I have tried to install apache-airflow kubernetes package pip install apache-airflow[kubernetes] but this did not help.

CodePudding user response:

The import is:

from airflow.kubernetes.secret import Secret

Note that the Secret class in Airflow can only reference secrets already exist in Kubernetes.

If you are looking to "pass" = generate secrets then it won't work. You first must create them in Kubernetes. You can do this by using create_namespaced_secret of the Kubernetes Python SDK - see Using create_namespaced_secret API in Kubernetes Python client

  • Related