java为什么活动性/就绪性探测失败?
我正试图通过Helm charts将一个应用程序部署到Kubernetes集群。每次尝试部署应用程序时,我都会得到
"Liveness probe failed: Get http://172.17.0.7:80/: dial tcp 172.17.0.7:80: connect: connection refused" and "Readiness probe failed: Get http://172.17.0.7:80/: dial tcp 172.17.0.7:80: connect: connection refused"
这是我的部署。亚马尔:
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,但这仍然没有解决我的问题
有什么意见吗
# 1 楼答案
连接被拒绝意味着容器没有监听端口80。同样,当您设置http就绪探测或活动探测时,如下所示
为了执行探测,kubelet向在容器中运行并侦听端口80的服务器发送HTTP GET请求。如果服务器的
/
路径的处理程序返回一个成功代码,则kubelet会认为容器是活动的、健康的。如果处理程序返回失败代码,kubelet将终止容器并重新启动它因此,代码中没有返回路径^{成功代码的处理程序。由于它是一个spring boot应用程序,假设您在pom中有spring boot actuator依赖项,您可以将路径更改为
/actuator/health
,这应该可以解决问题# 2 楼答案
既然我能把图像拉出来,我试了一下
我有日志
似乎申请是从1993港开始的,而不是80港
然后检查容器中的端口和连接:
因此,请确保正确设置了检查路径
/
或其他路径,并且端口80
或1993
已准备就绪