Byzer on K8S 部署 - 微軟云

Byzer 是一個云原生的應(yīng)用,本文以一個例子介紹在微軟云(中國區(qū))部署 Byzer。例子要求

  • AKS 最少有 24 GB 內(nèi)存,6 核 CPU
  • 1 個 Azure Database for MySQL
  • 1 個 Azure Blob Container
  • 1 臺安裝了 Ubuntu 20.04 的機器

完成后,用戶能編輯,執(zhí)行,調(diào)度 Byzer 任務(wù)。個人玩家可以使用微軟云提供的免費額度創(chuàng)建上述資源,過程請參考微軟云文檔。

客戶機配置

云上資源到位后,我們開始第一步,配置 Ubuntu 20.04 客戶機,安裝 kubectl 1.23.0 helm 3.8.1 az ( azure 命令行), 配置 AKS 集群的連接信息。

## 下載 kubectl 1.23.0
curl -LO https://dl.k8s.io/release/v1.23.0/bin/linux/amd64/kubectl
## 拷貝 kubectl 至可執(zhí)行文件目錄
chmod +x kubectl
sudo install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl

輸入 kubectl ,打印幫助信息,表示安裝成功。

安裝 helm 至 /work/server 目錄

wget https://get.helm.sh/helm-v3.8.1-linux-amd64.tar.gz
tar -xf helm-v3.8.1-linux-amd64.tar.gz -C /work/server/
cd /work/server
mv linux-amd64/ helm

編輯 ~/.bashrc 文件 /work/server/helm/ 加入 $PATH。 執(zhí)行 helm 打印幫助信息,表示安裝成功。接下來,使用 apt 安裝 az

sudo apt update
sudo apt install -y azure-cli

執(zhí)行下面命令配置 AKS 連接信息。az login 時需要登錄 azure web頁面二次認證。subscription-id 是你的微軟云訂閱 id , resource-group 是微軟云資源組, aks-name 為 aks 集群名稱,都可以在 portal.azure.cn 得到。

az cloud set --name AzureChinaCloud
az login
az account set --subscription <subscription-id>
az aks get-credentials --resource-group <resource-group> --name <aks-name>

執(zhí)行 kubectl cluster-info 并檢查集群連接信息。

創(chuàng)建 K8S namespace 和權(quán)限

K8S 一般使用 namespace 隔離多個部門/業(yè)務(wù)/應(yīng)用。管理員可以為各個 namespace 設(shè)置資源隔離;不同 namespace 可以存在同名的資源。我們使用命令 kubectl create namespace byzer-qa ; 并設(shè)置為默認 namespace。

kubectl config set-context --current --namespace=byzer-qa

ServiceAccount Role RoleBinding 是 K8S 重要概念,用于權(quán)限管控。在這里,使用 byzer 這個 serviceaccount 部署;并綁定到 byzer-admin role。byzer-admin 具有較高權(quán)限;能創(chuàng)建各類 K8S 對象。下面是創(chuàng)建這 3 者的命令和 yaml 。

kubectl create serviceaccount byzer 

使用 kubectl apply命令創(chuàng)建 role

apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
  name: byzer-admin
rules:
- apiGroups: [""] 
  resources: ["pods","deployments", "replicas", "secrets", "configmaps","services","ingresses"]
  verbs: ["*"]

綁定 Service Account byzer 到 role byzer-admin

kubectl create rolebinding byer-role-binding --role=byzer-admin --serviceaccount=byzer-qa:byzer --namespace=byzer-qa

Byzer-lang 部署

完成基礎(chǔ)配置后,開始部署 Byzer-lang 2.2.2 Byzer-notebook 1.1.1DolphinScheduler 1.3.9 3 個應(yīng)用。

Byzer-lang 是 Byzer 的執(zhí)行引擎,不對公網(wǎng)暴露, 數(shù)據(jù)存儲在 Azure Blob。

Byzer 團隊提供的 helm chart, 內(nèi)部在微軟云上部署成功。 helm chart 簡化了 K8S 部署, 不需要寫 deployment, service configmap yaml 文件;修改 values.yaml 再部署即可。下面是詳細部署步驟。

下載 helm chart

wget https://download.byzer.org/k8s-helm/byzer-lang/2.2.2/byzer-lang-helm-charts-2.2.2.tgz
# 解壓至 /work/server
tar -xf helm_chart_byzer-lang-2.2.2.tgz -C /work/server
cd /work/server/byzer-lang

helm chart 的 templates 目錄包含 deployment service configmap 等模板,部署時,使用 values.yaml 文件渲染模板,并部署至 K8S。

修改配置

按照你的實際情況,修改 values.yaml 中以下配置。注意,CPU 內(nèi)存不要超過 AKS 每個 worker 節(jié)點可分配數(shù),否則 Pod 無法啟動。

