目前我正在GKE上设置Kubeflow Pipeline。目标是在ML引擎上启动trainingjob,然后在GKE上提供它。
trainingjob在Docker容器中启动。 (管道中的每一步都必须是一个容器。)
运行容器时出现以下错误:
ERROR: (gcloud.ml-engine.jobs.submit.training) You do not currently have an active account selected.
Please run:
$ gcloud auth login
to obtain new credentials, or if you have already logged in with a
different account:
$ gcloud config set account ACCOUNT
to select an already authenticated account to use.
docker容器通过following answer中建议的服务帐户获取凭据。
FROM tensorflow/tensorflow:1.8.0-devel-gpu-py3
RUN apt-get update -y && apt-get install --no-install-recommends -y -q ca-certificates python-dev python-setuptools wget unzip git
# Components to run ML Engine job on cluster
RUN cd / && \
wget -nv https://dl.google.com/dl/cloudsdk/release/google-cloud-sdk.zip && \
unzip -qq google-cloud-sdk.zip -d tools && \
rm google-cloud-sdk.zip && \
tools/google-cloud-sdk/install.sh --usage-reporting=false \
--path-update=false --bash-completion=false \
--disable-installation-options && \
tools/google-cloud-sdk/bin/gcloud -q components update \
gcloud core gsutil && \
tools/google-cloud-sdk/bin/gcloud config set component_manager/disable_update_check true && \
touch /tools/google-cloud-sdk/lib/third_party/google.py
ENV PATH $PATH:/tools/node/bin:/tools/google-cloud-sdk/bin
RUN mkdir /workdir
COPY . /workdir
RUN export GOOGLE_APPLICATION_CREDENTIALS=/workdir/ml6-sandbox-cdc8cb4bcae2.json
ENTRYPOINT ["bash", "/workdir/ml-engine/train.sh"]
错误发现在train.sh中,我提交了一个trainingjob:
gcloud ml-engine jobs submit training $JOB_NAME \
--job-dir $JOB_DIR \
--runtime-version 1.8 \
--python-version 3.5 \
--module-name trainer.run_train \
--package-path ./trainer \
--region $REGION \
--config=trainer/config.yaml \
--stream-logs \
-- \
--data-dir $DATA_DIR \
--version $VERSION
在我的run_train.py中,我获得了以下Google Application Credentials:
os.environ[
"GOOGLE_APPLICATION_CREDENTIALS"] = '/workdir/ml6-sandbox-cdc8cb4bcae2.json'
Train.sh独立工作。
你只需要在GOOGLE_APPLICATION_CREDENTIALS
时设置using the client libraries env变量。
当您使用gcloud
CLI更改此行时:
RUN export GOOGLE_APPLICATION_CREDENTIALS=/workdir/ml6-sandbox-cdc8cb4bcae2.json
至
gcloud auth activate-service-account yourServiceAccount --key-file=/workdir/ml6-sandbox-cdc8cb4bcae2.json
这会将您的服务帐户记录为gcloud
使用的有效帐户。
此外,此服务帐户需要使用适当的roles授予。