Deploying AspNet Core to GKE gives connection refused

12/18/2019

I am trying to deploy an example Asp.Net Core 3.1 app to GKE, I am building the app in cloud console and it works fine when i am running it from the console with this command "docker run -p 8080:8080 [Image Name]asp-app:v1"

When i deploy it to my Cluster in GKE i cant reach my app althoug i am exposing it with this command: "kubectl expose deployment asp-web --type=LoadBalancer --port 80 --target-port 8080" I get this error in my webbrowser: "ERR_CONNECTION_REFUSED"

I have managed to deploy another app that where built using Asp.Net Core 2.2 so my settings in GCP should be right.

Does anyone have some experience with this?

Dockerfile:

FROM mcr.microsoft.com/dotnet/core/aspnet:3.1 AS base
WORKDIR /app
EXPOSE 80

FROM mcr.microsoft.com/dotnet/core/sdk:3.1 AS build
WORKDIR /src
COPY ["asp/asp.csproj", "asp/"]
RUN dotnet restore "asp/asp.csproj"
COPY . .
WORKDIR /src/asp
RUN dotnet build "asp.csproj" -c Release -o /app/build

FROM build AS publish
RUN dotnet publish "asp.csproj" -c Release -o /app/publish

FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENV ASPNETCORE_URLS http://*:8080
ENTRYPOINT ["dotnet", "asp.dll"]
-- Hammerboy1
asp.net-core
google-kubernetes-engine

1 Answer

12/19/2019

Figured it out. I had made a new project and added "ENV ASPNETCORE_URLS http://*:8080" to the dockerfile to make it bind to the port while running in the container on GKE.

-- Hammerboy1
Source: StackOverflow