<p>I use GCE and try to expose an application via ingress. But path rules don't work.</p>

<pre><code>apiVersion: extensions/v1beta1
kind: Ingress
metadata:
    name: front-ingress
    namespace: {{ .Release.Namespace }}
    annotations:
        {{ if eq .Values.env "dev" }}
        kubernetes.io/ingress.global-static-ip-name: "test-ip"
        {{ else }}
        cloud.google.com/load-balancer-type: "Internal"
        {{ end }}
spec:
    rules:
    -   host: {{ .Values.domain }}
        http:
            paths:
            -   path: /
                backend:
                    serviceName: front-service
                    servicePort: 80
            -   path: /api/
                backend:
                    serviceName: backend-service
                    servicePort: 80
</code></pre>

<p>When site opened in browser - all files return 404. When I open file by url, I receive: default backend - 404. If I set default backend via annotations - all files loaded, but /api requests failed - 404 error.</p>

<p>What it can be?</p>

<p>The main idea: test branch on site subdomain. k8s namespace = branch name. Ingress deployed to every namespace with a different host in rules. Global static IP set by annotation and set in GCE Cloud DNS.</p>

<p>Thanks.</p>

<p>UPDATE:</p>

<p>If I use annotation <code>kubernetes.io/ingress.class: "gce"</code> and path: /* and /api/* - site works perfectly. But because I use global static IP, I can't create more than one ingress per IP. If I use <code>kubernetes.io/ingress.class: "nginx"</code> - site returns error: <code>default backend - 404</code></p>

Serhii Koberniuk
<p>You can actually create multiple ingresses using the same external IP address. You just have to make sure that they are under different host (or hostname rules), so the paths don't interfere with each other. Every host represents a <a href="https://nginx.org/en/docs/http/ngx_http_core_module.html#server" rel="nofollow noreferrer">server {}</a> block in the nginx configs with a unique <code>server_name</code>.</p>

<p>Ingress1:</p>

<pre><code>spec:
    rules:
    -   host: host1.domain1
        http:
            paths:
            -   path: /
                backend:
                    serviceName: front-service1
                    servicePort: 80
            -   path: /api/
                backend:
                    serviceName: backend-service1
                    servicePort: 80
</code></pre>

<p>Ingress2:</p>

<pre><code>-   host: host2.domain2
        http:
            paths:
            -   path: /
                backend:
                    serviceName: front-service2
                    servicePort: 80
            -   path: /api/
                backend:
                    serviceName: backend-service2
                    servicePort: 80
</code></pre>

<p>If you want to use an externalIP it's still doable, but you just have to use a separate ingress controller with a different ingress class name. For example, with the <a href="https://github.com/kubernetes/ingress-nginx" rel="nofollow noreferrer">nginx ingress controller</a> you can use the <a href="https://kubernetes.github.io/ingress-nginx/user-guide/cli-arguments/" rel="nofollow noreferrer"><code>--ingress-class</code></a> option:</p>

<p><a href="https://i.stack.imgur.com/5Pidk.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/5Pidk.png" alt="ingress class"></a></p>

<p>Also if you don't specify an <code>--ingress-class</code> in your first ingress controller you will have to configure it too, otherwise like the option says, the first ingress will satisfy all the classes.</p>
