Use*_*250 4 asp.net-mvc docker kubernetes asp.net-core angular
我将 .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"]
Run Code Online (Sandbox Code Playgroud)
当我检查 pod 的日志时,出现以下错误:
无法绑定到IPv6 环回接口上的http://localhost:5000 :“无法分配请求的地址”
活动探测失败:获取http://yyyy:80/:拨打 tcp yyyy:80: 连接:连接被拒绝
这是我的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 }}
Run Code Online (Sandbox Code Playgroud)
问题是 .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"
}
}
}
Run Code Online (Sandbox Code Playgroud)
注意: UseUrl()方法或设置环境变量ASPNETCORE_URLS不适用于.NET Core 3.1。
| 归档时间: |
|
| 查看次数: |
2087 次 |
| 最近记录: |