1

Hello Im new to minikube and I cant connect to an exposed service. I created an Api .Net Core, I builded the image, go it into my private registry and then i created an deployment with an yml file that works. But i cant expose that deployment as service. Everytime after I expose it its all fine but I cant connect to it via the port and the minikube ip adress. If I try to connect to the ipadress:port I get connection refused.

Deployment yml file:

kind: Deployment
apiVersion: apps/v1
metadata:
  name: testapp1-deployment
  labels:
    app: testapp1
spec:
  replicas: 2
  selector:
    matchLabels:
      app: testapp1
  template:
    metadata:
      labels:
        app: testapp1
        version: v0.1
    spec:
      containers:
      - name: testapp1-deployment
        image: localhost:5000/testapp1
        imagePullPolicy: Never
        resources:
          requests:
            cpu: 120m
        ports:
        - containerPort: 80

Service yml file:

    apiVersion: v1
    kind: Service
    metadata:
      name: testapp1-service
    spec:
      type: NodePort
      selector:
          app: testapp1
      ports:
      - protocol: TCP
        port: 80  
        targetPort: 80
Yatesu
  • 51
  • 1
  • 6
  • Can you connect your app from inside the pod? `kubectl exec -it ... ` & then `curl -XGET localhost:80` ? – Kamol Hasan Oct 05 '20 at 12:16
  • I get also curl: (7) Failed to connect to localhost port 80: Connection refused – Yatesu Oct 05 '20 at 12:56
  • So, your application is not running. Check the container's log for more details. – Kamol Hasan Oct 05 '20 at 13:29
  • these are my pod logs error: warn: Microsoft.AspNetCore.Server.Kestrel[0] Unable to bind to http://localhost:5000 on the IPv6 loopback interface: 'Cannot assign requested address'. warn: Microsoft.AspNetCore.Server.Kestrel[0] Unable to bind to https://localhost:5001 on the IPv6 loopback interface: 'Cannot assign requested address'. – Yatesu Oct 05 '20 at 14:01
  • From the logs it seems like the deployment can't download the image from localhost:5001, if you type `kubectl get pods` the pod is healthy and running? – Jakub Oct 06 '20 at 09:20
  • yes they are healthy and running – Yatesu Oct 08 '20 at 11:15
  • Have you tried to use this [workaround](https://stackoverflow.com/a/59662573/11977760) to make it work? There is [another](https://stackoverflow.com/a/45074576/11977760) one. If you haven't tried it yet could you try and let me know if that work? – Jakub Oct 09 '20 at 05:48

1 Answers1

1

The problem was my dockerfile and I wasn't enabling docker support in my app in ASP .NET Core. I enabled the docker support and changed the dockerfile a bit then I rebuild it and it worked for me.

FROM mcr.microsoft.com/dotnet/core/sdk:3.1 AS build-env

WORKDIR /app

COPY *.csproj ./ RUN dotnet restore

COPY . ./ RUN dotnet publish -c Release -o out

FROM mcr.microsoft.com/dotnet/core/aspnet:3.1 WORKDIR /app COPY --from=build-env /app/out . ENTRYPOINT ["dotnet", "aspnetapp.dll"]

that's the dockerfile Im using for my app at the moment so if someone else face the same problem as me try to use the dockerfile. If it still won't work look up in previous comments.

Yatesu
  • 51
  • 1
  • 6