【问题标题】:Kubernetes HTTP health check fails with `http: server gave HTTP response to HTTPS client`Kubernetes HTTP 健康检查失败并显示“http:服务器向 HTTPS 客户端提供了 HTTP 响应”
【发布时间】:2019-12-05 02:27:21
【问题描述】:

这发生在我做了一个:

    RewriteCond %{HTTP:X-Forwarded-Proto} !https
    RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NE]

在 apache 中,它实际上基于 HTTP 标头进行 301 重定向。

从这个 curl 开始:

curl -vk -H 'Host: example.com' 172.17.0.2/api/v1/ping
* Expire in 0 ms for 6 (transfer 0x1af6470)
*   Trying 172.17.0.2...
* TCP_NODELAY set
* Expire in 200 ms for 4 (transfer 0x1af6470)
* Connected to 172.17.0.2 (172.17.0.2) port 80 (#0)
> GET /api/v1/ping HTTP/1.1
> Host: example.com
> User-Agent: curl/7.64.0
> Accept: */*
> 
< HTTP/1.1 301 Moved Permanently
< Date: Fri, 26 Jul 2019 18:14:09 GMT
< Server: Apache/2.4.38 (Debian)
< Location: https://example.com/api/v1/ping
< Content-Length: 239
< Content-Type: text/html; charset=iso-8859-1
< 
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>301 Moved Permanently</title>
</head><body>
<h1>Moved Permanently</h1>
<p>The document has moved <a href="https://example.com/api/v1/ping">here</a>.</p>
</body></html>
* Connection #0 to host 172.17.0.2 left intact

为什么这个 pod 会因为这个错误而失败?

  Warning  Unhealthy  99m (x7 over 100m)  kubelet, minikube  Readiness probe failed: Get https://172.17.0.9:80/api/v1/ping: http: server gave HTTP response to HTTPS client

【问题讨论】:

  • 这将有助于查看探针的定义。特别是scheme(默认为http)和httpHeaders(如果已配置)。否则,根据文档 (kubernetes.io/docs/tasks/configure-pod-container/…):“...任何大于或等于 200 且小于 400 的代码都表示成功。任何其他代码都表示失败”。顺便说一句,curl 的测试没有在 URL 中指定方案,因此它默认为 http

标签: kubernetes kubernetes-health-check


【解决方案1】:

可能它只是看到 301 重定向到 https...该错误有点误导,因为它甚至没有尝试 HTTPS 请求...我假设它不会遵循 301 而是在不返回时失败200...

【讨论】:

    猜你喜欢
    • 2020-05-07
    • 1970-01-01
    • 2020-12-31
    • 2018-09-15
    • 2021-04-27
    • 2021-04-19
    • 1970-01-01
    • 1970-01-01
    • 2019-12-22
    相关资源
    最近更新 更多