Docker 无法访问部署到kubernetes的容器化asp.core web api?
我创建了一个虚拟的容器化web api—实际上是Visual studio创建的标准模板rest api 是否将其docker文件创建的映像预测并部署到我的kubernetes集群中 我的kubernetes集群有一个入口控制器,但由于某种原因,我似乎无法公开绑定到该pod的服务 通过我的入口控制器运行web api 每次我尝试访问它时,我都会收到一个503错误,说明该服务暂时不可用,这没有任何意义 dockerfile:Docker 无法访问部署到kubernetes的容器化asp.core web api?,docker,kubernetes,asp.net-core-webapi,Docker,Kubernetes,Asp.net Core Webapi,我创建了一个虚拟的容器化web api—实际上是Visual studio创建的标准模板rest api 是否将其docker文件创建的映像预测并部署到我的kubernetes集群中 我的kubernetes集群有一个入口控制器,但由于某种原因,我似乎无法公开绑定到该pod的服务 通过我的入口控制器运行web api 每次我尝试访问它时,我都会收到一个503错误,说明该服务暂时不可用,这没有任何意义 dockerfile: #See https://aka.ms/containerfastmod
#See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging.
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
WORKDIR /src
COPY ["weather/weather.csproj", "weather/"]
RUN dotnet restore "weather/weather.csproj"
COPY . .
WORKDIR "/src/weather"
RUN dotnet build "weather.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "weather.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "weather.dll"]
Kubernetes配置文件:
kind: Deployment
apiVersion: extensions/v1beta1
metadata:
name: weather
spec:
replicas: 1
template:
metadata:
name: weather
labels:
name: weather
spec:
containers:
- name: weather
image: weather
imagePullPolicy: Always
ports:
- containerPort: 443
env:
- name: "ASPNETCORE_ENVIRONMENT"
value: "Development"
livenessProbe:
httpGet:
path: /WeatherForecast
port: 443
initialDelaySeconds: 3
periodSeconds: 3
---
kind: Service
apiVersion: v1
metadata:
name: weather-service
spec:
ports:
- name: http
port: 443
protocol: TCP
targetPort: 443
selector:
app: weather
sessionAffinity: None
type: ClusterIP
---
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /
name: weather-ingress
spec:
rules:
- host: weather.localhost
http:
paths:
- backend:
serviceName: weather-service
servicePort: 443
path: /app3
为什么这不起作用?
我尝试了端口80和443,但似乎没有任何效果 您是否尝试通过端口80或端口443转发pod并在本地发出请求?首先尝试使用端口80。我假设您希望443是TLS/SSL连接。您是否试图点击
weather.localhost/app3
?