目录

Spark-3.0.0-SNAPSHOT-Access-Kerberized-HDFS

1 Overview

Spark 2.2 on K8S 的 Fork 已经废弃近两年了,那时候的几个主力开发也全部转移到 Spark 2.3/2.4 以及即将发布的 3.0 的 on K8S 模块的开发了。

3.0 相对于 2.2 的 Fork 除了关于 Spark App 的管理外,大部分特性都是 2.2 的改良,甚至镜像文件都只剩下一个(更方便管理)。而比较重要的劣势是 3.0 还不正式支持 Dynamic Resource Allocation,2.2 是已经有一种实现的(基于 DaemotSet 来创建 Shuffle Pod)。

前期调研 2.3 的时候发现,还没有支持 Kerberos 的相关特性,最近重新调研 2.4 的代码的时候,发现在 3.0.0 SNAPSHOT 已经有了支持了,而且方案比 2.2 更好。

2 Design

在 Spark 3.0.0 中,提交 Spark 任务的脚本如下。

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
/opt/spark/bin/spark-submit \
      --deploy-mode cluster \
      --class org.apache.spark.examples.HdfsTest \
      --master=k8s://https://kubernetes.default.svc \
      --conf spark.executor.instances=1 \
      --conf spark.task.cpus=1 \
      --conf spark.executor.memory=512M \
      --conf spark.kubernetes.namespace=runzhliu \
      --conf spark.driver.extraJavaOptions=-Dlog4j.configuration=file:///opt/spark/logconf/log4j.properties \
      --conf spark.executor.extraJavaOptions=-Dlog4j.configuration=file:///opt/spark/logconf/log4j.properties \
      --conf spark.kubernetes.executor.deleteOnTermination=false \
      --conf spark.app.name=spark-hdfs \
      --conf spark.kerberos.keytab=/etc/DC-sh-cr-kerberos.keytab \
      --conf spark.kubernetes.kerberos.krb5.path=/etc/krb5.conf  \
      --conf spark.kerberos.principal=DC-sh-cr-kerberos@HADOOP.COM \
      --conf spark.kubernetes.container.image=hub.oa.com/runzhliu/spark:v3.0.4 \
      local:///opt/spark/examples/jars/spark-examples_2.12-3.0.0-SNAPSHOT.jar \
      hdfs://sh-kerberos.hdfs.cr.ied.com:8020/sh-cr

Spark 访问 Kerberized HDFS 有几种情况。

  1. keytab: if a kerberos keytab is defined, it is provided to the driver, and the driver will manage the kerberos login and the creation of delegation tokens.
  2. existing tokens: if a secret containing delegation tokens is provided, it will be mounted on the driver pod, and the driver will handle distribution of those tokens to executors.
  3. tgt only: if Hadoop security is enabled, the local TGT will be used to create delegation tokens which will be provided to the driver. The driver will handle distribution of the tokens to executors.

【1】指出了,当在 submit 的客户端如果可以访问到 keytab,并且通过 Spark conf 来指定。那么 submit 的时候会将 krb5.conf 还有 hadoop 相关的配置通过 configmap 来保存,所以后面 driver 和 exectutor 启动,就可以直接通过 configmap 读到 hadoop 相关配置,以及拿到与 datanode 交互的 delegation token,如下图。

/spark-3.0.0-snapshot-access-kerberized-hdfs/image_1deu2ms6h1pls1us81iinho3137l9.png /spark-3.0.0-snapshot-access-kerberized-hdfs/image_1deu2pkfdgt01pvbgg1a591plm.png /spark-3.0.0-snapshot-access-kerberized-hdfs/image_1deu2qmkv176jcul1blb1ndr1nmk13.png

【2】指出了,用户也可以通过提前生成 token 的 secret,在 submit 的时候,直接指定需要 mount 的 configmap 和 secret,这种情况下,无需 keytab。 【3】指出了 submit 客户端如果存在本地的 TGT 缓存(类似

3 For Spark

目前平台是不支持直接跑 Spark 3.0.0 的,最主要是 submit 的一些 Spark conf 有些改变,最直接的就是 image,现在只需要一个统一的 image 就可以了,不需要 driver 和 executor 等,所以需要前后端的改动。

/spark-3.0.0-snapshot-access-kerberized-hdfs/image_1deu7mlvr1n545cd3aa1ttpkcj9.png /spark-3.0.0-snapshot-access-kerberized-hdfs/image_1deu7pfuh17ua1tu63bn15qc56am.png

所以大致的改造计划包括以下几个步骤。

  1. Spark计算只提供Container Image的配置,但是开放副本数,资源的配置
  2. Keytab/krb5.conf通过提供的服务拉取,Principal 根据协议自动补充
  3. 其他SparkConf的配置不变
  4. 支持DRA
警告
本文最后更新于 2017年2月1日,文中内容可能已过时,请谨慎参考。