4

海豚调度在 Kubernetes 体系中的技术实战

 2 years ago
source link: https://www.infoq.cn/article/UXfpYzpT3MBbWV9tlSpR
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

海豚调度在 Kubernetes 体系中的技术实战

  • 2022 年 2 月 22 日
  • 本文字数:6130 字

    阅读完需:约 20 分钟

海豚调度在 Kubernetes 体系中的技术实战

海豚调度是当前非常优秀的分布式易扩展的可视化工作流任务调度平台。

基于笔者所在公司业务的特性,阐述我们使用 Kubernetes 作为海豚调度的技术底座的原因:

  • 各类独立部署项目,需要快速建立开发环境和生产环境;

  • 项目环境互联网访问受限,服务器只能使用离线的安装方式;

  • 尽可能统一的安装配置的信息,减少多个项目配置的异常;

  • 与对象存储技术的结合,统一非结构化数据的技术;

  • 便捷的监控体系,与现有监控集成;

  • 多种调度器的混合使用;

  • 全自动的资源调整能力;

  • 快速的自愈能力;

本文的案例都是基于海豚调度 1.3.9 版本为基础。Hadoop

基于 helm 工具的自动化高效部署方式

首先,我们介绍基于官网提供的 helm 的安装方式。Helm 是查找、分享和使用软件构建 Kubernetes 的最优方式。也是云原生 CNCF 的毕业项目之一。

海豚的官网和 GitHub 上有非常详细的配置文件和案例。这里我们重点介绍一些社区中经常出现的咨询和问题。

官网文档地址 https://dolphinscheduler.apache.org/zh-cn/docs/1.3.9/user_doc/Kubernetes-deployment.html

GitHub 文件夹地址 https://GitHub.com/apache/dolphinscheduler/tree/1.3.9-release/docker/Kubernetes/dolphinscheduler

  • 在 value.yaml 文件中修改镜像,以实现离线安装(air-gap install);

  image:    repository: "apache/dolphinscheduler"    tag: "1.3.9"    pullPolicy: "IfNotPresent"

针对公司内部安装好的 harbor,或者其他公有云的私仓,进行 pull,tag,以及 push。这里我们假定私仓地址是 harbor.abc.com,你所在构建镜像的主机已经进行了 docker login harbor.abc.com, 且已经建立和授权私仓下面新建 apache 项目。

执行 shell 命令

  docker pull apache/dolphinscheduler:1.3.9  dock tag apache/dolphinscheduler:1.3.9 harbor.abc.com/apache/dolphinscheduler:1.3.9  docker push apache/dolphinscheduler:1.3.9

