GCE ingress multi-path wildcard issue

8/21/2018

I have configured my Kubernetes cluster in GCP as follows,

ingress.yaml

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
 name: test-ingress
 annotations:
   kubernetes.io/ingress.class: "gce"
   kubernetes.io/ingress.global-static-ip-name: "ip-name"
   ingress.kubernetes.io/rewrite-target: "/"
   kubernetes.io/ingress.allow-http: "true"
spec:
  backend:
    serviceName: default-http-backend
    servicePort: 80
  rules:
  - http:
     paths:
     - path: /myService/*
       backend:
         serviceName: my-service
         servicePort: 80

app.yaml

apiVersion: extensions/v1beta1
  kind: Deployment
  metadata:
    name: my-service
    labels:
      app: my-service
  spec:
    replicas: 3
    template:
      metadata:
        labels:
          app: my-service
      spec:
        containers:
          - image: gcr.io/project_name7/my-service:6.0
            imagePullPolicy: Always
            name: my-service
            ports:
              - containerPort: 4000
            readinessProbe:
              httpGet:
                path: /healthz
                port: 4000
              periodSeconds: 1
              timeoutSeconds: 1
              successThreshold: 1
              failureThreshold: 10
  ---
  apiVersion: v1
  kind: Service
  metadata:
    name: my-service
    labels:
      k8s-app: my-service
  spec:
    type: NodePort
    ports:
      - name: my-service
        port: 80
        protocol: TCP
        targetPort: 4000
    selector:
      app: my-service

default-backend.yaml

apiVersion: extensions/v1beta1
    kind: Deployment
    metadata:
      name: default-http-backend
    spec:
      replicas: 1
      template:
        metadata:
          labels:
            app: default-http-backend
        spec:
          terminationGracePeriodSeconds: 60
          containers:
          - name: default-http-backend
            # Any image is permissable as long as:
            # 1. It serves a 404 page at /
            # 2. It serves 200 on a /healthz endpoint
            image: gcr.io/google_containers/defaultbackend:1.4
            livenessProbe:
              httpGet:
                path: /healthz
                port: 8080
                scheme: HTTP
              initialDelaySeconds: 30
              timeoutSeconds: 5
            ports:
            - containerPort: 8080
            resources:
              limits:
                cpu: 10m
                memory: 20Mi
              requests:
                cpu: 10m
                memory: 20Mi
    ---
    kind: Service
    apiVersion: v1
    metadata:
      name: default-http-backend
    spec:
      selector:
        app: default-http-backend
      ports:
        - protocol: TCP
          port: 80
          targetPort: 8080
      type: NodePort

My health check is all good, the load balancer is up and running. I can hit default-backend also. but when I try to hit,

GET http://ingress-ip/myService/api/test

I get the following error in postman with 404 Statuscode,

        <!DOCTYPE html>
    <html lang="en">
        <head>
            <meta charset="utf-8">
            <title>Error</title>
        </head>
        <body>
            <pre>Cannot GET /myService/api/test</pre>
        </body>
    </html>

But the API is available in the service, When I switch the service from NodePort to LoadBalancer, I can access the API with the LoadBalancer IP. Can anyone help me with this issue? How to resove the wildcard or how can I access my API?

-- NitinD
google-cloud-platform
google-kubernetes-engine
kubernetes
kubernetes-ingress

1 Answer

8/21/2018

GCE ingress doesn't support ingress.kubernetes.io/rewrite-target, so your application pod is receiving paths of the form /myService/api/test, and it's returning the HTTP/404 because of that.

-- Marcin Romaszewicz
Source: StackOverflow