삽질/Airflow

airflow k8s(helm) pip 패키지 설치 추가

maengis 2023. 5. 24. 19:58

helm으로 airflow 설치 후 dag 작성하고 테스트를 하려는데 kafka-python을 설치해야 했다.

예제로 mariadb > kafka로 데이터를 넣는 걸 작성하려고 했는데, 문제는 이걸 비개발자가 chatgpt만 사용해서 dag을 작성할 수 있게 하는 게 목표라서 미리 PyPI인 kafka-python을 설치해야 했다.

 

values.yaml에 있는 extraPipPackages를 사용 했는데 설치가 안 됐다.

https://github.com/airflow-helm/charts/blob/main/charts/airflow/docs/faq/configuration/extra-python-packages.md

 

GitHub - airflow-helm/charts: The User-Community Airflow Helm Chart is the standard way to deploy Apache Airflow on Kubernetes w

The User-Community Airflow Helm Chart is the standard way to deploy Apache Airflow on Kubernetes with Helm. Originally created in 2017, it has since helped thousands of companies create production-...

github.com

 

검색을 하면서 알게 된 사실

https://github.com/apache/airflow/discussions/20689

 

installing pip packages on airflow image/helm chart? · apache/airflow · Discussion #20689

I am looking to add snowflake operator to airflow following this tutorial here. I have a docker file and I am using a helm chart to install airflow. For this, I have to add few python packages and ...

github.com

도커파일에 추가하는 게 맞다고 한다.

 

https://airflow.apache.org/docs/helm-chart/stable/quick-start.html

 

Quick start with kind — helm-chart Documentation

 

airflow.apache.org

 

위 내용대로 하면서 문제가 된 건, kind가 안 됨... ㅠㅠ

회사 도커이미지 저장소에 대한 정보가 없어서 없는줄 알았는데, 일정이 얼마 안 남아서 그런가 마치 주마등처럼 누군가의 문서에서 회사 도커이미지 저장소를 본 기억이 있어서 values.yaml에서 도커이미지 저장소를 쓰는 방법으로 하기로 함.

 

일단 도커 설치 후 확인

yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
yum-config-manager --enable docker-ce-nightly
yum -y install docker-ce docker-ce-cli containerd.io
 
systemctl start docker
systemctl enable docker
 
systemctl status docker

 

도커 파일 작성

cat <<EOM > Dockerfile
FROM apache/airflow
RUN pip install --no-cache-dir kafka-python
EOM

 

빌드 하고 저장소에 올리기

docker build --pull --tag airflow-qa-pip-image:0.0.1 .
docker tag airflow-qa-pip-image:0.0.1 {저장소 주소}/airflow-qa-pip-image:0.0.1
docker push {저장소 주소}/airflow-qa-pip-image:0.0.1

 

values.yaml에 저장소 주소 반영

images:
  airflow:
    repository: {저장소 주소}/airflow-qa-pip-image
    tag: 0.0.1

 

values.yaml 적용

helm upgrade --install airflow apache-airflow/airflow -n airflow -f values.yaml

 

PythonVirtualenvOperator 관련해서 안내를 하는 게 낫지 않을까 싶긴 하다.

https://airflow.apache.org/docs/apache-airflow/2.5.3/howto/operator/python.html#pythonvirtualenvoperator

 

PythonOperator — Airflow Documentation

 

airflow.apache.org

 

반응형