google cloud endpoints api_method not found on gke

11/14/2019

404 response Method: 1.api_endpoints_gcp_project_cloud_goog.Postoperation failed: NOT_FOUND on google cloud endpoints esp

I'm trying to deploy my API with google cloud endpoints with my backend over GKE. I'm getting this error on the Produced API logs, where shows:

Method: 1.api_endpoints_gcp_project_cloud_goog.Postoperation failed: NOT_FOUND

and i'm getting a 404 responde from the endpoint.

The backend container is answering correctly, but when i try to post http://[service-ip]/v1/postoperation i get the 404 error. I'm guessing it's related with the api_method name but i've already changed so it's the same in the openapi.yaml, the gke deployment and the app.py.

I deployed the API service succesfully with this openapi.yaml:

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"

Then i tried to configure the backend and esp with this deploy.yaml and lb-deploy.yaml

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

my flask app that serves the api, is this 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)
-- Gleiwer Montoya
flask
google-cloud-endpoints
google-cloud-platform
google-kubernetes-engine
kubernetes

2 Answers

11/15/2019

Looks like you need to configure route in your flask app. Try this:

@app.route('/v1/postoperation', methods=['POST'])
-- Emil Gi
Source: StackOverflow

11/15/2019

Some bits from kubectl expose -h

  • --port='' - The port that the service should serve on. Copied from the resource being exposed, if unspecified
  • --target-port='' - Name or number for the port on the container that the service should direct traffic to. Optional.

While proxy directing your trafic to --backend=127.0.0.1:5000, use container name isntead --backend=api-container:5000.

-- Oleg Butuzov
Source: StackOverflow