升级到 .Net Core 3.1 后,活跃/就绪探针失败

3

我将我的 .Net Core 2.1 升级到了 3.1。升级后,pod 的 Liveness 和 Readiness 探针失败了。

以下是我的 Docker 文件片段:

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:'Cannot assign requested address'
存活探针失败:获取http://yyyy:80/:dial tcp yyyy:80: connect: connection refused
这是我的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 }}

@ArghyaSadhu 已添加 deployment.yaml 文件内容 - User3250
尝试绑定到127.0.0.1而不是localhost - Matt
@HelloWorld 我应该在哪里进行更改?只是提醒一下,我在项目中提到要使用网址"http://localhost:5000"。 - User3250
1
好的,你的应用正在使用端口5000而不是80。首先将你的应用绑定到 0.0.0.0:5000 而不是 localhost:5000 ,这样它就可以从 Pod 外部访问,并且将健康检查设置为端口5000,而不是端口80。 - Matt
@HelloWorld 非常感谢!将URL从“localhost:5000”更改为“0.0.0.0:5000”起了很大作用。虽然找到这样做的方法并不容易。 - User3250
显示剩余7条评论
1个回答

7
问题在于 .NET Core 3.1 的 Kestrel 服务器将指向 localhost 而不是 0.0.0.0。因此,它无法从外部访问。这就是为什么存活和准备探针失败的原因。
要将 url 从 localhost 更改为 0.0.0.0,我需要在 appsettings.json 中添加以下部分:
"Kestrel": {
    "EndPoints": {
      "Http": {
        "Url": "http://0.0.0.0:5000"
      }
    }
  }

注意:在.NET Core 3.1中,使用UseUrl()方法或设置环境变量ASPNETCORE_URLS无效。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接