<p>I have two pods, each with a LoadBalancer svc. Each service's IP address is working.</p>
<p>My first service is:</p>
<pre><code>apiVersion: v1
kind: Service
metadata:
  name: hello-world-1
spec:
  type: LoadBalancer
  selector:
    greeting: hello
    version: one
  ports:
  - protocol: TCP
    port: 60000
    targetPort: 50000
</code></pre>
<p>My second service is:</p>
<pre><code>apiVersion: v1
kind: Service
metadata:
  name: hello-world-2
spec:
  type: LoadBalancer
  selector:
    greeting: hello
    version: two
  ports:
  - protocol: TCP
    port: 5000
    targetPort: 5000
</code></pre>
<p>My ingress is:</p>
<pre><code>apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: my-ingress
  annotations:
    kubernetes.io/ingress.class: gce
spec:
  defaultBackend:
    service:
      name: hello-world-1
      port:
        number: 60000
  rules:
  - http:
      paths:
      - path: /
        pathType: ImplementationSpecific
        backend:
          service:
            name: hello-world-1
            port:
              number: 60000
      - path: /v2
        pathType: ImplementationSpecific
        backend:
          service:
            name: hello-world-2
            port:
              number: 5000
</code></pre>
<p>Only the first route works this way and when I put</p>
<pre><code>&lt;MY_IP&gt;/v2
</code></pre>
<p>in the url bar I get</p>
<pre><code>Cannot GET /v2
  
</code></pre>
<p>How do I configure the ingress so it hits the / route when no subpath is specified and the /v2 route when /v2 is specified?</p>
<p>If I change the first route to</p>
<pre><code>backend:
          service:
            name: hello-world-2
            port:
              number: 5000
</code></pre>
<p>and get rid of the second one it works.</p>
<p>but if I change the route to /v2 it stops working?</p>
<p>***** EDIT *****</p>
<p>Following this tutorial here <a href="https://cloud.google.com/kubernetes-engine/docs/tutorials/http-balancer" rel="nofollow noreferrer">ingress tut</a> I tried changing the yaml so the different routes were on different ports and this breaks it. Does anybody know why?</p>

<p>By default, when you create an ingress in your cluster, GKE creates an HTTP(S) load balancer and configures it to route traffic to your application, as stated in the following document [1]. So, you should not be configuring your services as LoadBalancer type, instead you need to configure them as NodePort.</p>
<p>Here, you can follow an example of a complete implementation similar to what you want to accomplish:</p>
<ol>
<li>Create a manifest that runs the application container image in the specified port, for each version:</li>
</ol>
<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: web1
  namespace: default
spec:
  selector:
    matchLabels:
      run: web1
  template:
    metadata:
      labels:
        run: web1
    spec:
      containers:
      - image: gcr.io/google-samples/hello-app:1.0
        imagePullPolicy: IfNotPresent
        name: web1
        ports:
        - containerPort: 8000
          protocol: TCP

---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: web2
  namespace: default
spec:
  selector:
    matchLabels:
      run: web2
  template:
    metadata:
      labels:
        run: web2
    spec:
      containers:
      - image: gcr.io/google-samples/hello-app:2.0
        imagePullPolicy: IfNotPresent
        name: web2
        ports:
        - containerPort: 9000
          protocol: TCP
</code></pre>
<ol start="2">
<li>Create two services (one for each version) as type <strong>NodePort</strong>. A very important note at this step, is that the <strong>targetPort</strong> specified should be the one the application is listening on, in my case both services are pointing to port 8080 since I am using the same application but different versions:</li>
</ol>
<pre><code>apiVersion: v1
kind: Service
metadata:
  name: web1
  namespace: default
spec:
  ports:
  - port: 8000
    protocol: TCP
    targetPort: 8080
  selector:
    run: web1
  type: NodePort

---
apiVersion: v1
kind: Service
metadata:
  name: web2
  namespace: default
spec:
  ports:
  - port: 9000
    protocol: TCP
    targetPort: 8080
  selector:
    run: web2
  type: NodePort
</code></pre>
<ol start="3">
<li>Finally, you need to create the ingress with the path rules:</li>
</ol>
<pre><code>apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: my-ingress
  annotations:
    kubernetes.io/ingress.class: gce
spec:
  defaultBackend:
    service:
      name: web1
      port:
        number: 8000
  rules:
  - http:
      paths:
      - path: /
        pathType: ImplementationSpecific
        backend:
          service:
            name: web1
            port:
              number: 8000
      - path: /v2
        pathType: ImplementationSpecific
        backend:
          service:
            name: web2
            port:
              number: 9000
</code></pre>
<p>If you configured everything correctly, the output of the command <strong>kubectl get ingress my-ingress</strong> should be something like this:</p>
<pre><code>NAME         CLASS    HOSTS   ADDRESS          PORTS   AGE
my-ingress   &lt;none&gt;   *       &lt;External IP&gt;    80      149m
</code></pre>
<p>And, if your services are pointing to the correct ports, and your applications are listening on those ports, doing a curl to your external ip (<strong>curl External IP</strong>) should get you to the version one of your application, here is my example output:</p>
<pre><code>Hello, world!
Version: 1.0.0
Hostname: web1-xxxxxxxxxxxxxx
</code></pre>
<p>Doing a curl to your external ip /v2 (<strong>curl External IP/v2</strong>) should get you to the version two of your application:</p>
<pre><code>Hello, world!
Version: 2.0.0
Hostname: web2-xxxxxxxxxxxxxx
</code></pre>
<p>[1] <a href="https://cloud.google.com/kubernetes-engine/docs/tutorials/http-balancer" rel="nofollow noreferrer">https://cloud.google.com/kubernetes-engine/docs/tutorials/http-balancer</a></p>
