TandoorRecipes / recipes

Application for managing recipes, planning meals, building shopping lists and much much more!
https://docs.tandoor.dev
Other
5.35k stars 563 forks source link

root_path for hosting with prefix in Kubernetes #2903

Open Phil997 opened 8 months ago

Phil997 commented 8 months ago

Issue

hello

I would like to host the app in Kubernetes behind an Ingress route the traffic with PathPrefixes.

I have rent a server on which I installed Kubernetes with kind. I want to run several applications in the Kubernetes cluster and reach them all over the same address. I want to differentiate the applications with a sub-paths in the url. Unfortunately, I cannot use a subdomain or connect additional domains to the cluster, as this lead to additional costs and I want to keep them as low as possible. (It's only for my private projects)

I want to make the app accessible under this url: my-website.de/tandoor

The way I have currently set it up in my Ingress, I get to the main page, but when I click on for example the meal plan, I get redirected to my-website.de/plan/ and get a 404 error. To make it work, I need to be redirected to my-website.com/tandoor/plan/.

Is there a way to set the root_path for the app?

Here is my ingress.yaml:

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: main-ingress
  #annotations:
  #  nginx.ingress.kubernetes.io/rewrite-target: /
  #  nginx.ingress.kubernetes.io/ssl-redirect: "false"
spec:
  tls:
  - hosts:
    - my-website.de
    secretName: letsencrypt-cert-prod
  rules:
  - host: my-website.de
    http:
      paths:
      - backend:
          service:
            name: recipes
            port:
              number: 8080
        path: /tandoor
        pathType: Prefix
      - backend:
          service:
            name: recipes
            port:
              number: 80
        path: /tandoor/media
        pathType: Prefix
      - backend:
          service:
            name: recipes
            port:
              number: 80
        path: /tandoor/static
        pathType: Prefix

PS: I use the current example manifests from /docs/install/k8s. There is no .env file given which i could mount to my Pod

Tandoor Version

1.5.10

OS Version

Kubernetes with Kind==0.11.1

Setup

Kubernetes

Reverse Proxy

No reverse proxy

Other

ingress nginx controller v1.9.5

Environment file

No response

Docker-Compose file

No response

Relevant logs

No response

smilerz commented 8 months ago

I can't help with kubernetes specifically, but you have to set SCRIPT_NAME=/tandoor in the env and the following host headers

    proxy_set_header X-Script-Name /tandoor ;
    proxy_cookie_path / /tandoor ;
Phil997 commented 8 months ago

ok i can set the SCRIPT_NAME env to /tandoor in the deployment.yaml

Here is a snipped from the deployment.yaml with the SCRIPT_NAME setting:

      - name: recipes
        image: vabene1111/recipes:1.5.10
        command:
          - /opt/recipes/venv/bin/gunicorn
          - -b
          - :8080
          - --access-logfile
          - "-"
          - --error-logfile
          - "-"
          - --log-level
          - INFO
          - recipes.wsgi
        volumeMounts:
          ...
        env:
          - name: DEBUG
            value: "0"
          - name: ALLOWED_HOSTS
            value: '*'

          # ... skip a few envs

          # here the new envs:
          - name: SCRIPT_NAME
            value: /tandoor

Can I give the proxy_set_header and proxy_cookie_path as envs to the app, too, like this:

          ...
        env:
          # ... skip a few envs

          # here the new envs:
          - name: SCRIPT_NAME
            value: /tandoor
          - name: proxy_set_header 
            value: "X-Script-Name /tandoor"
          - name: proxy_cookie_path 
            value: /tandoor

or do I have to write it to a config file and then pass the config file to the app?

smilerz commented 8 months ago

Tandoor just needs the SCRIPT_NAME env variable - can't help with whatever reverse proxy you are using