gpt4 book ai didi

docker - 如何请求由Go运行在Cloud Run上的gRPC服务器

转载 作者:行者123 更新时间:2023-12-01 21:14:43 25 4
gpt4 key购买 nike

我通过go lang制作了gRPC服务器。
https://github.com/takat0-h0rikosh1/grpc-with-go

这是一个cafe-cli应用程序。

我向GCR注册了容器,然后将其部署到Cloud Run。

# docker build
docker build -t cafe .

# register image
$ docker tag cafe gcr.io/xxx/cafe
$ docker push gcr.io/xxx/cafe

# deploy to cloud run
$ gcloud beta run deploy --project xxx --image gcr.io/xxx/cafe
Please choose a target platform:
[1] Cloud Run (fully managed)
[2] Cloud Run for Anthos deployed on Google Cloud
[3] Cloud Run for Anthos deployed on VMware
[4] cancel
Please enter your numeric choice: 1

To specify the platform yourself, pass `--platform managed`. Or, to make this the default target platform, run `gcloud config set run/platform managed`.

Service name (cafe): cafe-service
Allow unauthenticated invocations to [cafe-service] (y/N)? N

Deploying container to Cloud Run service [cafe-service] in project [xxx] region [us-central1]
✓ Deploying new service... Done.
✓ Creating Revision...
✓ Routing traffic...
Done.
Service [cafe-service] revision [cafe-service-00001-pal] has been deployed and
is serving 100 percent of traffic at https://cafe-service-xxx-uc.a.run.app

如何向该gRPC服务器请求?
我尝试了以下方法。

$ curl -H \
"Authorization: Bearer (gcloud auth print-identity-token)" \
https://cafe-service-xxx-uc.a.run.app

<html><head>
<meta http-equiv="content-type" content="text/html;charset=utf-8">
<title>401 Unauthorized</title>
</head>
<body text=#000000 bgcolor=#ffffff>
<h1>Error: Unauthorized</h1>
<h2>Your client does not have permission to the requested URL <code>/</code>.</h2>
<h2></h2>
</body></html>

$ grpcurl -plaintext cafe-service-xxx-uc.a.run.app:443 list
Failed to dial target host "cafe-service-xxx-uc.a.run.app:443": context deadline exceeded

$ grpcurl -authority (gcloud auth print-identity-token) -plaintext cafe-service-xxx-uc.a.run.app:443 list
Failed to dial target host "cafe-service-xxx-uc.a.run.app:443": context deadline exceeded

我必须做什么?

最佳答案

要做的第一件事就是创建一个新服务并允许未经身份验证的服务:

"Allow unauthenticated invocations to [] (y/N)? y"



其次,如果您尝试使用auth访问gRPC,请检查:

https://medium.com/google-cloud/grpc-authentication-with-cloud-run-72e4d6c44739

关于docker - 如何请求由Go运行在Cloud Run上的gRPC服务器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59691495/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com