# Airflow 배포 ## 1. 배포 방법 ### 1) 배포시 주의 사항 - 배포전 airflow dag를 저장할 git 리포지토리가 생성 필요 - ### 2) 배포 방법 ``` sh git clone https://github.com/paasup/dip-catalog.git cd charts/flowise helm upgrade airflow ./ -f custom-values.yaml --install -n airflow --create-namespace ``` ## 2.custom-values.yaml 설명 - custom-values.yaml에 정의된 값에 대한 설명이다. ### 1) Pod 설정 | Name | 설명 | 기본값 | | ---------------------- | ------------------------------------------------------------ | ------ | | `defaultAirflowRepository` | 오프라인 설치 시에 설정. 내부 저장소 타겟으로 변경 | `"apache/airflow"` | | `defaultAirflowTag` | 이미지 태그 설정 | '0.5.4' | ### 2) Git Sync 설정 - Dag ``` yaml dags: gitSync: enabled: true # dag가 저장될 gitea의 repository url, k8s 서비스로 설정한다. repo: http://gitea-http.platform.svc.cluster.local:3000/dip/airflow-dags.git branch: master rev: HEAD depth: 1 subPath: "" credentialsSecret: git-credentials env: - name: GIT_SSL_NO_VERIFY value: "true" # git 리포지토리의 clone 및 pull 실행 시 사용할 username, password 설정. # 실행하는 git 이미지의 버전은 v3, v4 2가지가 있고 사용하는 환경변수가 다름. # 2가지 설정을 하지 않을 시 동작 에러 발생. extraSecrets: git-credentials: data: | GIT_SYNC_USERNAME: c3Vkb3VzZXI= GITSYNC_USERNAME: c3Vkb3VzZXI= GIT_SYNC_PASSWORD: UGFhc2FkbTEyMzQh GITSYNC_PASSWORD: UGFhc2FkbTEyMzQh ``` ### 3) Volume 설정 ``` yaml # Dag의 저장 공간 크기 설정 dags: persistence: enabled: true size: 5Gi # airflow의 dag 동작시 생성되는 log의 저장 공간 크기 설정 logs: persistence: enabled: true size: 5Gi ``` ### 3) Ingress 설정 #### 3.1) tls 시크릿 직접 생성 - flowise에서 ingress 사용을 위해서는 다음과 같이 설정할 수 있다. ``` yaml ingress: web: enabled: true hosts: - name: "airflow.example.org" tls: enabled: true secretName: "airflow-tls" ``` - ingress 사용을 위해서는 인증서를 secret으로 제공해야한다. 로컬 파일을 이용해 secret을 생성하는 방법은 다음과 같다. ``` sh kubectl create secret tls airflow-tls --cert= --key= -n ``` #### 3.2) cert-manager를 이용한 자동 생성 - cert manager를 통해 인증서 자동 생성 시 `custom-values.yaml` 수정한다. - `ingress.web.annotations.cert-manager.io/cluster-issuer`에 미리 배포된 Cluster Issuer의 이름으로 변경한다. 그리고 ff ``` yaml ingress: web: enabled: true annotations: cert-manager.io/issuer: "root-ca-issuer" kubernetes.io/ingress.class: kong konghq.com/protocols: https konghq.com/https-redirect-status-code: "301" hosts: - name: "airflow.example.org" tls: enabled: true secretName: "airflow-tls" ``` ### 4) Postgresql 설정 - 내장 bitnami postgresql 서브차트 대신, `cnpg-cluster`(전용 인스턴스)를 외부 DB로 사용한다. - **사전 조건**: `cloudnative-pg` operator(`manifests/helm/cloudnative-pg/0.29.0`)가 클러스터에 먼저 설치되어 있어야 한다. - **배포 순서** ``` sh # 1) airflow용 DB 계정 시크릿 생성 (아래 password는 metadataConnection.pass와 동일해야 한다) kubectl create secret generic airflow-db-app-secret \ --from-literal=username=airflow --from-literal=password=airflow -n airflow # 2) 전용 cnpg-cluster 배포 helm upgrade airflow-db manifests/helm/cnpg-cluster/1.0.0 \ -f manifests/helm/cnpg-cluster/1.0.0/custom-values.yaml \ -f manifests/applicationset/airflow/1.16.0/airflow-db-values.yaml \ --install -n airflow # 3) airflow 배포 (기존 배포 방법과 동일) helm upgrade airflow ./ -f custom-values.yaml --install -n airflow --create-namespace ``` - ArgoCD로 배포한다면 `manifests/applicationset/airflow/1.16.0/`의 ApplicationSet을 쓴다 — `airflow-db`(syncWave 0) → `airflow`(syncWave 1) 순서로 자동 배포된다. 자세한 내용은 해당 디렉토리의 `README.md` 참고. - custom-values.yaml ``` yaml postgresql: enabled: false data: metadataConnection: user: airflow pass: airflow # 위 시크릿 생성 시 사용한 password와 동일해야 한다 protocol: postgresql host: airflow-db-rw # cnpg-cluster 릴리스명이 airflow-db일 때의 rw 서비스명 port: 5432 db: airflow sslmode: disable ``` - 참고: `manifests/applicationset/airflow/1.16.0/airflow-db-values.yaml`