我有一个形象,这将是我的培训工作。培训数据位于Cloud数据库中。当我在本地机器上运行cloud_sql_proxy时,容器可以很好地连接。
❯ docker run --rm us.gcr.io/myproject/trainer:latest mysql -uroot -h"'172.17.0.2'" -e"'show databases;'"
Running: `mysql -uroot -h'172.17.0.2' -e'show databases;'`
Database
information_schema
mytrainingdatagoeshere
mysql
performance_schema我使用mysql只是为了测试连接,实际的训练命令在容器的其他地方。当我尝试通过人工智能平台,我不能连接。
❯ gcloud ai-platform jobs submit training firsttry3 \
--region us-west2 \
--master-image-uri us.gcr.io/myproject/trainer:latest \
-- \
mysql -uroot -h"'34.94.1.2'" -e"'show tables;'"
Job [firsttry3] submitted successfully.
Your job is still active. You may view the status of your job with the command
$ gcloud ai-platform jobs describe firsttry3
or continue streaming the logs with the command
$ gcloud ai-platform jobs stream-logs firsttry3
jobId: firsttry3
state: QUEUED
❯ gcloud ai-platform jobs stream-logs firsttry3
INFO 2019-12-16 22:58:23 -0700 service Validating job requirements...
INFO 2019-12-16 22:58:23 -0700 service Job creation request has been successfully validated.
INFO 2019-12-16 22:58:23 -0700 service Job firsttry3 is queued.
INFO 2019-12-16 22:58:24 -0700 service Waiting for job to be provisioned.
INFO 2019-12-16 22:58:26 -0700 service Waiting for training program to start.
ERROR 2019-12-16 22:59:32 -0700 master-replica-0 Entered Slicetool Container
ERROR 2019-12-16 22:59:32 -0700 master-replica-0 Running: `mysql -uroot -h'34.94.1.2' -e'show tables;'`
ERROR 2019-12-16 23:01:44 -0700 master-replica-0 ERROR 2003 (HY000): Can't connect to MySQL server on '34.94.1.2'似乎无法从作业运行的地方访问主机。如何授予AI平台对Cloud的访问权限?
我已经考虑过将云sql代理包括在培训容器中,然后将服务帐户凭据作为用户args注入,但是由于它们都在同一个项目中,所以我希望这一步没有必要。这些希望是否落空了?
发布于 2019-12-17 16:35:30
因此,不幸的是,并不是所有的云产品都被沙箱装进同一个网络,所以您无法在产品之间自动连接。因此,您面临的问题是,AI平台无法在34.xx.x.xIP地址自动到达Cloud实例。
有几种方法,你可以考虑修复它,尽管警告,我不知道人工智能平台的网络设置很好(我将不得不这样做,并在这里很快博客)。首先,您可以尝试查看是否可以将AI平台连接到VPC (虚拟专用云)网络,并将Cloud实例放到同一个VPC中。这将允许他们通过私有IP相互交谈(可能与您现在拥有的IP不同)。在Cloud实例的连接详细信息中,您应该看到您是否拥有私有IP,如果没有,您可以在实例设置中启用它(需要关闭并重新启动)。否则,您可以确保设置了公共IP地址,这可能是34.xx.x.xIP,然后是让列表(白名单,但我试图改变术语)云IP地址的AI平台。
您可以在这里了解GCP处理IP范围的方式:https://cloud.google.com/compute/docs/ip-addresses/
一旦将这些范围添加到Cloud连接设置中的授权网络中,您应该能够从AI平台直接连接。
原始响应
当您试图从AI平台连接到它时,代理在哪里运行?还在你的本地机器上吗?因此,基本上,在场景1中,您是在本地运行这个容器,并运行码头,并连接到您的本地IP: 172.17.0.2,然后当您转移到AI平台时,您将在34.xx.x.x连接到您的本地机器?因此,首先,您可能想要删除您的实际家庭IP地址从您原来的问题。人们在互联网上很粗鲁,如果这真的是你的家庭IP的话,结果可能会很糟糕。第二,你有多确定你已经在你的防火墙上打开了一个洞,让流量从人工智能平台进入?一般来说,这就是我认为问题所在的地方,您在本地机器上的连接被拒绝,而导致无法连接的错误。
发布于 2021-07-26 23:39:59
以下是我在不需要VPC窥视或独立代理的情况下,完全通过我的Python项目所做的工作。
from oauth2client.client import GoogleCredentials
from googleapiclient import discovery
from googleapiclient import errors
from time import time
project_name = YOUR_PROJECT
project_id = 'projects/{}'.format(project_name)
projectNumber = 1234 # retrieved via Google Cloud SDK Shell: gcloud projects describe YOUR_PROJECT --format="value(projectNumber)"
trainingInputs = {
"region": "us-east4",
"masterConfig": {
"imageUri": "gcr.io/my_project/my_image",
},
"serviceAccount":"****@your_project.iam.gserviceaccount.com"
}
# https://cloud.google.com/ai-platform/training/docs/reference/rest/v1/projects.jobs#ReplicaConfig
job = {
"jobId": f"TestJob_{int(time())}",
"labels": {
"custom_label":"label_value"
},
"trainingInput": trainingInputs
}
# https://cloud.google.com/ai-platform/training/docs/reference/rest/v1/projects.jobs/create
cloudml = discovery.build('ml','v1')
request = cloudml.projects().jobs().create(body=job,
parent=project_id)
try:
response = request.execute()
# You can put your code for handling success (if any) here.
print(response)
except errors.HttpError as err:
print('There was an error creating the training job.'
' Check the details:')
print(err._get_reason())https://stackoverflow.com/questions/59368758
复制相似问题