Cannot reach containerized asp.core web api deployed to kubernetes?

1/20/2020

I have created a dummy containerized web api - actually the standard template rest api Visual studio created the one with the whether forecast and deployed the image its docker file creates into my kubernetes cluster.

My kubernetes cluster has an ingress controller, but for some reason I seem to be unable to expose my service which is bound the pod that runs the web api via my ingress controller.

Everytime I try to reach it i get an 503 error stating that the service is temporally unavailable which does not make any sense?

The dockerfile:

#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 configuration file:

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

Why is this not working? I tried with port 80, and 443 nothing seem to work...

-- kafka
asp.net-core-webapi
docker
kubernetes

0 Answers