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

时间:2019-11-25 19:37:28

标签: kubernetes ip google-kubernetes-engine grpc google-cloud-endpoints

我有一个包含多个节点的集群。我已经建立了Cloud Endpoints门户并部署了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\'."
'

谢谢!

EDIT 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服务配置规范

2 个答案:

答案 0 :(得分:0)

有可能。

这里是link到openapi,但这可能对您有帮助。

答案 1 :(得分:0)

这些行必须根据此doc

添加到您的api_config.yaml中
endpoints:
- name: name.projectid.cloud.goog
  target: "X.X.X.X"

我通过遵循quickstart for gRPC endpoints / GKE

进行了测试

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

(emerald-cumulus-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