简体   繁体   English

如何请求在 Cloud Run 上运行的 Go 制作的 gRPC 服务器

[英]How to request gRPC server made by Go running on Cloud Run

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

It's a cafe-cli application.这是一个 cafe-cli 应用程序。

I registered container to GCR, and deploy to Cloud Run.我将容器注册到 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

How to request to this gRPC server?如何请求这个 gRPC 服务器?
I tried the following.我尝试了以下方法。

$ 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

What must I do?我必须做什么?

The first thing to try is to get things going is create a new service and allow unauthenticated:首先要尝试的是创建一个新服务并允许未经身份验证的:

"Allow unauthenticated invocations to [] (y/N)? y" “允许未经身份验证的调用 [] (y/N)?y”

Secondly, if you would try to access gRPC with auth, please check:其次,如果您尝试使用 auth 访问 gRPC,请检查:

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

The Authorization header in your curl command is wrong. curl 命令中的 Authorization 标头是错误的。 It's missing a $ before the gcloud command.在 gcloud 命令之前缺少$ Use this instead:改用这个:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法连接到在本地 Docker 容器中运行的 Go GRPC 服务器 - Cannot connect to Go GRPC server running in local Docker container gRPC 节点:当 *Dockerizing* 服务时,请求不是通过服务的服务器 go 吗? [包括截图] - gRPC-node: When *Dockerizing* Service, request doesn't go through service's server? [Screenshots included] 连接到在不同 pod 上运行的 gRPC 服务器 - Connect to gRPC server running on different pod 如何向在Docker上运行的服务器发出请求 - How to make request to server running on docker 如何在 docker 容器中使用 nestjs 运行 gRPC 微服务 - How to run gRPC microservice with nestjs in a docker container 如何在 docker 容器中运行 .net 核心 grpc? - How to run .net core grpc in docker container? 保持Dotnet Core Grpc Server作为控制台应用程序运行? - Keep Dotnet Core Grpc Server running as a console application? 如何查看在我的 Google Cloud Platform Cloud Run 服务上运行的文件? - How to see the files running on my Google Cloud Platform Cloud Run service? Wine 未在 Google Cloud Run 上运行(Google Cloud Run 的限制) - Wine not running on Google Cloud Run (limitations of google cloud run) 如何在python中热重载grpc-server? - How to hot reload grpc-server in python?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM