Java 为什么活力/准备度探测失败?
我正试图通过Helm charts将一个应用程序部署到Kubernetes集群。每次尝试部署应用程序时,我都会得到 “活动性探测失败:获取:拨号tcp” 172.17.0.7:80:连接:连接被拒绝”和“准备就绪探测失败:获取:拨号tcp 172.17.0.7:80:连接: 连接被拒绝” 这是我的部署。yaml:Java 为什么活力/准备度探测失败?,java,spring-boot,kubernetes,deployment,kubernetes-helm,Java,Spring Boot,Kubernetes,Deployment,Kubernetes Helm,我正试图通过Helm charts将一个应用程序部署到Kubernetes集群。每次尝试部署应用程序时,我都会得到 “活动性探测失败:获取:拨号tcp” 172.17.0.7:80:连接:连接被拒绝”和“准备就绪探测失败:获取:拨号tcp 172.17.0.7:80:连接: 连接被拒绝” 这是我的部署。yaml: apiVersion: apps/v1 kind: Deployment metadata: name: {{ include "mychart.fullname" . }}
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ include "mychart.fullname" . }}
labels:
{{- include "mychart.labels" . | nindent 4 }}
spec:
replicas: {{ .Values.replicaCount }}
selector:
matchLabels:
{{- include "mychart.selectorLabels" . | nindent 6 }}
template:
metadata:
labels:
{{- include "mychart.selectorLabels" . | nindent 8 }}
spec:
{{- with .Values.imagePullSecrets }}
imagePullSecrets:
{{- toYaml . | nindent 8 }}
{{- end }}
serviceAccountName: {{ include "mychart.serviceAccountName" . }}
securityContext:
{{- toYaml .Values.podSecurityContext | nindent 8 }}
containers:
- name: {{ .Chart.Name }}
securityContext:
{{- toYaml .Values.securityContext | nindent 12 }}
image: nikovlyubomir/docker-spring-boot:latest
imagePullPolicy: {{ .Values.image.pullPolicy }}
ports:
- name: http
containerPort: 80
protocol: TCP
livenessProbe:
initialDelaySeconds: 200
httpGet:
path: /
port: 80
readinessProbe:
initialDelaySeconds: 200
httpGet:
path: /
port: http
resources:
{{- toYaml .Values.resources | nindent 12 }}
{{- with .Values.nodeSelector }}
nodeSelector:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.affinity }}
affinity:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.tolerations }}
tolerations:
{{- toYaml . | nindent 8 }}
{{- end }}
我读到可能的解决方案是在两个探测中添加更多的initialDelaySecond,但这仍然没有解决我的问题
有什么意见吗 连接被拒绝表示容器未侦听端口80。同样,当您设置http就绪探测或活动探测时,如下所示
apiVersion: v1
kind: Pod
metadata:
labels:
test: liveness
name: liveness-http
spec:
containers:
- name: liveness
image: k8s.gcr.io/liveness
args:
- /server
livenessProbe:
httpGet:
path: /
port: 80
initialDelaySeconds: 3
periodSeconds: 3
为了执行探测,kubelet向在容器中运行并侦听端口80的服务器发送HTTP GET请求。如果服务器的/
路径的处理程序返回一个成功代码,则kubelet认为容器是活动的和健康的。如果处理程序返回失败代码,kubelet将终止容器并重新启动它
因此,代码中没有返回路径成功代码的处理程序
/
。因为它是一个spring boot应用程序,假设您在pom中有spring boot actuator依赖项,您可以将路径更改为/actuator/health
,这应该可以解决问题。因为我可以拉取图像,所以我尝试了一下
$ docker run -d nikovlyubomir/docker-spring-boot:latest
9ac42a1228a610ae424217f9a2b93cabfe1d3141fe49e0665cc71cb8b2e3e0fd
我有日志
$ docker logs 9ac
...
2020-03-08 02:02:30.552 INFO 1 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 1993 (http) with context path ''
应用程序似乎从1993端口开始,而不是从80端口开始
然后检查容器中的端口和连接:
$ docker exec -ti 9ac bash
root@9ac42a1228a6:/# curl localhost:1993
{"timestamp":"2020-03-08T02:03:12.104+0000","status":404,"error":"Not Found","message":"No message available","path":"/"}
root@9ac42a1228a6:/# curl localhost:1993/actuator/health
{"timestamp":"2020-03-08T02:04:01.348+0000","status":404,"error":"Not Found","message":"No message available","path":"/actuator/health"}
root@9ac42a1228a6:/# curl localhost:80
curl: (7) Failed to connect to localhost port 80: Connection refused
root@9ac42a1228a6:/# curl localhost:80/actuator/health
curl: (7) Failed to connect to localhost port 80: Connection refused
因此,请确保检查路径
/
或其他路径已正确设置,并且端口80
或1993
已准备就绪。探头是否继续出现故障或最终切换为绿色?应用程序是否正确启动?日志怎么说?探测一直失败,每当我部署应用程序时,我都会看到绿色的部署,持续1-2分钟,但经过一段时间(可能是延迟),它会变回红色。我认为该应用程序已正确启动,以下是我的事件:1)成功将默认/示例E-mychart-67f9c7c485-47zw8分配给minikube 2)容器映像“nikovlyubomir/docker spring boot:latest”计算机上已存在3)已创建容器mychart4)已启动容器mychart5)活动性探测失败:Get:拨号tcp 172.17.0.7:80:连接:连接被拒绝6)活动性探测失败:Get:拨号tcp 172.17.0.7:80:连接:连接被拒绝7)容器mychart活动性探测失败,将重新启动8)退出重新启动失败的集装箱应用程序是否实际在端口80上运行?通常,默认端口是8080。请检查吊舱的日志。应用程序应说明是已成功启动还是因错误而终止。