如何使用 Ingress 访问 Minikube 上的 kubernetes-dashboard?

如何使用 Ingress 访问 Minikube 上的 kubernetes-dashboard?

我可以通过获取其 URL 来访问 kubernetes-dashboard minikube dashboard --url。但是,使用此方法每次重新启动 Minikube 集群时都会使用不同的端口名。因此,我尝试添加ingress-nginx并公开 kubernetes-dashoard 服务:

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: k8s-dashboard-ingress
  namespace: kubernetes-dashboard
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /$1
spec:
  rules:
  - host: kube-dashboard.local
    http:
      paths:
      - path: /
        pathType: Prefix  
        backend:
          service:
            name: kubernetes-dashboard
            port: 
              number: 80

kube-dashboard.local使用 映射到集群 IP 地址的 IP 地址/etc/hosts。这似乎有效,浏览器正在获取一些初始内容,但浏览器窗口仍然是空的。似乎只有初始请求被路由到仪表板,但其他对 JS 资源的请求不知何故失败了。入口规则有什么问题?

minikube kubectl -- describe service kubernetes-dashboard -n kubernetes-dashboard
Name:              kubernetes-dashboard
Namespace:         kubernetes-dashboard
Labels:            addonmanager.kubernetes.io/mode=Reconcile
                   k8s-app=kubernetes-dashboard
                   kubernetes.io/minikube-addons=dashboard
Annotations:       <none>
Selector:          k8s-app=kubernetes-dashboard
Type:              ClusterIP
IP Family Policy:  SingleStack
IP Families:       IPv4
IP:                10.105.10.141
IPs:               10.105.10.141
Port:              <unset>  80/TCP
TargetPort:        9090/TCP
Endpoints:         10.244.1.186:9090
Session Affinity:  None
Events:            <none>
minikube kubectl -- get ingress -n kubernetes-dashboard
NAME                    CLASS   HOSTS                  ADDRESS        PORTS   AGE
k8s-dashboard-ingress   nginx   kube-dashboard.local   192.168.58.2   80      11h
minikube kubectl -- describe ingress k8s-dashboard-ingress -n kubernetes-dashboard
Name:             k8s-dashboard-ingress
Labels:           <none>
Namespace:        kubernetes-dashboard
Address:          192.168.58.2
Ingress Class:    nginx
Default backend:  <default>
Rules:
  Host                  Path  Backends
  ----                  ----  --------
  kube-dashboard.local  
                        /   kubernetes-dashboard:80 (10.244.1.186:9090)
Annotations:            nginx.ingress.kubernetes.io/rewrite-target: /$1
Events:                 <none>

在此处输入图片描述

入口pod的日志:

192.168.58.1 - - [12/Sep/2023:17:28:57 +0000] "GET / HTTP/1.1" 200 821 "-" "Mozilla/5.0 (X11; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/116.0" 364 0.002 [kubernetes-dashboard-kubernetes-dashboard-80] [] 10.244.1.186:9090 821 0.002 200 e71b7c14812998f8561b5175cc0f0b3a
192.168.58.1 - - [12/Sep/2023:17:28:57 +0000] "GET /runtime.134ad7745384bed8.js HTTP/1.1" 200 821 "http://kube-dashboard.local/" "Mozilla/5.0 (X11; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/116.0" 318 0.002 [kubernetes-dashboard-kubernetes-dashboard-80] [] 10.244.1.186:9090 821 0.002 200 c55b47568d3dafe06b1a9ccaf18442d7
192.168.58.1 - - [12/Sep/2023:17:28:57 +0000] "GET /scripts.2c4f58d7c579cacb.js HTTP/1.1" 200 821 "http://kube-dashboard.local/" "Mozilla/5.0 (X11; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/116.0" 318 0.003 [kubernetes-dashboard-kubernetes-dashboard-80] [] 10.244.1.186:9090 821 0.003 200 20d5cd52673bc584ff05f54feb76fa99
192.168.58.1 - - [12/Sep/2023:17:28:57 +0000] "GET /en.main.3550e3edca7d0ed8.js HTTP/1.1" 200 821 "http://kube-dashboard.local/" "Mozilla/5.0 (X11; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/116.0" 318 0.004 [kubernetes-dashboard-kubernetes-dashboard-80] [] 10.244.1.186:9090 821 0.004 200 69b2b69e0fc4a406982c449cc661dd01
192.168.58.1 - - [12/Sep/2023:17:28:57 +0000] "GET /polyfills.5c84b93f78682d4f.js HTTP/1.1" 200 821 "http://kube-dashboard.local/" "Mozilla/5.0 (X11; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/116.0" 320 0.005 [kubernetes-dashboard-kubernetes-dashboard-80] [] 10.244.1.186:9090 821 0.005 200 1614d55b9416bab79683a87254d8992d
192.168.58.1 - - [12/Sep/2023:17:28:57 +0000] "GET /assets/images/kubernetes-logo.png HTTP/1.1" 200 821 "http://kube-dashboard.local/" "Mozilla/5.0 (X11; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/116.0" 346 0.002 [kubernetes-dashboard-kubernetes-dashboard-80] [] 10.244.1.186:9090 821 0.002 200 4414ae9d92778f8a2440829124251adc