fs.defaultFS
預(yù)先申請的 Azure Blob 地址,Byzer-lang 基于 HDFS API 訪問它。格式為 wasb://<container_name>@<account_name>.blob.core.chinacloudapi.cn/ 。core.chinacloudapi.cn 表示中國區(qū)微軟云,其他區(qū)域有不同地址。Azure Blob jar 已經(jīng)集成在 byzer 鏡像,且經(jīng)過測試。

clusterUrl
Base 64 編碼的AKS APIServer 地址??梢栽?AKS overview 頁面查到,例如 https://hello-k8s-dns.hcp.chinanorth2.cx.prod.service.azk8s.cn:443

image.png

storage.SecretKey
Base 64 編碼的 Azure Blob Secret Key; 可以在 portal.azure.cn 的頁面查到.

image.png

spark.driver.memory
Driver 內(nèi)存,例如 8g;由于 Byzer Driver 負擔(dān)較重,建議比 Executor 大。

spark.driver.cores
Driver CPU 核數(shù)

spark.driver.maxResultSize
Driver 端結(jié)果集上限,例如 2g

spark.executor.memory
Executor 內(nèi)存,例如 4g

spark.executor.cores
Executor CPU 核數(shù),例如 1

spark.executor.instances
Executor 數(shù)量,例如 2

streaming.datalake.path
Azure Blob 的 DeltaLake 目錄,例如 /byzer/_delta . 無需事先創(chuàng)建。

helm install

執(zhí)行 helm install byzer-lang . 部署 。 byzer-lang 是 helm release 名稱, . 表示使用當(dāng)前目錄 helm chart。執(zhí)行后,可以在 AKS 頁面看到新的 deployment, pod, service。 執(zhí)行命令 kubectl get pod -l app.kubernetes.io/instance=byzer-lang 查看 Driver pod

NAME                                     READY   STATUS    RESTARTS   AGE
byzer-lang-deployment-686f555dc8-l7x99   1/1     Running   0          2d5h

使用 kubectl 查看 Byzer-lang log

kubectl logs $(kubectl get pod -l app.kubernetes.io/name=byzer-lang -o name | head -1)

Nginx-Ingress Controller 部署

這里,我們?yōu)?AKS 申請一個 公網(wǎng) IP,創(chuàng)建 Nginx-ingress Pod,為 DolphinScheduler 和 Byzer-notebook 暴露公網(wǎng)服務(wù)。由于我國特殊國情,無法拉取 gcr.io 上的 nginx-ingress yaml 文件。Byzer 團隊維護的 nginx-ingress helm chart 使用微軟云中國區(qū)的 repo 安裝 nginx-ingress。

## 下載 Byzer 團隊維護的 nginx-ingress 。指定鏡像源為 azure cn 。
wget http://download.byzer.org/k8s-helm/nginx-ingress/1.41.3/nginx-ingress-1.41.3.tgz
tar -xf nginx-ingress-1.41.3.tgz
cd nginx-ingress
## 部署 nginx-ingress
helm install nginx-ingress .

部署后,使用命令 kubectl get pod -l app=nginx-ingress 查看

kubectl get pod -l app=nginx-ingress
NAME                                                        READY   STATUS    RESTARTS   AGE
nginx-ingress-1648861535-controller-6f857ccb9-rnhz9         1/1     Running   0          24d
nginx-ingress-1648861535-default-backend-77bd68c866-n6kq2   1/1     Running   0          24d

DolphinScheduler 部署

DolphinScheduler 1.3.9 作為 Byzer-notebook 的調(diào)度引擎。這個例子僅部署 1 個 zookeeper 實例 ;生產(chǎn)環(huán)境部署至少 3 個 Zookeeper 實例,且分布在不同 K8S worker node。

我們使用 Byzer 團隊維護的 helm chart 部署 DolphinScheduler , 因為它集成了 MySQL JDBC驅(qū)動。

下載 DolphinScheduler helm chart

## 下載
wget http://download.byzer.org/k8s-helm/dolphinscheduler/1.3.0/dolphinscheduler-1.3.0.tgz
## 解壓縮至 /work/server
tar -xf dolphinscheduler-1.3.0.tgz -C /work/server
cd /work/server/dolphinscheduler

創(chuàng)建 DolphinScheduler 數(shù)據(jù)庫表

登錄你的微軟云 MySQL,執(zhí)行語句創(chuàng)建數(shù)據(jù)庫

CREATE DATABASE dolphinscheduler DEFAULT CHARACTER SET  utf8mb4;
-- {mysql_username}  是 values.yaml 配置的 MySQL 用戶,
GRANT ALL PRIVILEGES ON dolphinscheduler.* TO '{mysql_username}'@'%';

