我将.Net Core 2.1升级到3.1。升级后,对Pod的“活动性和就绪性”探测失败。 以下是我的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:“无法分配请求的地址”
活动探测失败:获取http://yyyy:80/:拨打tcp yyyy:80:connect:连接被拒绝
这是我的 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 }}
答案 0 :(得分:4)
问题是.NET Core 3.1的kestrel服务器指向localhost
而不是0.0.0.0
。因此,无法从外部访问。这就是为什么对活力和就绪性测试失败的原因。
要将网址从localhost
更改为0.0.0.0
,我需要在appsettings.json
中添加以下部分:
"Kestrel": {
"EndPoints": {
"Http": {
"Url": "http://0.0.0.0:5000"
}
}
}
注意::UseUrl()
方法或设置环境变量ASPNETCORE_URLS
不适用于.NET Core 3.1。