Javascript content (DT, Leaflet) does not load on Google Cloud Kubernetes

I am facing some issues that Javscript-related content like DT datatables or leaflet maps sometimes do not load in my shiny app deployed with Kubernetes on Google Cloud.

In the browser console I see 404 ressource not found error codes.

The error seems to be stochastic as sometimes everything is correctly displayed. It may be linked with the Load Balancer I think. Does anyone has any ideas how to fix this?

Example app is here

So, what I think is causing this is missing session affinity. A request is send to a different pod, where the ressources are then not found resulting in the 404 errors. Can anybody confirm that I need session affinity for shiny apps?

What I read is that session affinity won't work with services of type NodePort unless using the nginx ingress type in Kubernetes. So I tried to configure an nginx ingress, but I am stuck, what annotations I have to set.

This is the config I tried:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: shiny
  labels:
    app: shiny
spec:
  replicas: 1
  selector:
    matchLabels:
      app: shiny
  template:
    metadata:
      labels:
        app: shiny
    spec:
      containers:
      - name: shiny
        image: rocker/shiny:3.6.1
        ports:
        - containerPort: 3838
---
kind: Service
apiVersion: v1
metadata:
  name: shiny
spec:
  selector:
    app: shiny
  type: NodePort
  ports:
  - protocol: TCP
    port: 80
    targetPort: 3838
---
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  name: shiny-ingress
  annotations:
    kubernetes.io/ingress.class: "nginx"
    nginx.ingress.kubernetes.io/affinity: "cookie"
    nginx.ingress.kubernetes.io/session-cookie-expires: "86400"
    nginx.ingress.kubernetes.io/session-cookie-max-age: "86400"
    nginx.ingress.kubernetes.io/ssl-redirect: "false"
    nginx.ingress.kubernetes.io/affinity-mode: persistent
    nginx.ingress.kubernetes.io/session-cookie-hash: sha1
spec:
  rules:
  - host: www.example.com
    http:
      paths:
      - backend:
          serviceName: shiny-service
          servicePort: 80

I have read I'm losing my mind with shiny + Kubernetes which seems to be a similar issue. Not sure, how to get my app running, so any help is appreciated!

This topic was automatically closed 54 days after the last reply. New replies are no longer allowed.