然后下載 DolphinScheduler 1.3.9 安裝包,配置 MySQL 連接信息 后執(zhí)行腳本創(chuàng)建 MySQL 表。

## 下載 DolphinScheduler 1.3.9
wget --no-check-certificate https://dlcdn.apache.org/dolphinscheduler/1.3.9/apache-dolphinscheduler-1.3.9-bin.tar.gz
tar -xf apache-dolphinscheduler-1.3.9-bin.tar.gz -C /work/server
cd /work/server/apache-dolphinscheduler-1.3.9-bin/

## 下載 MySQL JDBC,放到 lib 目錄
wget https://repo1.maven.org/maven2/mysql/mysql-connector-java/5.1.47/mysql-connector-java-5.1.47.jar \
--directory-prefix /work/server/apache-dolphinscheduler-1.3.9-bin/lib/

# 編輯數(shù)據(jù)源配置文件
vi conf/datasource.properties
## 注掉 PG 設(shè)置
# spring.datasource.driver-class-name=org.postgresql.Driver
# spring.datasource.url=jdbc:postgresql://localhost:5432/dolphinscheduler
## 設(shè)置 MySQL 連接信息
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
# 需要修改 ip 和端口
spring.datasource.url=jdbc:mysql://xxx:3306/dolphinscheduler?useUnicode=true&characterEncoding=UTF-8&allowMultiQueries=true    
# 修改為你的 mysql_username 
spring.datasource.username=xxx
# 修改為實際 MySQL 密碼
spring.datasource.password=xxx

## 最后 wq ,保存退出

請找你的同事確認上述 MySQL 連接信息準確無誤;且當(dāng)前機器能訪問 MySQL。 請備份數(shù)據(jù)庫,再執(zhí)行 DolphinScheduler 提供的腳本,創(chuàng)建 MySQL 表。

sh script/create-dolphinscheduler.sh

Dolphinscheduler 的 MySQL 庫表創(chuàng)建后,我們修改 DolphinScheduler 配置并部署。

配置 MySQL 連接信息

首先,登錄 Azure Portal. 在 MySQL Connection Security 界面勾選 Allow access to Azure services, 允許 AKS 應(yīng)用訪問。

修改 values.yaml


postgresql:
  enabled: false

externalDatabase:
  type: "mysql"
  driver: "com.mysql.jdbc.Driver"
  host: "<your_mysql_host>"
  port: "<mysql_port>"
  username: "<mysql_username>"
  password: "<password>"
  database: "dolphinscheduler"
  params: "useUnicode=true&characterEncoding=UTF-8"

配置 DolphinScheduler Pod

根據(jù)你的需要,設(shè)置 master, worker 實例數(shù)。例子設(shè)置為最小值 1.

master: 
  podManagementPolicy: "Parallel"
  replicas: "1"

worker:
  podManagementPolicy: "Parallel"
  replicas: "1"

創(chuàng)建 DolphinScheduler Ingress 規(guī)則

我們?yōu)?DolphinScheduler 創(chuàng)建 Ingress 路由規(guī)則。由于是公網(wǎng)環(huán)境,我們設(shè)置 IP 白名單,保證安全。修改 values.yaml

ingress:
  enabled: true
  #host: "dolphinscheduler.org"
  path: "/dolphinscheduler"
  annotations:
    nginx.ingress.kubernetes.io/whitelist-source-range: 192.168.1.0/8

請修改 192.168.1.0/8 為你的源網(wǎng)段。如果你使用家庭寬帶,沒有固定 IP,無法設(shè)置 IP 白名單。請務(wù)必使用后,就關(guān)閉 Ingress rules。

helm install

執(zhí)行 helm install dolphin .,將部署 5 個 Pod, 我們執(zhí)行命令 get pod -l app.kubernetes.io/instance=dolphin 查看

kubectl get pod -l app.kubernetes.io/instance=dolphin
NAME                             READY   STATUS    RESTARTS   AGE
dolphin-alert-65c55d8b5b-j9tfj   1/1     Running   0          8d
dolphin-api-5445495cb6-gr6d2     1/1     Running   0          8d
dolphin-master-0                 1/1     Running   0          8d
dolphin-worker-0                 1/1     Running   0          8d
dolphin-zookeeper-0              1/1     Running   0          8d

創(chuàng)建 DolphinScheduler token

DolphinScheduler ingress-rules 創(chuàng)建后,登錄 Azure Portal, 選擇 你的 AKS 集群,在 Services & Ingresses 菜單,能看到 1 個 LoadBalancer 及其 公網(wǎng)IP。使用 http://<公網(wǎng)IP>/dolphinscheduler/ui/view/login/index.html 輸入賬號 admin 默認密碼 dolphinscheduler123 登錄 DolphinScheduler . 參考 DolphinScheduler Quick Start 創(chuàng)建 DolphinScheduler 用戶,token tenant。請注意,token 默認有效期較短,根據(jù)你的需求調(diào)整。記錄 token,稍后配置到 Byzer-notebook . tenant codetenant name 都填 root

