<p>I have configured my Kubernetes cluster in GCP as follows,</p>

<p><strong>ingress.yaml</strong></p>

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

<p><strong>app.yaml</strong></p>

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

<p><strong>default-backend.yaml</strong></p>

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

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

<pre><code>GET http://ingress-ip/myService/api/test
</code></pre>

<p>I get the following error in postman with 404 Statuscode, </p>

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

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

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