K8S部署分布式調(diào)度任務(wù)Airflow
一、部署要求
Apache Airflow 已通過以下測(cè)試:
注意: MySQL 5.x 版本不能或有運(yùn)行多個(gè)調(diào)度程序的限制——請(qǐng)參閱調(diào)度程序文檔。MariaDB 未經(jīng)過測(cè)試/推薦。
注意: SQLite 用于 Airflow 測(cè)試。不要在生產(chǎn)中使用它。我們建議使用最新的 SQLite 穩(wěn)定版本進(jìn)行本地開發(fā)。
PS:本文部署 Airflow 穩(wěn)定版 2.1.4,Kubernetes使用1.20.x版本,PostgreSQL使用12.x,使用Helm Charts部署。
二、生成Helm Charts配置
PS:使用 helm 3 版本部署
- # 創(chuàng)建kubernetes airflow 命名空間
 - $ kubectl create namespace airflow
 - # 添加 airflow charts 倉庫源
 - $ helm repo add apache-airflow https://airflow.apache.org
 - # 更新 aiarflow 源
 - $ helm repo update
 - # 查看 airflow charts 所有版本(這里選擇部署charts 1.2.0,也就是airflow 2.1.4)
 - $ helm search repo apache-airflow/airflow -l
 - NAME CHART VERSION APP VERSION DESCRIPTION
 - apache-airflow/airflow 1.3.0 2.2.1 The official Helm chart to deploy Apache Airflo...
 - apache-airflow/airflow 1.2.0 2.1.4 The official Helm chart to deploy Apache Airflo...
 - apache-airflow/airflow 1.1.0 2.1.2 The official Helm chart to deploy Apache Airflo...
 - apache-airflow/airflow 1.0.0 2.0.2 Helm chart to deploy Apache Airflow, a platform...
 - # 導(dǎo)出 airflow charts values.yaml 文件
 - $ helm show values apache-airflow/airflow --version 1.2.0 > airflow_1.2.4_values.yaml
 
三、修改airflow配置
3.1 配置持續(xù)存儲(chǔ) StorageClass
PS: 使用阿里云NAS極速存儲(chǔ)
- # 編輯 StorageClass 文件
 - $ vim alicloud-nas-airflow-test.yaml
 - apiVersion: storage.k8s.io/v1
 - kind: StorageClass
 - metadata:
 - name: alicloud-nas-airflow-test
 - mountOptions:
 - - nolock,tcp,noresvport
 - - vers=3
 - parameters:
 - volumeAs: subpath
 - server: "xxxxx.cn-beijing.extreme.nas.aliyuncs.com:/share/airflow/"
 - provisioner: nasplugin.csi.alibabacloud.com
 - reclaimPolicy: Retain
 - # 應(yīng)用到K8S中
 - $ kubectl apply -f alicloud-nas-airflow-test.yaml
 
3.2 配置 airflow Dags 存儲(chǔ)倉庫 gitSshKey
- # 編輯 airflow-ssh-secret.yaml 文件,首先需要把shh公鑰添加到git項(xiàng)目倉庫中
 - $ vim airflow-ssh-secret.yaml
 - apiVersion: v1
 - kind: Secret
 - metadata:
 - name: airflow-ssh-secret
 - namespace: airflow
 - data:
 - # key needs to be gitSshKey
 - gitSshKey: "ssh私鑰,base64"
 - # 應(yīng)用到K8S中
 - $ kubectl apply -f airflow-ssh-secret.yaml
 
3.3 Docker 部署 PostgreSQL 12
- # 創(chuàng)建 postgresql 存儲(chǔ)目錄
 - $ mkdir /data/postgresql_data
 - # 創(chuàng)建啟動(dòng)文件
 - $ vim docker-compose.yaml
 - version: "3"
 - services:
 - airflow-postgres:
 - image: postgres:12
 - restart: always
 - container_name: airflow-postgres
 - environment:
 - TZ: Asia/Shanghai
 - POSTGRES_USER: airflow
 - POSTGRES_PASSWORD: Airflow123
 - volumes:
 - - /data/postgresql_data:/var/lib/postgresql/data
 - ports:
 - - "5432:5432"
 - # 啟動(dòng) postgresql docker
 - $ docker-compose up -d
 
3.4 修改 airflow_1.2.4_values.yaml 配置
PS:本文 airflow_1.2.4_values.yaml 配置文件需要三個(gè)pvc,服務(wù)分別是 redis、worker(只部署1個(gè)worker,可以部署多個(gè)worker)、dags
因配置文件太長(zhǎng),不具體貼出,具體內(nèi)容請(qǐng)參考下面鏈接:
https://github.com/yangpeng14/DevOps/blob/master/config_dir/airflow_1.2.4_values.yaml
四、部署 Airfolw
- # 第一次部署 Airflow
 - $ helm install airflow apache-airflow/airflow --namespace airflow --version 1.2.0 -f airflow_1.2.4_values.yaml
 - # 以后如果要修改airflow配置,請(qǐng)使用下面命令
 - $ helm upgrade --install airflow apache-airflow/airflow --namespace airflow --version 1.2.0 -f airflow_1.2.4_values.yaml
 
五、配置 Airflow Ingress Nginx 訪問入口
- # 生成 ingress nginx 配置文件
 - $ vim airflow-ingress.yaml
 - apiVersion: networking.k8s.io/v1
 - kind: Ingress
 - metadata:
 - name: airflow
 - namespace: airflow
 - annotations:
 - kubernetes.io/ingress.class: nginx
 - nginx.ingress.kubernetes.io/ssl-redirect: "false"
 - nginx.ingress.kubernetes.io/proxy-connect-timeout: "60"
 - nginx.ingress.kubernetes.io/proxy-read-timeout: "60"
 - nginx.ingress.kubernetes.io/proxy-send-timeout: "60"
 - spec:
 - rules:
 - - host: "airflow.example.com"
 - http:
 - paths:
 - - path: /
 - pathType: Prefix
 - backend:
 - service:
 - name: airflow-webserver
 - port:
 - number: 8080
 - # 應(yīng)用到K8S中
 - $ kubectl apply -f airflow-ingress.yaml
 
六、參考鏈接
1、https://github.com/apache/airflow/tree/2.1.4
2、https://airflow.apache.org/docs/helm-chart/1.2.0/index.html
















 
 
 














 
 
 
 