Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting up a Kuberentes cluster with HTTP Load balancing ingress for RStudio and Shiny results in error pages

I'm attempting to create a cluster on Google Kubernetes Engine that runs nginx, RStudio server and two Shiny apps, following and adapting this guide.

I have 4 workloads that are all green in the UI, deployed via:

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

They were then all exposed as node ports via:

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

..that are all green in the UI.

I then deployed this Ingress backend

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

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:

  • /rstudio/ - Input/output error
  • /shiny1/ - Page not found (the Shiny 404 page)
  • /shiny5/ - Page not found (the Shiny 404 page)

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

Can anyone point to where I'm going wrong?

Qs:

  • 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
  • Both RStudio and Shiny need websockets - does this affect this?
  • Does session affinity need to be on? I tried adding that with IP but same errors.
like image 847
MarkeD Avatar asked Jan 25 '18 21:01

MarkeD


2 Answers

As Radek suggested, ingress.kubernetes.io/rewrite-target: / 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.

Instead, on GKE, you must use an nginx ingress controller.

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

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/*
like image 100
Rhys Jackson Avatar answered Nov 15 '22 23:11

Rhys Jackson


the most likely problem you have is that when you go with this ingress you attached your URI is different then with direct accesc ( /shiny1/ vs / ) so your app is lost and has no content for that uri.

With Nginx Ingress Controller you can use ingress.kubernetes.io/rewrite-target: / annotation to mitigate this and make sure that / is accessed even when there is a subfolder in the ingress path.

like image 23
Radek 'Goblin' Pieczonka Avatar answered Nov 15 '22 22:11

Radek 'Goblin' Pieczonka