Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nginx: How to enable dashboard on a sub-path? #683

Closed
colemickens opened this issue May 3, 2017 · 18 comments
Closed

nginx: How to enable dashboard on a sub-path? #683

colemickens opened this issue May 3, 2017 · 18 comments
Labels
lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed.

Comments

@colemickens
Copy link
Contributor

This works, reliably:

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  annotations:
    kubernetes.io/ingress.class: "nginx"
  name: dashboard
  namespace: kube-system
spec:
  rules:
  - host: 'dashboard.domain.tld'
    http:
      paths:
      - path: /
        backend:
          serviceName: kubernetes-dashboard-head
          servicePort: 80

On the other hand, this only works with http://domain.tld/dashboard/ and not http://domain.tld/dashboard (note trailing slash). And adding/removing a trailing slash to the 'path' field of the yaml has no effect:

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  annotations:
    kubernetes.io/ingress.class: "nginx"
    ingress.kubernetes.io/rewrite-target: "/"
  name: dashboard
  namespace: kube-system
spec:
  rules:
  - host: 'domain.tld'
    http:
      paths:
      - path: /dashboard/
        backend:
          serviceName: kubernetes-dashboard-head
          servicePort: 80

(Note, the delta is the host, the path, and the rewrite-target annotation)

From reading the HTML source of dashboard, I understand why this is happening, but I'm not familiar enough with nginx/ingress to know what the right fix is...

@colemickens
Copy link
Contributor Author

colemickens commented May 4, 2017

It looks like when using kubectl proxy, this happens:

--2017-05-03 21:15:54--  http://10.0.0.2:9090/api/v1/namespaces/kube-system/services/kubernetes-dashboard-head/proxy
Connecting to 10.0.0.2:9090... connected.
HTTP request sent, awaiting response... 301 Moved Permanently
Location: /api/v1/namespaces/kube-system/services/kubernetes-dashboard-head/proxy/ [following]
--2017-05-03 21:15:54--  http://10.0.0.2:9090/api/v1/namespaces/kube-system/services/kubernetes-dashboard-head/proxy/
...

I guess I need a way to say "redirect path to path/" (maybe if the path in the spec has a trailing slash?), or an annotation for configuring a manual 301 for a given host/path. Thoughts on either of those @aledbf, or maybe I'm missing a more obvious way of accomplishing this goal?

@theobolo
Copy link

theobolo commented May 30, 2017

Hello @colemickens, you just have to define your Ingress rule like this :

 rules:
  - host: 'domain.tld'
    http:
      paths:
      - path: /dashboard
        backend:
          serviceName: kubernetes-dashboard-head
          servicePort: 80

Just remove the last / at path: /dashboard

Then go to http://domain.tld/dashboard/, should works, i'm using that config too.

@colemickens
Copy link
Contributor Author

But there's no automatic redirect. If you visit http://domain.tld/dashboard you get dropped on a blank white page.

@delacroixe
Copy link

The same happens to me. It doesn't redirect from path: "/whatever" to "/" inside the service. There is any way to redirect from specified path in the ingress file to the root path of the service?

@aledbf aledbf added this to TODO in nginx 0.9-beta.11 Jun 30, 2017
@aledbf aledbf added this to TODO in nginx 0.9-beta.12 Jul 14, 2017
@himikof
Copy link

himikof commented Aug 8, 2017

This seems related to issue #646, there are some workarounds there.

@fejta-bot
Copy link

Issues go stale after 90d of inactivity.
Mark the issue as fresh with /remove-lifecycle stale.
Stale issues rot after an additional 30d of inactivity and eventually close.

Prevent issues from auto-closing with an /lifecycle frozen comment.

If this issue is safe to close now please do so with /close.

Send feedback to sig-testing, kubernetes/test-infra and/or @fejta.
/lifecycle stale

@k8s-ci-robot k8s-ci-robot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Jan 2, 2018
@diwakar-s-maurya
Copy link

diwakar-s-maurya commented Jan 28, 2018

By borrowing idea from #646, following makes dashboard serve at /kube path with tls passthrough. It also redirects /kube to /kube/

cat <<EOF | kubectl apply -f -
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: kubernetes-dashboard
  namespace: kube-system
  annotations:
    kubernetes.io/ingress.class: "nginx"
    nginx.ingress.kubernetes.io/secure-backends: "true"
    ingress.kubernetes.io/ssl-passthrough: "true"
    nginx.ingress.kubernetes.io/rewrite-target: "/"
    # adds 301 redirect with trailing slash
    nginx.ingress.kubernetes.io/configuration-snippet: |
      rewrite ^(/kube)$ $1/kube/ permanent;