image.png
image.png

image.png

Byzer-notebook 部署

Byzer-notebook 提供了交互式編程環(huán)境。我們依然使用 helm chart 部署。

創(chuàng)建 MySQL 數(shù)據(jù)庫表

CREATE DATABASE notebook DEFAULT CHARACTER SET  utf8mb4;
-- {mysql_username}  是 values.yaml 配置的 MySQL 用戶,
GRANT ALL PRIVILEGES ON notebook .* TO '{mysql_username}'@'%';

配置 Byzer-notebook

下載 helm chart ,解壓,根據(jù)你的實際情況修改 value.yaml

https://download.byzer.org/k8s-helm/byzer-notebook/1.1.1/byzer-notebook-helm-charts-1.1.1.tgz

Notebook 基本配置

配置 說明
notebook.security.key 調(diào)用 byzer-notebook API時,鑒權(quán) security key
user.home 用戶數(shù)據(jù)根目錄
mlsql.engine-url Byzer-lang HTTP 接口,建議使用 K8S 內(nèi)部域名, 格式為 http://<byzer-lang-service-name>.<namespace>:9003
mlsql.auth-client Byzer-lang 數(shù)據(jù)權(quán)限接口,默認 streaming.dsl.auth.client.DefaultConsoleClient
job.history.max-size 默認 2000 Notebook 執(zhí)行歷史保留條數(shù)
job.history.max-time 默認 30 Notebook 執(zhí)行歷史保留天數(shù)

調(diào)度配置

配置 說明
scheduler.enable 默認 false, 請改為 true
scheduler.scheduler-url DolphinScheduler URL。請使用 K8S 內(nèi)部域名,格式為 http://<dolphinscheduler-service-name>.<namespace>:12345/dolphinscheduler
scheduler.auth-token DolphinScheduler 配置的 token
scheduler.callback-url Byzer-notebook 供 DolphinScheduler 回調(diào)的接口地址, 使用 K8S 內(nèi)部域名 http://<byzer-notebook-service-name>.<namespace>:9002/

數(shù)據(jù)庫配置

配置 說明
database.port 數(shù)據(jù)庫端口,目前僅支持 MySQL 默認 3306
database.name 上一步創(chuàng)建的 數(shù)據(jù)庫名稱 notebook
database.ip 你的數(shù)據(jù)庫地址,例如 127.0.0.1,不是 jdbc 字符串
database.username 上一步創(chuàng)建的數(shù)據(jù)庫用戶
database.password 密碼

Ingress 配置

配置 說明
ingress.enabled 請改為 true ,創(chuàng)建 ingress
ingress.annotations.nginx.ingress.kubernetes.io/proxy-body-size HTTP 上傳的限制 例如 50m
ingress.annotations.nginx.ingress.kubernetes.io/whitelist-source-range IP 白名單網(wǎng)段, 例如192.168.50.0/8,10.0.0.0/8

AKS 部署 Byzer-notebook

執(zhí)行命令 helm install byzer-notebook . 將創(chuàng)建 1 Deloyment 1 個 Pod, 1 個 Service, 1 Ingress . 可以使用以下命令檢查

kubectl get service -l app.kubernetes.io/name=byzer-notebook
kubectl get pod -l app.kubernetes.io/name=byzer-notebook

校驗

瀏覽器輸入 http://<公網(wǎng)IP>/#/home , 在注冊頁面填寫 用戶名密碼注冊,并登錄。參考 官方文檔 - 工作區(qū) 創(chuàng)建一個 Notebook, 輸入代碼select 1 AS id AS output; 并執(zhí)行,應(yīng)成功結(jié)束。
再根據(jù)創(chuàng)建調(diào)度文檔 ,為 Notebook 創(chuàng)建調(diào)度。也應(yīng)能調(diào)度成功。

FAQ

DolphinScheduler 執(zhí)行任務(wù)時報錯 "there is not any tenant suitable"

tenant 是 操作系統(tǒng)賬號,DolphinScheduler 使用它執(zhí)行時任務(wù)。請檢查

  • 創(chuàng)建這個任務(wù)的用戶是否關(guān)聯(lián)tenant
  • 任務(wù)執(zhí)行隊列 Queue 是否關(guān)聯(lián) tenant

特別指出:DolphinScheduler 管理員賬戶 admin 默認沒有關(guān)聯(lián) tenant, 會報錯。由于 admin 權(quán)限太高,請不要用于執(zhí)行任務(wù)。

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容