[Airflow] git-sync 로 DAG git repository 연동하기

Woong·2025년 4월 1일
0

Apache Airflow

목록 보기
8/9

ssh key 설정

  • ssh key 로 secret 생성
    • 상대경로 불가능하므로 절대경로 사용
kubectl create secret generic git-ssh-key \
  --from-file=ssh-privatekey=$HOME/.ssh/id_rsa \
  --type=kubernetes.io/ssh-auth -n airflow
  • 생성한 ssh key 는 git 에 등록한다.
  • gitSync 를 사용하기 위해 pvc enable, gitsync enable
helm upgrade --install airflow apache-airflow/airflow \
  --set dags.persistence.enabled=true \
  --set dags.gitSync.enabled=true

secret 생성

  • ssh key 생성

ssh-keygen -t rsa -b 4096 -C "your_email@example.com"

  • Git repository 배포 키에 ssh 공개키 추가
  • 개인키 등록을 위해 base64 인코딩

base64 <my-private-ssh-key> -w 0 > temp.txt

helm chart 설치

helm repo add apache-airflow https://airflow.apache.org
helm upgrade --install airflow apache-airflow/airflow --namespace airflow --create-namespace
  • helm chart 커스텀
    • persistence 설정은 DAG 가 많지 않을 경우 false 하여도 무방

helm show values apache-airflow/airflow > airflow/value.yaml

# Git sync
dags:
  mountPath: ~
  persistence:
    annotations: {}
    enabled: false
    size: 1Gi
    storageClassName:
    accessMode: ReadWriteOnce
    existingClaim:
    subPath: ~
  gitSync:
    enabled: true

    # git repo clone url
    # ssh example: git@github.com:apache/airflow.git
    # https example: https://github.com/apache/airflow.git
    repo: git@<git 주소>:<git 프로젝트>.git
    branch: next
    rev: HEAD
    ref: next
    depth: 1
    maxFailures: 0
    # git repot 내 DAG path 지정
    subPath: "dags"

    # 위에서 생성한 secret 지정
    sshKeySecret: git-ssh-key
    period: 5s
    wait: ~
    envFrom: ~

    containerName: git-sync
    uid: 65533

    securityContext: {}

    securityContexts:
      container: {}

    containerLifecycleHooks: {}

    extraVolumeMounts: []
    env: []

    resources: {}
  • helm install
    • 수정 후 재배포할 땐 helm install 대신 helm update
helm install airflow-prod apache-airflow/airflow \
  --namespace airflow \
  --create-namespace \
  -f airflow/values.yaml

reference

0개의 댓글