我使用GCSFuse将GCS桶挂载到JupyterHub中的用户荚中,但是它总是在错误消息gcsfuse takes exactly two arguments中失败。
这是我的DockerFile:
FROM jupyter/minimal-notebook:177037d09156
ENV GCSFUSE_REPO gcsfuse-stretch
ENV GOOGLE_APPLICATIONS_CREDENTIALS=test-serviceaccount.json
ENV GCS_BUCKET: "my-bucket"
ENV GCS_BUCKET_FOLDER: "shared-data"
USER root
# Add google repositories for gcsfuse and google cloud sdk
RUN apt-get update -y && apt-get install -y --no-install-recommends apt-transport-https ca-certificates curl gnupg
RUN echo "deb http://packages.cloud.google.com/apt $GCSFUSE_REPO main" | tee /etc/apt/sources.list.d/gcsfuse.list
RUN echo "deb https://packages.cloud.google.com/apt cloud-sdk main" | tee -a /etc/apt/sources.list.d/google-cloud-sdk.list
RUN curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add -
# Install gcsfuse and google cloud sdk
RUN apt-get update -y && apt-get install -y gcsfuse google-cloud-sdk \
&& apt-get autoremove -y \
&& apt-get clean -y \
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
# Switch back to notebook user (defined in the base image)
USER $NB_UID
# make directory for mounting
RUN mkdir -p home/shared-data \
&& mkdir -p etc/scripts
COPY start_mounting.sh etc/scripts
# install extra packages required for model training
RUN pip install --upgrade pip
RUN pip install fasttext
RUN pip install ax-platform
CMD ["bin/bash", "etc/scripts/start_mounting.sh"]剧本:
#!/bin/bash
# Setup GCSFuse
gcsfuse --key-file ${GOOGLE_APPLICATIONS_CREDENTIALS} ${GCS_BUCKET} ${GCS_BUCKET_FOLDER}我的jupyterhub config.yaml
hub:
baseUrl: /jupyterhub
extraConfig: |
from kubernetes import client
def modify_pod_hook(spawner, pod):
pod.spec.containers[0].security_context = client.V1SecurityContext(
privileged=True,
capabilities=client.V1Capabilities(
add=['SYS_ADMIN']
)
)
pod.spec.containers[0].env.append(
client.V1EnvVar(
name='GOOGLE_APPLICATIONS_CREDENTIALS',
value_from=client.V1EnvVarSource(
secret_key_ref=client.V1SecretKeySelector(
name='jhub-secret',
key='jhub-serviceaccount',
)
)
)
)
return pod
c.KubeSpawner.modify_pod_hook = modify_pod_hook
singleuser:
storage:
type: none
extraEnv:
GCS_BUCKET: "my-bucket"
GCS_BUCKET_FOLDER: "shared-data"
lifecycleHooks:
postStart:
exec:
command: ["/bin/sh", "etc/scripts/start_mounting.sh"]
preStop:
exec:
command: ["fusermount", "-u", "shared-data"]
image:
name: gcr.io/project/base-images/jhub-k8s-cust-singleuser
tag: 1.1.6
pullPolicy: Always我正在重写GOOGLE_APPLICATIONS_CREDENTIALS ENV,因为它在gcsfuse中使用了密钥文件参数。
有人能告诉我这里出了什么问题吗?我的pod PostStart Exec命令有什么问题吗?还是我的导火索错了?
发布于 2020-08-11 14:57:55
我通过为K8s秘密创建卷挂载(Google )并将其作为ENV传递到gcsfuse命令的脚本start_mounting.sh中来解决这个问题。
下面是我使用的代码:
storage:
extraVolumes:
- name: my-secret-jupyterhub
secret:
secretName: my-secret
extraVolumeMounts:
- name: my-secret-jupyterhub
mountPath: /etc/secrets
readOnly: true
extraEnv:
GOOGLE_APPLICATIONS_CREDENTIALS: /etc/secrets/key.json这似乎比获取服务帐户的文件内容更简洁,并像前面和前面所讨论的那样,将它放在gcs引信命令的文件中。
发布于 2020-08-08 20:51:13
我不是JupyterHub的专家(甚至是用户)。我的回答是通用的
我看到了解决你问题的两种方法
在jupyterhub yaml文件中,更改json密钥文件内容的env var。
pod.spec.containers[0].env.append(
client.V1EnvVar(
name='GOOGLE_APPLICATIONS_CREDENTIALS_CONTENT',
value_from=client.V1EnvVarSource(
secret_key_ref=client.V1SecretKeySelector(
name='jhub-secret',
key='jhub-serviceaccount',
)
)
)
)像这样修改脚本(将内容写入定义的文件):
#!/bin/bash
echo ${GOOGLE_APPLICATIONS_CREDENTIALS_CONTENT} > ${GOOGLE_APPLICATIONS_CREDENTIALS}
# Setup GCSFuse
gcsfuse --key-file ${GOOGLE_APPLICATIONS_CREDENTIALS} ${GCS_BUCKET} ${GCS_BUCKET_FOLDER}容器是不可变的。我认为这将有效,因为更改只在内存中执行。
注意:更喜欢GOOGLE_APPLICATIONS_CREDENTIALS文件路径定义的绝对路径
https://stackoverflow.com/questions/63317861
复制相似问题