没有日志消息表明有东西到达 pod kubernetes-dashboard。 使用来自 的 URL 时minikube dashboard --url,我可以看到以下日志:

2023/09/12 17:34:08 [2023-09-12T17:34:08Z] Incoming HTTP/1.1 GET /api/v1/service/kubernetes-dashboard/kubernetes-dashboard/ingress?itemsPerPage=10&page=1&sortBy=d,creationTimestamp request from 127.0.0.1: 
2023/09/12 17:34:08 [2023-09-12T17:34:08Z] Incoming HTTP/1.1 GET /api/v1/service/kubernetes-dashboard/kubernetes-dashboard/event?itemsPerPage=10&page=1&sortBy=d,lastSeen request from 127.0.0.1: 
2023/09/12 17:34:08 [2023-09-12T17:34:08Z] Incoming HTTP/1.1 GET /api/v1/service/kubernetes-dashboard/kubernetes-dashboard request from 127.0.0.1: 
2023/09/12 17:34:08 Getting details of kubernetes-dashboard service in kubernetes-dashboard namespace
2023/09/12 17:34:08 [2023-09-12T17:34:08Z] Incoming HTTP/1.1 GET /api/v1/namespace request from 127.0.0.1: 
2023/09/12 17:34:08 Getting list of namespaces
2023/09/12 17:34:08 [2023-09-12T17:34:08Z] Incoming HTTP/1.1 GET /api/v1/service/kubernetes-dashboard/kubernetes-dashboard/pod?itemsPerPage=10&page=1&sortBy=d,creationTimestamp request from 127.0.0.1: 
2023/09/12 17:34:08 Found 0 events related to kubernetes-dashboard service in kubernetes-dashboard namespace
2023/09/12 17:34:08 Found 1 endpoints related to kubernetes-dashboard service in kubernetes-dashboard namespace
2023/09/12 17:34:08 [2023-09-12T17:34:08Z] Outcoming response to 127.0.0.1 with 200 status code
2023/09/12 17:34:08 [2023-09-12T17:34:08Z] Outcoming response to 127.0.0.1 with 200 status code
2023/09/12 17:34:08 [2023-09-12T17:34:08Z] Outcoming response to 127.0.0.1 with 200 status code
2023/09/12 17:34:08 [2023-09-12T17:34:08Z] Outcoming response to 127.0.0.1 with 200 status code
2023/09/12 17:34:08 Getting pod metrics
2023/09/12 17:34:08 [2023-09-12T17:34:08Z] Outcoming response to 127.0.0.1 with 200 status code
2023/09/12 17:34:11 Getting application global configuration
2023/09/12 17:34:11 Application configuration {"serverTime":1694540051060}
...

相关内容