404响应Method: 1.api_endpoints_gcp_project_cloud_goog.Postoperation failed: NOT_FOUND
我正在尝试将我的API与Google Cloud端点一起通过GKE后端进行部署。我在生产的API日志中看到此错误,显示如下:
Method: 1.api_endpoints_gcp_project_cloud_goog.Postoperation failed: NOT_FOUND
我从端点收到404响应。
后端容器正确回答,但是当我尝试发布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)