Kubernetes HTTP health check fails with `http: server gave HTTP response to HTTPS client`

7/26/2019

This occurred after I did a:

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

In apache which in effect does a 301 redirect based on a HTTP header.

Demonstarted with this 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

Why is this pod failing on this error?

  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
-- Chris Stryczynski
kubernetes
kubernetes-health-check

1 Answer

7/26/2019

Probably it's just seeing the 301 redirect to https... The error is a a bit misleading as it does not even attempt a HTTPS request... I'd assume it would just not follow the 301 and instead fail on not returning a 200...

-- Chris Stryczynski
Source: StackOverflow