I've a Kubernetes cluster on GKE that has a nginx ingress controller sitting on top to mapping the RStudio Server endpoint under /rstudio/. This works quite well.
Unfortunately, one of my deployments (RStudio Server) doensn't work properly because it uses client-side redirects during the login/logout which end ups in 404 error when trying to access /auth-login (it should be /rstudio/auth-login)
In the past, when using a non-containerized install of RStudio Server, I used to sit an Apache reverse proxy on front to handle url rewrites.
From the official RStudio Server Pro guide i see that adding this location
section to nginx.conf
should solve the problem.
location /rstudio/ {
rewrite ^/rstudio/(.*)$ /$1 break;
proxy_pass http://localhost:8787;
proxy_redirect http://localhost:8787/ $scheme://$host/rstudio/;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
proxy_read_timeout 20d;
}
Can I use annotation on ingress controller to obtain the same results?
Although this doesn't end up with the same nginx.conf
content, it seems to work. But i don't know if it could cause some side-effects (tested with one pod only atm).
Maybe others would help commenting the answer about...
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: rstudio-ingress-nginx
annotations:
kubernetes.io/ingress.class: nginx
nginx.ingress.kubernetes.io/rewrite-target: /
nginx.ingress.kubernetes.io/ssl-redirect: "false"
nginx.ingress.kubernetes.io/add-base-url: "true"
nginx.ingress.kubernetes.io/proxy-redirect-from: "$scheme://$host/"
nginx.ingress.kubernetes.io/proxy-redirect-to: "$scheme://$host/rstudio/"
nginx.ingress.kubernetes.io/proxy-read-timeout: 20d
nginx.ingress.kubernetes.io/affinity: "cookie"
nginx.ingress.kubernetes.io/session-cookie-name: "route"
nginx.ingress.kubernetes.io/session-cookie-hash: "sha1"
spec:
rules:
- http:
paths:
- path: /rstudio/
backend:
serviceName: rstudio
servicePort: 8787