再替换 value 文件中的镜像信息,这里我们推荐使用 Always 的方式拉取镜像,生产环境中尽量每次去检查是否是最新的镜像内容,保证软件制品的正确性。此外,很多同学会把 tag 写成 latest(制作镜像不写 tag 信息,这样在生产环境非常危险,任何人 push 了镜像,就相当于改变了 latest 的 tag 的镜像,而且也无法判断 latest 是什么版本,所以建议要明确每次发版的 tag,并且使用 Always。

  image:    repository: "harbor.abc.com/apache/dolphinscheduler"    tag: "1.3.9"    pullPolicy: "Always"GitHub

https://GitHub.com/apache/dolphinscheduler/tree/1.3.9-release/docker/Kubernetes/dolphinscheduler 整个目录 copy 到可以执行 helm 命令的主机,然后按照官网执行

  kubectl create ns ds139Git   MySQL install dolphinscheduler . -n ds139

即可实现离线安装。

  • 集成 DataX MySQL Oracle 客户端组件,首先下载以下组件

  • https://repo1.maven.org/maven2/MySQL/MySQL-connector-java/5.1.49/MySQL-connector-java-5.1.49.jar

  • https://repo1.maven.org/maven2/com/Oracle/database/jdbc/ojdbc8/

  • https://GitHub.com/alibaba/DataX/blob/master/userGuid.md 根据提示进行编译构建,文件包位于 {DataX_source_code_home}/target/DataX/DataX/

  • 基于以上 plugin 组件新建 dockerfile,基础镜像可以使用已经 push 到私仓的镜像。

  FROM harbor.abc.com/apache/dolphinscheduler:1.3.9  COPY *.jar /opt/dolphinscheduler/lib/  RUN mkdir -p /opt/soft/DataX  COPY DataX /opt/soft/DataX

保存 dockerfile,执行 shell 命令

  docker build -t harbor.abc.com/apache/dolphinscheduler:1.3.9-MySQL-Oracle-DataX .  #不要忘记最后一个点  docker push harbor.abc.com/apache/dolphinscheduler:1.3.9-MySQL-Oracle-DataX

修改 value 文件

  image:    repository: "harbor.abc.com/apache/dolphinscheduler"    tag: "1.3.9-MySQL-Oracle-DataX"    pullPolicy: "Always"

执行 helm install dolphinscheduler . -n ds139,或者执行 helm upgrade dolphinscheduler -n ds139,也可以先 helm uninstall dolphinscheduler -n ds139,再执行 helm install dolphinscheduler . -n ds139。

  • 通常生产环境建议使用独立外置 postgresql 作为管理数据库,并且使用独立安装的 zookeeper 环境(本案例使用了 zookeeper operator https://GitHub.com/pravega/zookeeper-operator,与海豚调度在同一个 Kubernetes 集群中)。

  ## If not exists external database, by default, Dolphinscheduler's database will use it.  postgresql:    enabled: false    postgresqlUsername: "root"    postgresqlPassword: "root"    postgresqlDatabase: "dolphinscheduler"    persistence:      enabled: false      size: "20Gi"      storageClass: "-"  ## If exists external database, and set postgresql.enable value to false.  ## external database will be used, otherwise Dolphinscheduler's database will be used.  externalDatabase:    type: "postgresql"    driver: "org.postgresql.Driver"    host: "192.168.1.100"    port: "5432"    username: "admin"    password: "password"    database: "dolphinscheduler"    params: "characterEncoding=utf8"  ## If not exists external zookeeper, by default, Dolphinscheduler's zookeeper will use it.  zookeeper:    enabled: false    fourlwCommandsWhitelist: "srvr,ruok,wchs,cons"    persistence:      enabled: false      size: "20Gi"      storageClass: "storage-nfs"    zookeeperRoot: "/dolphinscheduler"  ## If exists external zookeeper, and set zookeeper.enable value to false.  ## If zookeeper.enable is false, Dolphinscheduler's zookeeper will use it.  externalZookeeper:    zookeeperQuorum: "zookeeper-0.zookeeper-headless.zookeeper.svc.cluster.local:2181,zookeeper-1.zookeeper-headless.zookeeper.svc.cluster.local:2181,zookeeper-2.zookeeper-headless.zookeeper.svc.cluster.local:2181"    zookeeperRoot: "/dolphinscheduler"

基于 argo-cd 的 Gitops 部署方式

argo-cd 是基于 Kubernetes 的声明式 Gitops 持续交付工具。argo-cd 是 CNCF 的孵化项目,Gitops 的最佳实践工具。关于 Gitops 的解释可以参考https://about.Gitlab.com/topics/Gitops/

Gitops 可以为海豚调度的实施带来以下优点:

  • 图形化安装集群化的软件,一键安装;

  • Git 记录全发版流程,一键回滚;

  • 便捷的海豚工具日志查看;

使用 argo-cd 的实施安装步骤:

  • 从 GitHub 上下载海豚调度源码,修改 value 文件,参考上个章节 helm 安装需要修改的内容;

  • 把修改后的源码目录新建 Git 项目,并且 push 到公司内部的 Gitlab 中,GitHub 源码的目录名为 docker/Kubernetes/dolphinscheduler;

  • 在 argo-cd 中配置 Gitlab 信息,我们使用 https 的模式;

  • argo-cd 新建部署工程,填写相关信息

  • 对 Git 中的部署信息进行刷新和拉取,实现最后的部署工作;可以看到 pod,configmap,secret,service 等等资源全自动拉起。

  • 通过 kubectl 命令可以看到相关资源信息;

  [root@tpk8s-master01 ~]# kubectl get po -n ds139  NAME                                     READY   STATUS    RESTARTS   AGE  dolphinscheduler-alert-96c74dc84-72cc9   1/1     Running   0          22m  dolphinscheduler-api-78db664b7b-gsltq    1/1     Running   0          22m  dolphinscheduler-master-0                1/1     Running   0          22m  dolphinscheduler-master-1                1/1     Running   0          22m  dolphinscheduler-master-2                1/1     Running   0          22m  dolphinscheduler-worker-0                1/1     Running   0          22m  dolphinscheduler-worker-1                1/1     Running   0          22m  dolphinscheduler-worker-2                1/1     Running   0          22m  [root@tpk8s-master01 ~]# kubectl get statefulset -n ds139  NAME                      READY   AGE  dolphinscheduler-master   3/3     22m  dolphinscheduler-worker   3/3     22m  [root@tpk8s-master01 ~]# kubectl get cm -n ds139  NAME                      DATA   AGE  dolphinscheduler-alert    15     23m  dolphinscheduler-api      1      23m  dolphinscheduler-common   29     23m  dolphinscheduler-master   10     23m  dolphinscheduler-worker   7      23m  [root@tpk8s-master01 ~]# kubectl get service -n ds139  NAME                               TYPE        CLUSTER-IP    EXTERNAL-IP   PORT(S)              AGE  dolphinscheduler-api               ClusterIP   10.43.238.5   <none>        12345/TCP            23m  dolphinscheduler-master-headless   ClusterIP   None          <none>        5678/TCP             23m  dolphinscheduler-worker-headless   ClusterIP   None          <none>        1234/TCP,50051/TCP   23m  [root@tpk8s-master01 ~]# kubectl get ingress -n ds139  NAME               CLASS    HOSTS           ADDRESS  dolphinscheduler   <none>   ds139.abc.com   
  • 可以看到所有的 pod 都分撒在 Kubernetes 集群中不同的 host 上,例如 worker1 和 2 都在不同的节点上。

  • 我们配置了 ingress,公司内部配置了泛域名就可以方便的使用域名进行访问;

  • 可以登录域名进行访问。

  • 具体配置可以修改 value 文件中的内容:

  ingress:    enabled: true    host: "ds139.abc.com"    path: "/dolphinscheduler"    tls:      enabled: false      secretName: "dolphinscheduler-tls"
  • 对部署好的系统进行检查,3 个 master,3 个 worker,zookeeper 都配置正常;

  • 使用 argo-cd 可以非常方便的进行修改 master,worker,api,alert 等组件的副本数量,海豚的 helm 配置也预留了 cpu 和内存的设置信息。这里我们修改 value 中的副本值。修改后,提交公司内部 Gitlab。

  master:    ## PodManagementPolicy controls how pods are created during initial scale up, when replacing pods on nodes, or when scaling down.    podManagementPolicy: "Parallel"    ## Replicas is the desired number of replicas of the given Template.    replicas: "5"  worker:    ## PodManagementPolicy controls how pods are created during initial scale up, when replacing pods on nodes, or when scaling down.    podManagementPolicy: "Parallel"    ## Replicas is the desired number of replicas of the given Template.    replicas: "5"  alert:    ## Number of desired pods. This is a pointer to distinguish between explicit zero and not specified. Defaults to 1.    replicas: "3"  api:    ## Number of desired pods. This is a pointer to distinguish between explicit zero and not specified. Defaults to 1.    replicas: "3"

只需要在 argo-cd 点击 sync 同步,对应的 pods 都按照需求进行了增加

  [root@tpk8s-master01 ~]# kubectl get po -n ds139  NAME                                     READY   STATUS    RESTARTS   AGE  dolphinscheduler-alert-96c74dc84-72cc9   1/1     Running   0          43m  dolphinscheduler-alert-96c74dc84-j6zdh   1/1     Running   0          2m27s  dolphinscheduler-alert-96c74dc84-rn9wb   1/1     Running   0          2m27s  dolphinscheduler-api-78db664b7b-6j8rj    1/1     Running   0          2m27s  dolphinscheduler-api-78db664b7b-bsdgv    1/1     Running   0          2m27s  dolphinscheduler-api-78db664b7b-gsltq    1/1     Running   0          43m  dolphinscheduler-master-0                1/1     Running   0          43m  dolphinscheduler-master-1                1/1     Running   0          43m  dolphinscheduler-master-2                1/1     Running   0          43m  dolphinscheduler-master-3                1/1     Running   0          2m27s  dolphinscheduler-master-4                1/1     Running   0          2m27s  dolphinscheduler-worker-0                1/1     Running   0          43m  dolphinscheduler-worker-1                1/1     Running   0          43m  dolphinscheduler-worker-2                1/1     Running   0          43m  dolphinscheduler-worker-3                1/1     Running   0          2m27s  dolphinscheduler-worker-4                1/1     Running   0          2m27s

海豚调度与 s3 对象存储技术集成

许多同学在海豚的社区中提问,如何配置 s3 minio 的集成。这里给出基于 Kubernetes 的 helm 配置。

  • 修改 value 中 s3 的部分,建议使用 ip+端口指向 minio 服务器。

  common:    ## Configmap    configmap:      DOLPHINSCHEDULER_OPTS: ""      DATA_BASEDIR_PATH: "/tmp/dolphinscheduler"      RESOURCE_STORAGE_TYPE: "S3"      RESOURCE_UPLOAD_PATH: "/dolphinscheduler"      FS_DEFAULT_FS: "s3a://dfs"      FS_S3A_ENDPOINT: "http://192.168.1.100:9000"      FS_S3A_ACCESS_KEY: "admin"      FS_S3A_SECRET_KEY: "password"
  • minio 中存放海豚文件的 bucket 名字是 dolphinscheduler,这里新建文件夹和文件进行测试。

海豚调度与 kube-prometheus 的技术集成

  • 我们在 Kubernetes 使用 kube-prometheus operator 技术,实现了在部署海豚后,自动实现了对海豚各个组件的资源监控。

  • 请注意 kube-prometheus 的版本,需要对应 Kubernetes 主版本。https://GitHub.com/prometheus-operator/kube-prometheus

海豚调度与 Service Mesh 的技术集成

  • 通过 Service Mesh 技术可以实现对海豚内部的服务调用,以及海豚 api 外部调用的可观测性分析,以实现海豚调度产品的自身服务优化。

  • 我们使用 linkerd 作为 Service Mesh 的产品进行集成,linkerd 也是 CNCF 优秀的毕业项目。

  • 只需要在海豚 helm 的 value 文件中修改 annotations,重新部署,就可以快速实现 mesh proxy sidecar 的注入。可以对 master,worker,api,alert 等组件都注入。

    annotations: #{}      linkerd.io/inject: enabled

未来海豚调度基于云原生技术的展望

海豚调度作为面向新一代云原生大数据工具,未来可以在 Kubernetes 生态集成更多的优秀工具和特性,满足更多的用户群体和场景。

  • 和 argo-workflow 的集成,可以通过 api,cli 等方式在海豚调度中调用 argo-workflow 单个作业,dag 作业,以及周期性作业;

  • 使用 hpa 的方式,自动扩缩容 worker,实现无人干预的水平扩展方式;

  • 集成 Kubernetes 的 spark operator 和 Hadoopoperator 工具,全面的云原生化;

  • 实现多云和多集群的分布式作业调度;

  • 采用 sidecar 实现定期删除 worker 作业日志;

作者简介

杨滇,深圳交通中心数据和算法平台架构师

划线
评论
复制
2022 年 2 月 22 日 07:08539
文章版权归极客邦科技InfoQ所有,未经许可不得转载。
轻点一下,留下你的鼓励
240dab3ce940663252a5964e57d1ccc6.jpg
Java避坑指南:Java高手笔记代码篇
Java 避坑指南:Java 高手笔记代码篇

本迷你书包括 86 个业务开发中常见踩坑点。每一个知识点都相当的实用,是程序员业务开发中的必备避坑指南...

大厂实战PPT下载

换一换
从架构师到CTO—看到技术背后的非技术选择
从架构师到CTO—看到技术背后的非技术选择

袁岳峰(湘菜) | 悦孚斯 独立站负责人

P2C - 淘系频道业务需求结构化平台

郭启织(卡狸) | 阿里巴巴 淘系前端F(x)Team前端技术专家

MagicHub.com开源社区: 为AI提供数据生产力

张晴晴 博士 | 爱数智慧 创始人兼 CEO


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK