【问题标题】:Why Liveness / Readiness probe failed?为什么 Liveness / Readiness 探测失败?
【发布时间】:2020-06-19 23:44:55
【问题描述】:

我正在尝试通过 Helm 图表将应用程序部署到 Kubernetes 集群。每次我尝试部署应用程序时,我都会得到 ​​p>

"Liveness probe failed: Get http://172.17.0.7:80/: dial tcp 172.17.0.7:80:连接:连接被拒绝”和“就绪探测失败:获取http://172.17.0.7:80/:拨号 tcp 172.17.0.7:80:连接: 连接被拒绝”

这是我的部署.yaml:

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-2 分钟,但过了一段时间(可能是延迟)它又变回红色。我认为应用程序已正确启动,这些是我的事件:1)成功将默认/examplee-mychart-67f9c7c485-47zw8 分配给 minikube 2)容器映像“nikovlyubomir/docker-spring-boot:latest”已经存在于机器 3)创建容器 mychart
  • 4) 启动容器 mychart
  • 5) Liveness probe failed: Get 172.17.0.7:80: dial tcp 172.17.0.7:80: connect: connection denied 6) Liveness probe failed: Get 172.17.0.7:80: dial tcp 172.17.0.7:80:连接:连接被拒绝 7 ) 容器 mychart 失败的活性探测,将被重新启动 8 ) 回退重新启动失败的容器
  • 应用程序是否真的在端口 80 上运行?通常,默认端口是 8080。请检查 pod 的日志。应用程序应说明是否已成功启动或因错误而终止。

标签: java spring-boot kubernetes deployment kubernetes-helm


【解决方案1】:

因为我可以拉出图像,所以我试了一下

$ 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

所以请确保检查路径/ 或其他设置正确,端口801993 已准备好。

【讨论】:

    【解决方案2】:

    连接被拒绝意味着容器未在端口 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 向在 Container 中运行并侦听端口 80 的服务器发送 HTTP GET 请求。如果服务器的 / 路径的处理程序返回成功代码,则 kubelet 认为 Container活着和健康。如果处理程序返回失败代码,则 kubelet 会杀死 Container 并重新启动它。

    所以您的代码中没有处理程序,它返回路径/ 的成功代码。由于它是一个 spring boot 应用程序,假设您在 pom 中有 spring boot actuator 依赖项,您可以将路径更改为 /actuator/health 这应该可以解决问题。

    【讨论】:

      猜你喜欢
      • 2020-04-22
      • 2021-11-12
      • 1970-01-01
      • 1970-01-01
      • 2023-01-30
      • 2018-02-11
      • 2021-09-15
      • 2019-05-18
      • 2019-07-20
      相关资源
      最近更新 更多