我将我的 .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 }}
127.0.0.1
而不是localhost
。 - Matt0.0.0.0:5000
而不是localhost:5000
,这样它就可以从 Pod 外部访问,并且将健康检查设置为端口5000,而不是端口80。 - Matt