首页 > 解决方案 > Spark Kubernetes - 使用 --files 或 spark.files 将配置文件从驱动程序复制到执行程序时出现 FileNotFoundException

问题描述

我们正在将 Spark 工作负载从 Cloudera 迁移到 Kubernetes。

出于演示目的,我们希望在集群模式下使用 spark-submit 在 minikube 集群中运行我们的 spark 作业之一。

我想使用 spark.file conf 将类型安全的配置文件传递给我的执行程序(我也尝试过 --files )。配置文件已在构建时复制到 /opt/spark/conf 目录中的 spark docker 映像。

然而,当我提交我的工作时,我有一个java.io.FileNotFoundException: File file:/opt/spark/conf/application.conf does not exist

我的理解是 spark.files 将文件从驱动程序复制到执行程序的工作目录。

我错过了什么吗?谢谢您的帮助。

这是我的 spark-submit 命令

spark-submit \
        --master k8s://https://192.168.49.2:8443 \
        --driver-memory ${SPARK_DRIVER_MEMORY} --executor-memory ${SPARK_EXECUTOR_MEMORY} \
        --deploy-mode cluster \
        --class "${MAIN_CLASS}" \
        --conf spark.driver.defaultJavaOptions="-Dconfig.file=local://${POD_CONFIG_DIR}/application.conf $JAVA_ARGS" \
        --conf spark.files="file:///${POD_CONFIG_DIR}/application.conf,file:///${POD_CONFIG_DIR}/tlereg.properties" \
        --conf spark.executor.defaultJavaOptions="-Dconfig.file=local://./application.conf" \
        --conf spark.executor.instances=5 \
        --conf spark.kubernetes.container.image=$SPARK_CONTAINER_IMAGE \
        --conf spark.kubernetes.authenticate.driver.serviceAccountName=spark \
        --conf spark.kryoserializer.buffer.max=512M \
        --conf spark.driver.maxResultSize=8192M \
        --conf spark.kubernetes.authenticate.caCertFile=$HOME/.minikube/ca.crt \
        --conf spark.executor.extraClassPath="./" \
        local:///path/to/uber/jar.jar \
        "${PROG_ARGS[@]}" > $LOG_FILE 2>&1

标签: javascaladockerapache-sparkkubernetes

解决方案


我已经想通了。spark-submit向 kubernetes master 的 api-server 发送请求以创建驱动程序 pod。configmap 卷安装到驱动程序的 pod 上mountPath: /opt/spark/conf,它会覆盖位于 docker 容器中该路径的我的配置文件。解决方法:在 Dockerfile 中将 /opt/spark/conf 编辑为 /opt/spark/config,以便从后者复制我的配置文件。


推荐阅读