Google Kubernetes Engine - 从外部 IP 到云端点配置



我有一个包含多个节点的集群。我已设置云终结点门户并部署了api_config.yaml

#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# A Bookstore example API configuration.
#
# Below, replace MY_PROJECT_ID with your Google Cloud Project ID.
#
# The configuration schema is defined by service.proto file
# https://github.com/googleapis/googleapis/blob/master/google/api/service.proto
type: google.api.Service
config_version: 3
#
# Name of the service configuration.
#
name: MY-SERVICE.service.endpoints.MY-PROJECT-ID.cloud.goog
#
# API title to appear in the user interface (Google Cloud Console).
#
title: MyService gRPC API
apis:
- name: endpoints.MY-PROJECT-ID.service.MY-SERVICE.MyService

我的问题是我认为很简单:如何将 url 用作 API 端点而不是节点的外部 IP?因为如果我的 IP 发生变化,我不想在配置方面更改代码中的任何内容,而只需更新我的"地址绑定">

我可以通过 URL 访问 API 文档,并且我的服务可从外部 IP 访问。我只是想将两者绑定

现在我有以下行为:

MBP-de-Emixam23:service-interface emixam23$ gcloud endpoints services deploy service.pb api_config.yaml
ERROR: (gcloud.endpoints.services.deploy) INVALID_ARGUMENT: Cannot convert to service config.
'location: "api_config.yaml:36"
kind: ERROR
message: "Cannot resolve api 'endpoints.MY-PROJECT-ID.service.MY-SERVICE.MyService'."
'

谢谢!

编辑 v2(基于 Andres S 评论/答案(

host: "<YOUR_NAMING>.endpoints.YOUR_PROJECT_ID.cloud.goog"
x-google-endpoints:
- name: "<YOUR_NAMING>.endpoints.YOUR_PROJECT_ID.cloud.goog"
target: "IP_ADDRESS"
# host: "test.service.endpoints.example-project.cloud.goog"
# x-google-endpoints:
# - name: "test.service.endpoints.example-project.cloud.goog"
# target: "23.11.95.72"

错误:(gcloud.endpoints.services.deploy(无法从 api_config.yaml 解析 Open API 或 Google 服务配置规范

根据此文档,这些行必须添加到您的 api_config.yaml 中

endpoints:
- name: name.projectid.cloud.goog
target: "X.X.X.X"

我按照 gRPC 终结点/GKE 的快速入门进行了测试

并最终能够使用域从端点获得答案

(翡翠积云-260322 是我用于测试的时间投影 ID(

$ python bookstore_client.py --host bookstore.endpoints.emerald-cumulus-260322.cloud.goog --port 80                                 
ListShelves: shelves {
id: 1
theme: "Fiction"
}
shelves {
id: 2
theme: "Fantasy"
}

我的最终 api_config.yaml 如下所示:

# Copyright 2016 Google Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# A Bookstore example API configuration.
#
# Below, replace MY_PROJECT_ID with your Google Cloud Project ID.
#
# The configuration schema is defined by service.proto file
# https://github.com/googleapis/googleapis/blob/master/google/api/service.proto
type: google.api.Service
name: bookstore.endpoints.projectidhere.cloud.goog
endpoints:
- name: bookstore.endpoints.projectidhere.cloud.goog
target: "X.X.X.X"
config_version: 3
#
# Name of the service configuration.
#
#
# API title to appear in the user interface (Google Cloud Console).
#
title: Bookstore gRPC API
apis:
- name: endpoints.examples.bookstore.Bookstore
#
# API usage restrictions.
#
usage:
rules:
# ListShelves methods can be called without an API Key.
- selector: endpoints.examples.bookstore.Bookstore.ListShelves
allow_unregistered_calls: true

也许是可能的。

这是 openapi 的链接,但可能对您有所帮助。

最新更新