首页 > 解决方案 > Spring boot service in kubernetes always responses with HTTP status 400

问题描述

We have Spring Boot service running in Kubernetes.
This service has endpoint:
- GET /healthz

We have liveness probe that uses this endpoint. Probe runs successfully.
It means that the endpoint is reachable from the service pod (localhost).

When I run in the service pod : wget https://localhost:8080/healthz I get an answer (OK)

When I try to call this endpoint outside the pod wget https://myhost:8080/healthz, I get response 400 without body.
I don't see any logs of Sprint. It seems that it does not reach the Sprint .
When I added flag -Djavax.net.debug=all I see in log that TLS handshake finished and then:

GET /healthz HTTP/1.1    
host: myhost:8080    
accept: application/json    
Connection: close     

and immediately

HTTP/1.1 400 
Transfer-Encoding: chunked
Date: Mon, 25 Jun 201 8 08:43:43 GMT
Connection: close

When I try wget https://myhost:8080/blahblah (non existing endpoint), I still get 400, not 404!

When I try wget https://myWronghost:8080/healthz (wrong host), I get an error Bad address. It means that host 'myhost' is correct (otherwise I would get this error).

Docker file:

FROM openjdk:8-jdk-alpine
VOLUME /tmp
ARG JAR_FILE
COPY ${JAR_FILE} app.jar
ENV JAVA_TOOL_OPTIONS -Dfile.encoding=UTF8
ENTRYPOINT ["java","-Djavax.net.debug=all", "-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"]
EXPOSE 8080

Summing up:
The service endpoints are accessible from within service pod, but not accessible from outside the pod.
Any idea why?

Update:
The problem was solved by calling the service with fully qualified domain name : serviceName.namespaceName.svc.cluster.local
Tomcat didn't accept calls with short domain serviceName.namespaceName, it responded 400.

标签: spring-bootkuberneteskubernetes-ingresskubernetes-health-checkkubernetes-security

解决方案


您的问题可能是由https://github.com/spring-projects/spring-boot/issues/13205引起的。您所要做的就是将 Tomcat 版本升级到 8.5.32。您可以通过在 pom.xml 文件中添加版本来做到这一点。

 <properties>
    <!-- your properties -->
    <tomcat.version>8.5.32</tomcat.version>
 </properties>

推荐阅读