Kubernetes nginx 入口返回 400

问题描述 投票:0回答:1

我做了什么:

  1. 安装适用于 Windows 的 Docker 桌面
  2. 启用 Kubernetes(通过“设置”->“Kubernetes”->“启用 Kubernetes”)
  3. 通过 YAML 清单安装 Nginx Ingress:https://kubernetes.github.io/ingress-nginx/deploy/
  4. 通过 YAML 清单安装 kubernetes-dashboard:https://kubernetes.io/docs/tasks/access-application-cluster/web-ui-dashboard/#deploying-the-dashboard-ui
  5. 检查仪表板服务和 Pod 是否正常工作:
  6. 采用了一个最小的 Ingress 示例(https://kubernetes.io/docs/concepts/services-networking/ingress/#the-ingress-resource)并在其上创建了 ingress 清单:
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: root-ingress
  namespace: kubernetes-dashboard
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /
spec:
  ingressClassName: nginx
  rules:
  - http:
      paths:
      - path: /dashboard
        pathType: Prefix
        backend:
          service:
            name: kubernetes-dashboard
            port:
              number: 443
  1. Ingress 成功启动。

  2. 我不断从该路径收到 400 响应。

  3. curl -k -v https://localhost 在本地主机上响应:

PS C:\Windows\system32> curl.exe -k -v https://localhost
    *   Trying [::1]:443...
    * Connected to localhost (::1) port 443
    * schannel: disabled automatic use of client certificate
    * ALPN: curl offers http/1.1
    * ALPN: server accepted http/1.1
    * using HTTP/1.1
    > GET / HTTP/1.1
    > Host: localhost
    > User-Agent: curl/8.4.0
    > Accept: */*
    >
    * schannel: remote party requests renegotiation
    * schannel: renegotiating SSL/TLS connection
    * schannel: SSL/TLS connection renegotiated
    * schannel: remote party requests renegotiation
    * schannel: renegotiating SSL/TLS connection
    * schannel: SSL/TLS connection renegotiated
    < HTTP/1.1 404 Not Found
    < Date: Mon, 22 Jan 2024 20:20:40 GMT
    < Content-Type: text/html
    < Content-Length: 146
    < Connection: keep-alive
    < Strict-Transport-Security: max-age=15724800; includeSubDomains
    <
    <html>
    <head><title>404 Not Found</title></head>
    <body>
    <center><h1>404 Not Found</h1></center>
    <hr><center>nginx</center>
    </body>
    </html>
    * Connection #0 to host localhost left intact
  1. curl -k -v https://localhost 在 localhost/dashboard 上响应:
    PS C:\Windows\system32> curl.exe -k -v https://localhost/dashboard
    *   Trying [::1]:443...
    * Connected to localhost (::1) port 443
    * schannel: disabled automatic use of client certificate
    * ALPN: curl offers http/1.1
    * ALPN: server accepted http/1.1
    * using HTTP/1.1
    > GET /dashboard HTTP/1.1
    > Host: localhost
    > User-Agent: curl/8.4.0
    > Accept: */*
    >
    * schannel: remote party requests renegotiation
    * schannel: renegotiating SSL/TLS connection
    * schannel: SSL/TLS connection renegotiated
    * schannel: remote party requests renegotiation
    * schannel: renegotiating SSL/TLS connection
    * schannel: SSL/TLS connection renegotiated
    < HTTP/1.1 400 Bad Request
    < Date: Mon, 22 Jan 2024 20:23:04 GMT
    < Transfer-Encoding: chunked
    < Connection: keep-alive
    < Strict-Transport-Security: max-age=15724800; includeSubDomains
    <
    Client sent an HTTP request to an HTTPS server.
    * Connection #0 to host localhost left intact
kubernetes kubernetes-ingress docker-desktop
1个回答
0
投票
  • 在您的 K8s 中应用并连接到 nettool pod。

否则在本地计算机上公开 443 以使用curl

© www.soinside.com 2019 - 2024. All rights reserved.