I am trying to get my Blazor Webassembly running in Kubernetes. There is a service customer-pwa-svc that i can call with http://localhost:{assignedPort} and my Webassembly starts perfectly. So far it looks good and I my container is running as expected.
Now I want to get access from outside and want to use the ingress object with the following rule
rules:
- host: localhost
http:
paths:
- path: /
backend:
service:
name: customer-pwa-svc
port:
number: 80
pathType: Exact
when I now call localhost, i only see a black loading circle loadingscreen
In the dev tools I see the 404 errors, that the files cant be loaded enter image description here
But it has the correct index.html loaded.
My dockerfile looks like this:
FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base
USER app
WORKDIR /app
EXPOSE 8080
EXPOSE 8081
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
ARG BUILD_CONFIGURATION=Release
WORKDIR /app
COPY . .
RUN dotnet restore "./Customer.PWA.sln"
RUN dotnet build "./Customer.PWA.sln" -c $BUILD_CONFIGURATION -o /app/build
FROM build AS publish
ARG BUILD_CONFIGURATION=Release
RUN dotnet publish "./Customer.PWA.sln" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false
FROM nginx:alpine AS final
WORKDIR /usr/share/nginx/html
COPY --from=publish /app/publish/wwwroot .
COPY nginx.conf /etc/nginx/nginx.conf
and the nginx.conf:
events { }
http {
include mime.types;
server {
listen 80;
location / {
root /usr/share/nginx/html;
try_files $uri $uri/ /index.html =404;
}
}
}
When I connect to the pod and in the folder /usr/share/nginx/html I see all files and folders I expect, including _content and framework stuff from Blazor Webassembly.
What I also tried was just to use another image (like nginx) behind my customer-pwa-svc and when I then called localhost the nginx side was shown without problems.
What I am wondering is, why does everything works, when calling my service directly, but not when using the ingress rules. I guess there is a path problem, but I don't see where the problem is.
Ok, that was too obvious to see. The problem was in the pathtype. When I changed it to
Prefixeverything works as expected.