<p>I'm attempting to create a cluster on Google Kubernetes Engine that runs nginx, RStudio server and two Shiny apps, following and adapting <a href="https://cloud.google.com/kubernetes-engine/docs/tutorials/http-balancer" rel="noreferrer">this guide</a>.</p>

<p>I have 4 workloads that are all green in the UI, deployed via:</p>

<pre><code>kubectl run nginx --image=nginx --port=80
kubectl run rstudio --image gcr.io/gcer-public/persistent-rstudio:latest --port 8787
kubectl run shiny1 --image gcr.io/gcer-public/shiny-googleauthrdemo:latest --port 3838
kubectl run shiny5 --image=flaviobarros/shiny-wordcloud --port=80
</code></pre>

<p>They were then all exposed as node ports via:</p>

<pre><code>kubectl expose deployment nginx --target-port=80  --type=NodePort
kubectl expose deployment rstudio --target-port=8787  --type=NodePort
kubectl expose deployment shiny1 --target-port=3838  --type=NodePort
kubectl expose deployment shiny5 --target-port=80  --type=NodePort
</code></pre>

<p>..that are all green in the UI.</p>

<p>I then deployed this Ingress backend</p>

<pre><code>apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: r-ingress
spec:
  rules:
  - http:
      paths:
      - path: /
        backend:
          serviceName: nginx
          servicePort: 80
      - path: /rstudio/
        backend:
          serviceName: rstudio
          servicePort: 8787
      - path: /shiny1/
        backend:
          serviceName: shiny1
          servicePort: 3838
      - path: /shiny5/
        backend:
          serviceName: shiny5
          servicePort: 80
</code></pre>

<p>The result is that the nginx routing works great, I can see "Welcome to nginx" webpage from home, but the three other paths I get:</p>

<ul>
<li>/rstudio/ - <code>Input/output error</code></li>
<li>/shiny1/ - Page not found (the Shiny 404 page)</li>
<li>/shiny5/ - Page not found (the Shiny 404 page)</li>
</ul>

<p>The RStudio and Shiny workloads both work when exposing via the single load balancer, mapped to 8787 and 3838 respectively.</p>

<p>Can anyone point to where I'm going wrong?</p>

<p>Qs:</p>

<ul>
<li>Do the Dockerfiles need to be adapted so they all give a 200 status on port 80 when requesting "/"?  Do I need to change the health checker?  I tried changing the RStudio login page (that 302 to /auth-sign-in if you are not logged in) but no luck</li>
<li>Both RStudio and Shiny need websockets - does this affect this?</li>
<li>Does session affinity need to be on?  I tried adding that with IP but same errors. </li>
</ul>

<p>As Radek suggested, <code>ingress.kubernetes.io/rewrite-target: /</code> is required to re-write your requests. However, this is not currently supported by the GKE ingress controller and is the reason that you're receiving 404 responses.</p>

<p>Instead, on GKE, you must use an <a href="https://github.com/kubernetes/ingress-nginx/blob/master/deploy/README.md" rel="nofollow noreferrer">nginx ingress controller</a>.</p>

<p>You will then be able to configure ingress for your rstudio and shiny images that obeys the rewrite rule:</p>

<pre><code>apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: r-ingress
  annotations:
    kubernetes.io/ingress.class: "nginx"
    nginx.ingress.kubernetes.io/rewrite-target: /
spec:
  rules:
  - http:
      paths:
      - backend:
          serviceName: rstudio
          servicePort: 8787
        path: /rstudio/*
      - backend:
          serviceName: shiny1
          servicePort: 3838
        path: /shiny1/*
      - backend:
          serviceName: shiny5
          servicePort: 80
        path: /shiny5/*
</code></pre>
