Scripts and css not reachable after deploying Tiledesk with Kong as Load Balancer

73 Views Asked by At

I'm trying to deploy tiledesk to my kubernetes. The helm chart uses Nginx as load balancer, but I use Kong in my cluster, so, I try to adapt.

Helm chart ingress is defined as follows:

ingress:
  enabled: true  
  annotations:
    kubernetes.io/ingress.class: nginx #deprecated
    nginx.ingress.kubernetes.io/proxy-body-size: "50m"
    nginx.ingress.kubernetes.io/rewrite-target: /$1
    nginx.ingress.kubernetes.io/enable-cors: "true"
    nginx.ingress.kubernetes.io/configuration-snippet: |
      rewrite ^/firebase-messaging-sw.js /chat/firebase-messaging-sw.js last;
  hosts:
    hostip: 
      name:
      enabled: true
      paths: 
        - path: /api/(.*)
          service: server
        - path: /ws/(.*)
          service: server
        - path: /dashboard/(.*)
          service: dashboard
        - path: /cds/(.*)
          service: cds
        - path: /chat/(.*)
          service: ionic
        - path: /widget/(.*)
          service: webwidget
        - path: /widget-config.json
          service: webwidget
        - path: /mqws/(.*)
          service: rabbitmq
          servicePort: 15675
        # - path: /mq
        #   service: rabbitmq
        - path: /chatapi/(.*)
          service: c21httpsrv
    hostconsole:
      name: console.tiledesk.local
      enabled: true
      paths: 
        - path: /api/(.*)
          service: server
        - path: /ws/(.*)
          service: server
        - path: /dashboard/(.*)
          service: dashboard
        - path: /cds/(.*)
          service: cds
        - path: /chat/(.*)
          service: ionic
        - path: /widget/(.*)
          service: webwidget
        - path: /widget-config.json
          service: webwidget
        - path: /mqws/(.*)
          service: rabbitmq
          servicePort: 15675
        # - path: /mq/(.*)
        #   service: rabbitmq
        - path: /chatapi/(.*)
          service: c21httpsrv
    hostapi: 
      name: api.tiledesk.local
      enabled: false
      paths: 
        - path: /(.*)
          service: server
    hostrtm: 
      name: rtm.tiledesk.local
      enabled: false
      paths: 
        - path: /(.*)
          service: server
    hostwidget:
      name: widget.tiledesk.local 
      enabled: false
      paths: 
        - path: /(.*)
          service: webwidget
  tls: []
    #  - secretName: tiledesk-tls-secret
    #    hosts:
    #      - console.tiledesk.local
    #      - api.tiledesk.local

Than, I try to write a Kong Ingress file that does the same routes:

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: tiledesk-proxy-kong
  annotations:
    kubernetes.io/tls-acme: "true"
    cert-manager.io/cluster-issuer: letsencrypt
    kubernetes.io/ingress.class: kong
    konghq.com/override: tiledesk-proxy-kong
    konghq.com/strip-path: "true"
    konghq.com/preserve-host: "true"
spec:
  rules:
  - http:
      paths:
      - backend:
          service:
            name: tiledesk-server
            port:
              number: 80
        path: /api
        pathType: Prefix
      - backend:
          service:
            name: tiledesk-server
            port:
              number: 80
        path: /ws
        pathType: Prefix
      - backend:
          service:
            name: tiledesk-dashboard
            port:
              number: 80
        path: /dashboard
        pathType: Prefix
      - backend:
          service:
            name: tiledesk-cds
            port:
              number: 80
        path: /cds
        pathType: Prefix
      - backend:
          service:
            name: tiledesk-ionic
            port:
              number: 80
        path: /chat
        pathType: Prefix
      - backend:
          service:
            name: tiledesk-webwidget
            port:
              number: 80
        path: /widget
        pathType: Prefix
      - backend:
          service:
            name: tiledesk-webwidget
            port:
              number: 80
        path: /widget-config.json
        pathType: Prefix
      - backend:
          service:
            name: tiledesk-rabbitmq
            port:
              number: 15675
        path: /mqws
        pathType: Prefix
      - backend:
          service:
            name: tiledesk-c21httpsrv
            port:
              number: 80
        path: /chatapi
        pathType: Prefix

but, after applying, tiledesk is accessible throw [address]/dashboard/ but it does not load correctly. After some debug I see that javascript and css are not loading. I try to solve using combinations of strip-path and preserve-host, but none worked.

How can I solve this?

1

There are 1 best solutions below

0
VonC On BEST ANSWER

In the Nginx configuration, the use of rewrite-target and specific rewrite rules are important for serving static content correctly, which might not be directly replicable in Kong Ingress Controller without some adjustments.

When adapting to Kong, you have attempted to mirror this setup but faced issues with static content not loading. I suppose Kong's strip-path and preserve-host annotations, although somewhat similar, do not offer the same level of control over request paths as Nginx's rewrite rules. You might also need to use more specific path routing or even custom Kong plugins (as seen in issue 568) if the default behavior does not match your needs.

When strip-path is set to true, Kong removes the matched part of the path before forwarding the request to the upstream service. That can cause issues if the application expects the original path. Experiment with setting strip-path to false for routes serving static content to see if it resolves the issue (it is normally disabled by default).

If specific static content is not loading, consider adding more specific routes for those assets in your Kong Ingress. That might mean creating dedicated routes for commonly missed asset folders like /css, /js, etc., and making sure they point to the correct service capable of serving them.

For instance, if you are facing issues with a specific type of static content (say, CSS files not loading from a certain path), you could add a more specific route to your Kong Ingress like this:

- backend:
    service:
      name: tiledesk-webwidget
      port:
        number: 80
  path: /widget/css
  pathType: Prefix

And make sure strip-path is configured appropriately for this route.