【问题标题】:Defining permissions on a Kubernetes mounted volume in Spark executor在 Spark 执行器中定义 Kubernetes 挂载卷的权限
【发布时间】:2023-01-04 23:57:40
【问题描述】:

我正在尝试在我的 Spark(版本 3.1.3)执行程序上使用 Kubernetes(版本 1.21)安装的卷来完成某项工作,并将其用作我的执行程序溢出到的 SPARK_LOCAL_DIR。

将它安装在我的执行程序上与我的 spark-submit 中的以下行一起工作(受 Spark docs 启发):

--conf spark.kubernetes.executor.volumes.persistentVolumeClaim.test.options.claimName=OnDemand
--conf spark.kubernetes.executor.volumes.persistentVolumeClaim.test.options.storageClass=someClass
--conf spark.kubernetes.executor.volumes.persistentVolumeClaim.test.options.sizeLimit=100Gi
--conf spark.kubernetes.executor.volumes.persistentVolumeClaim.test.mount.path=//local-data
--conf spark.kubernetes.executor.volumes.persistentVolumeClaim.test.mount.readOnly=false

我确实可以验证在我的执行程序内部,/local-data/ 挂载存在 100Gi 的空间。此外,我看到在我的 K8s 命名空间中制作了必要的 PVC。

我遇到的问题是写入该磁盘,即使是手动写入也是如此。如果我在这 5 行配置中将 readOnly 参数设置为 true,我将得到以下信息:

cd /local-data/
touch testfile
touch: cannot touch 'testfile': Read-only file system

这是完全合理的,因为我将 readOnly 设置为 true。

现在,如果我将 readOnly 设置为 false,我会遇到以下问题:

cd /local-data/
touch testfile
touch: cannot touch 'testfile': Permission denied

所以看起来我有权限问题,这很容易通过 ls -al 看到:

185@job-0a37df82fdd123d2-exec-1:/local-data$ ls -al
total 24
drwxr-xr-x 3 root root  4096 Sep  2 10:48 .
drwxr-xr-x 1 root root  4096 Sep  2 10:49 ..
drwx------ 2 root root 16384 Sep  2 10:48 lost+found

如您所见,我的用户(默认 Spark 用户,我们不能以 root 身份运行)没有写入 /local-data 的权限。这似乎阻止了我将此卷用作本地存储,如 Spark docs 中所定义。

有没有一种方法可以在我的 spark 提交选项中定义这个已安装卷的权限?如果没有,您将如何着手并尝试能够在您的执行程序中将此安装的卷用作本地目录?但是,我不能在我的应用程序中以 root 用户身份运行 spark。

非常感谢!

【问题讨论】:

    标签: apache-spark kubernetes


    【解决方案1】:

    您可以创建一个类似于此的 pod-template.yaml -

    apiVersion: v1
    kind: Pod
    metadata:
    spec:
      securityContext:
        runAsUser: 1000
        runAsGroup: 3000
        fsGroup: 2000
    

    并在 spark-submit 命令中使用它。相应地更改 UID、GID,尤其是 fsGroup。

    spark-sumbit ... 
    --conf spark.kubernetes.driver.podTemplateFile=pod-template.yaml 
    --conf spark.kubernetes.executor.podTemplateFile=pod-template.yaml 
    ...
    

    【讨论】:

    • 非常感谢!这确实是这样做的方法:) :)
    猜你喜欢
    • 2020-11-06
    • 2021-03-31
    • 2020-08-07
    • 2017-06-30
    • 2019-08-24
    • 2021-10-26
    • 2019-10-09
    • 1970-01-01
    • 2018-12-29
    相关资源
    最近更新 更多