spring-boot - 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.
解决方案
您的问题可能是由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>
推荐阅读
- javascript - Javascript在画布上模拟鼠标移动事件
- javascript - 如何使用 angular 6 的 save-svg-as-png
- css - 如何在下拉框顶部显示下拉列表(始终)
- android - 在 ViewModel 之间共享数据
- elasticsearch - 为什么拼音搜索比普通匹配查询慢得多
- scala - 使用scala spark将参数传递给sql字符串三元组
- hyperledger-fabric - Hyperledger Fabric - 如何更改链码的集合配置?
- javascript - How to create singleton class and where we should use singleton class in Javascript?
- wpf - 如何避免 ControlTemplate 中的 Coloranimation 被应用到使用模板的每个对象
- discord.js - 使用startsWith discord.js问题时遇到问题