google 在 gke 上找不到云端点 api_method
google cloud endpoints api_method not found on gke
404 响应 Method: 1.api_endpoints_gcp_project_cloud_goog.Postoperation failed: NOT_FOUND
google 云端点 esp
我正在尝试通过 GKE 将我的 API 与 google 云端点部署在一起。我在 Produced API 日志中收到此错误,其中显示:
Method: 1.api_endpoints_gcp_project_cloud_goog.Postoperation failed: NOT_FOUND
我从端点收到 404 响应。
后端容器正确回答,但是当我尝试 post http://[service-ip]/v1/postoperation 时出现 404 错误。我猜它与 api_method 名称有关,但我已经更改,所以它在 openapi.yaml、gke 部署和 app.py.
中是相同的
我使用 openapi.yaml:
成功部署了 API 服务
swagger: "2.0"
info:
description: "API rest"
title: "API example"
version: "1.0.0"
host: "api.endpoints.gcp-project.cloud.goog"
basePath: "/v1"
# [END swagger]
consumes:
- "application/json"
produces:
- "application/json"
schemes:
# Uncomment the next line if you configure SSL for this API.
#- "https"
- "http"
paths:
"/postoperation":
post:
description: "Post operation 1"
operationId: "postoperation"
produces:
- "application/json"
responses:
200:
description: "success"
schema:
$ref: "#/definitions/Model"
400:
description: "Error"
parameters:
- description: "Description"
in: body
name: payload
required: true
schema:
$ref: "#/definitions/Resource"
definitions:
Resource:
type: "object"
required:
- "text"
properties:
tipodni:
type: "string"
dni:
type: "string"
text:
type: "string"
Model:
type: "object"
properties:
tipodni:
type: "string"
dni:
type: "string"
text:
type: "string"
mundo:
type: "string"
cluster:
type: "string"
equipo:
type: "string"
complejidad:
type: "string"
然后我尝试用这个 deploy.yaml 和 lb-deploy.yaml
配置后端和 esp
apiVersion: apps/v1 # for versions before 1.9.0 use apps/v1beta2
kind: Deployment
metadata:
name: api-deployment
namespace: development
spec:
strategy:
type: Recreate
selector:
matchLabels:
app: api1
replicas: 2 # tells deployment to run 2 pods matching the template
template:
metadata:
labels:
app: api1
spec:
volumes:
- name: google-cloud-key
secret:
secretName: secret-key
containers:
- name: api-container
image: gcr.io/gcp-project/docker-pqr:IMAGE_TAG_PLACEHOLDER
volumeMounts:
- name: google-cloud-key
mountPath: /var/secrets/google
ports:
- containerPort: 5000
- name: esp
image: gcr.io/endpoints-release/endpoints-runtime:1
args: [
"--http_port=8081",
"--backend=127.0.0.1:5000",
"--service=api.endpoints.gcp-project.cloud.goog",
"--rollout_strategy=managed"
]
ports:
- containerPort: 8081
kind: Service
metadata:
name: "api1-lb"
namespace: development
annotations:
cloud.google.com/load-balancer-type: "Internal"
spec:
type: LoadBalancer
# loadBalancerIP: "172.30.33.221"
selector:
app: api1
ports:
- protocol: TCP
port: 80
targetPort: 8081
我为 api 服务的 Flask 应用程序是这个 app.py
app = Flask(__name__)
categorizador = Categorizador(model_properties.paths)
@app.route('/postoperation', methods=['POST'])
def postoperation():
text = request.get_json().get('text', '')
dni = request.get_json().get('dni', '')
tipo_dni = request.get_json().get('tipo_dni', '')
categoria,subcategoria = categorizador.categorizar(text)
content = {
'tipodni': tipo_dni,
'dni': dni,
'text': text,
'mundo': str(categoria),
'cluster': str(subcategoria),
'equipo': '',
'complejidad': ''
}
return jsonify(content)
来自kubectl expose -h
的一些位
--port=''
- 服务应该服务的端口。从公开的资源中复制,如果未指定
--target-port=''
- 服务应将流量定向到的容器上端口的名称或编号。
可选。
当代理将您的流量定向到 --backend=127.0.0.1:5000
时,请使用容器名称 isstead --backend=api-container:5000
。
看来您需要在 Flask 应用中配置路由。
试试这个:
@app.route('/v1/postoperation', methods=['POST'])
404 响应 Method: 1.api_endpoints_gcp_project_cloud_goog.Postoperation failed: NOT_FOUND
google 云端点 esp
我正在尝试通过 GKE 将我的 API 与 google 云端点部署在一起。我在 Produced API 日志中收到此错误,其中显示:
Method: 1.api_endpoints_gcp_project_cloud_goog.Postoperation failed: NOT_FOUND
我从端点收到 404 响应。
后端容器正确回答,但是当我尝试 post http://[service-ip]/v1/postoperation 时出现 404 错误。我猜它与 api_method 名称有关,但我已经更改,所以它在 openapi.yaml、gke 部署和 app.py.
中是相同的我使用 openapi.yaml:
成功部署了 API 服务swagger: "2.0"
info:
description: "API rest"
title: "API example"
version: "1.0.0"
host: "api.endpoints.gcp-project.cloud.goog"
basePath: "/v1"
# [END swagger]
consumes:
- "application/json"
produces:
- "application/json"
schemes:
# Uncomment the next line if you configure SSL for this API.
#- "https"
- "http"
paths:
"/postoperation":
post:
description: "Post operation 1"
operationId: "postoperation"
produces:
- "application/json"
responses:
200:
description: "success"
schema:
$ref: "#/definitions/Model"
400:
description: "Error"
parameters:
- description: "Description"
in: body
name: payload
required: true
schema:
$ref: "#/definitions/Resource"
definitions:
Resource:
type: "object"
required:
- "text"
properties:
tipodni:
type: "string"
dni:
type: "string"
text:
type: "string"
Model:
type: "object"
properties:
tipodni:
type: "string"
dni:
type: "string"
text:
type: "string"
mundo:
type: "string"
cluster:
type: "string"
equipo:
type: "string"
complejidad:
type: "string"
然后我尝试用这个 deploy.yaml 和 lb-deploy.yaml
配置后端和 espapiVersion: apps/v1 # for versions before 1.9.0 use apps/v1beta2
kind: Deployment
metadata:
name: api-deployment
namespace: development
spec:
strategy:
type: Recreate
selector:
matchLabels:
app: api1
replicas: 2 # tells deployment to run 2 pods matching the template
template:
metadata:
labels:
app: api1
spec:
volumes:
- name: google-cloud-key
secret:
secretName: secret-key
containers:
- name: api-container
image: gcr.io/gcp-project/docker-pqr:IMAGE_TAG_PLACEHOLDER
volumeMounts:
- name: google-cloud-key
mountPath: /var/secrets/google
ports:
- containerPort: 5000
- name: esp
image: gcr.io/endpoints-release/endpoints-runtime:1
args: [
"--http_port=8081",
"--backend=127.0.0.1:5000",
"--service=api.endpoints.gcp-project.cloud.goog",
"--rollout_strategy=managed"
]
ports:
- containerPort: 8081
kind: Service
metadata:
name: "api1-lb"
namespace: development
annotations:
cloud.google.com/load-balancer-type: "Internal"
spec:
type: LoadBalancer
# loadBalancerIP: "172.30.33.221"
selector:
app: api1
ports:
- protocol: TCP
port: 80
targetPort: 8081
我为 api 服务的 Flask 应用程序是这个 app.py
app = Flask(__name__)
categorizador = Categorizador(model_properties.paths)
@app.route('/postoperation', methods=['POST'])
def postoperation():
text = request.get_json().get('text', '')
dni = request.get_json().get('dni', '')
tipo_dni = request.get_json().get('tipo_dni', '')
categoria,subcategoria = categorizador.categorizar(text)
content = {
'tipodni': tipo_dni,
'dni': dni,
'text': text,
'mundo': str(categoria),
'cluster': str(subcategoria),
'equipo': '',
'complejidad': ''
}
return jsonify(content)
来自kubectl expose -h
--port=''
- 服务应该服务的端口。从公开的资源中复制,如果未指定--target-port=''
- 服务应将流量定向到的容器上端口的名称或编号。 可选。
当代理将您的流量定向到 --backend=127.0.0.1:5000
时,请使用容器名称 isstead --backend=api-container:5000
。
看来您需要在 Flask 应用中配置路由。 试试这个:
@app.route('/v1/postoperation', methods=['POST'])