【问题标题】:Liveness / Readiness probe failed after upgrade to .Net Core 3.1升级到 .Net Core 3.1 后,Liveness/Readiness 探测失败
【发布时间】:2020-04-22 12:54:52
【问题描述】:

我将 .Net Core 2.1 升级到 3.1。升级后对 Pod 的 Liveness 和 Readiness 探测失败。 下面是我的docker文件sn-p:

FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-buster-slim AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443

FROM mcr.microsoft.com/dotnet/core/sdk:3.1-buster AS build
ENTRYPOINT ["dotnet", "Web.dll"]

当我检查 pod 的日志时,我得到以下错误:

无法绑定到 IPv6 环回接口上的 http://localhost:5000:“无法分配请求的地址”

Liveness probe failed: Get http://yyyy:80/: dial tcp yyyy:80: connect: connection denied

这是我的 Deployment.yaml 文件:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ include "staging.fullname" . }}
  namespace: staging
  labels:
    app.kubernetes.io/name: {{ include "staging.name" . }}
    helm.sh/chart: {{ include "staging.chart" . }}
    app.kubernetes.io/instance: {{ .Release.Name }}
    app.kubernetes.io/managed-by: {{ .Release.Service }}
spec:
  replicas: {{ .Values.replicaCount }}
  selector:
    matchLabels:
      app.kubernetes.io/name: {{ include "staging.name" . }}
      app.kubernetes.io/instance: {{ .Release.Name }}
  template:
    metadata:
      labels:
        app.kubernetes.io/name: {{ include "staging.name" . }}
        app.kubernetes.io/instance: {{ .Release.Name }}
    spec:
      imagePullSecrets:
        - name: {{ .Values.image.pullSecret }}
      containers:
        - name: {{ .Chart.Name }}
          image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
          imagePullPolicy: {{ .Values.image.pullPolicy }}
          ports:
            - name: http
              containerPort: 80
              protocol: TCP
          env:
            - name: ASPNETCORE_ENVIRONMENT
              value: "Staging"
          livenessProbe:
            httpGet:
              path: /
              port: http
          readinessProbe:
            httpGet:
              path: /
              port: http
            initialDelaySeconds: 10  
          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 }}

【问题讨论】:

  • 提供完整的部署文件以及服务和pod
  • @ArghyaSadhu 添加了 deployment.yaml 文件内容
  • 尝试绑定到127.0.0.1 而不是localhost
  • @HelloWorld 我应该在哪个地方进行更改?现在仅供参考,我在项目中提到使用 url “localhost:5000”。
  • 好的,所以您的应用程序在端口 5000 而不是 80 上工作。所以首先将您的应用程序绑定到 0.0.0.0:5000 而不是 localhost:5000 以便它可以从 pod 外部访问并设置您的健康检查到端口 5000,而不是端口 80

标签: angular asp.net-mvc docker asp.net-core kubernetes


【解决方案1】:

问题在于 .NET Core 3.1 的 kestrel 服务器指向 localhost 而不是 0.0.0.0。因此,无法从外部访问。这就是 liveness 和 readiness 探测失败的原因。

要将网址从localhost 更改为0.0.0.0,我需要在appsettings.json 中添加以下部分:

"Kestrel": {
    "EndPoints": {
      "Http": {
        "Url": "http://0.0.0.0:5000"
      }
    }
  }

注意: UseUrl() 方法或设置环境变量 ASPNETCORE_URLS 不适用于 .NET Core 3.1。

【讨论】:

    猜你喜欢
    • 2020-06-19
    • 2021-11-12
    • 1970-01-01
    • 2023-01-30
    • 1970-01-01
    • 2018-02-11
    • 2021-09-15
    • 2021-10-13
    • 2019-05-18
    相关资源
    最近更新 更多