<p><strong>404 response <code>Method: 1.api_endpoints_gcp_project_cloud_goog.Postoperation failed: NOT_FOUND</code> on google cloud endpoints esp</strong></p>

<p>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:</p>

<p><code>Method: 1.api_endpoints_gcp_project_cloud_goog.Postoperation failed: NOT_FOUND</code></p>

<p>and i'm getting a 404 responde from the endpoint.</p>

<p>The backend container is answering correctly, but when i try to post <a href="http://[service-ip]/v1/postoperation" rel="nofollow noreferrer">http://[service-ip]/v1/postoperation</a> 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.</p>

<p>I deployed the API service succesfully with this openapi.yaml:</p>

<pre><code>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"
</code></pre>

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

<pre><code>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
</code></pre>

<p>my flask app that serves the api, is this app.py</p>

<pre><code>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)
</code></pre>

<p>Some bits from <code>kubectl expose -h</code></p>

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

<p>While proxy directing your trafic to <code>--backend=127.0.0.1:5000</code>, use container name isntead <code>--backend=api-container:5000</code>.</p>