spec:
  tls:
  - hosts:
    - dashboard.domain.tld
  rules:
  - host: dashboard.domain.tld
    http:
      paths:
      - path: /kube
        backend:
          serviceName: kubernetes-dashboard
          servicePort: 443
EOF

@fejta-bot
Copy link

Stale issues rot after 30d of inactivity.
Mark the issue as fresh with /remove-lifecycle rotten.
Rotten issues close after an additional 30d of inactivity.

If this issue is safe to close now please do so with /close.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/lifecycle rotten
/remove-lifecycle stale

@k8s-ci-robot k8s-ci-robot added lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. and removed lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. labels Feb 27, 2018
@bfsmith
Copy link

bfsmith commented Mar 15, 2018

I'm seeing this issue and the rewrite doesn't seem to work with a non-standard port.

I'm using https://localhost:8002/dashboard to try and access the dashboard. The dashboard loads but fails to login, presumably related to how the dashboard does client-side routing. If I add a trailing slash, https://localhost:8002/dashboard/, I can login just fine.

Here's my yaml

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: kubernetes-dashboard
  namespace: kube-system
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: "/"
    nginx.ingress.kubernetes.io/add-base-url: "true"
    nginx.ingress.kubernetes.io/secure-backends: "true"
    nginx.ingress.kubernetes.io/configuration-snippet: rewrite ^(/dashboard)$ $1/ permanent;
spec:
  rules:
  - http:
      paths:
      - path: /dashboard
        backend:
          serviceName: kubernetes-dashboard
          servicePort: 443

That configuration takes my https://localhost:8002/dashboard and redirects me to https://localhost/dashboard/. Notice the port is now gone.

Removing "permanent" on the rewrite goes back to login not working.

@petergardfjall
Copy link

@bfsmith: I believe your issue (with non-standard port) is addressed by #2059

@fejta-bot
Copy link

Rotten issues close after 30d of inactivity.
Reopen the issue with /reopen.
Mark the issue as fresh with /remove-lifecycle rotten.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/close

@lxcyha
Copy link

lxcyha commented Jun 29, 2018

@bfsmith hi bfsmith, could you tell me how you solved this problem, please? I clicked #2059 but it didn't help .

@Queuecumber
Copy link

Queuecumber commented Aug 21, 2018

This should probably be reopened, it's kind of hilarious/sad that it can't handle a missing trailing '/' and it isnt at all obvious what is going wrong. Isn't this a bug on the dashboard side and not the ingress side though?

@mumubin
Copy link

mumubin commented Oct 8, 2019

The same issue, anyone has an example ingress configuration for subpath consul?

@grantsunny
Copy link

grantsunny commented Mar 17, 2020

Recently I upgraded the image to latest and encountered a regression. In short, new version of image for any reason added a unnecessary <base href="/"> and therefore hard-coded the assumption to have everything start from root directory.

As a result, it is no longer possible to enable the dashboard on sub-path. Please correct if I am wrong.

image kubernetesui/dashboard:v2.0.0-rc6 - it does not work as the base href configuration preventing the dashboard works under any sub path.

<head><base href="/">
  <meta charset="utf-8">
  <title>Kubernetes Dashboard</title>
  <link rel="icon"
        type="image/png"
        href="assets/images/kubernetes-logo.png" />
  <meta name="viewport"
        content="width=device-width">
<link rel="stylesheet" href="styles.fd5645b19f044bd0052c.css"></head>

image kubernetesui/dashboard:v2.0.0-rc5: it works fine

<head>
  <meta charset="utf-8">
  <title>Kubernetes Dashboard</title>
  <link rel="icon"
        type="image/png"
        href="assets/images/kubernetes-logo.png" />
  <meta name="viewport"
        content="width=device-width">
<link rel="stylesheet" href="styles.bb1efa96a359b8cd45d9.css"></head>

@vutny
Copy link

vutny commented Mar 24, 2020

kubernetes/dashboard#5017 (comment)

@grantsunny And that issue with hard base href should be already fixed in kubernetes/dashboard#5022 .

@grantsunny
Copy link

Thanks @vutny!

@peter-hartmann-emrsn
Copy link

Evil issue got this evil fix on my box ... no permanent redirect.

nginx.ingress.kubernetes.io/configuration-snippet: |
    if ($uri = "/dash") { return 302 /dash/; }

Before down-voting this one consider upvoting @Queuecumber 's comment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed.
Projects
No open projects
Development

No branches or pull requests