0

I want to run an ASP.NET application in kubernetes, specifically my local minikube instance.

  1. I created the Dockerfile:
FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS base
EXPOSE 80
EXPOSE 443
# omitted

FROM base AS final
# omited
ENTRYPOINT [ "dotnet", "Application.dll", "--urls http://0.0.0.0:80;https://0.0.0.0:443" ]
  1. I am using windows and powershell so I redirected docker to my minikube's docker:
& minikube -p minikube docker-env --shell powershell  | Invoke-Expression
  1. I created the secrets/configMap/deployment/service yaml files:
apiVersion: apps/v1
kind: Deployment
metadata:
  name: identities-deployment
  labels:
    app: identities
spec:
  replicas: 1
  selector:
    matchLabels:
      app: identities
  template:
    metadata:
      labels:
        app: identities
    spec:
      containers:
      - name: identities
        image: identities-service:latest
        imagePullPolicy: Never
        ports:
        - containerPort: 80
        - containerPort: 443
---
apiVersion: v1
kind: Service
metadata:
  name: identities-service
spec:
  type: NodePort
  selector:
    app: identities
  ports:
    - protocol: TCP
      port: 80
      targetPort: 80
      nodePort: 30001
      name: http
    - protocol: TCP
      port: 443
      targetPort: 443
      nodePort: 30002
      name: https
  1. I get minikube's IP by running minikube ip. Returns 192.168.49.2

  2. I send an http request to 192.168.49.2:30001 to check the application health (should simply return 200), but it times out.

  3. I get a shell inside my application's container and ensure that I can get a response from the app at localhost:80 (It returns 200, so it is okay)

kubectl exec --stdin --tty identities-deployment-d794d7866-6bnhn -- /bin/bash
curl localhost:80
  1. I get a shell inside minikube's container and ensure that I can get a response from the app at localhost:30001 (It returns 200, so it is okay)
docker exec -it 46cca50fc3b3 sh 
curl localhost:30001
  1. I run minikube service identities-service --url and get:
http://127.0.0.1:51504
http://127.0.0.1:51505
❗  Because you are using a Docker driver on windows, the terminal needs to be open to run it.
  1. I send a request to localhost:51504 and it returns 200 (successful)

My question is, at step 5, why is it timing out and how to solve it? I want my application to be exposed in port 30001, I am not sure where the 51504 is coming from. On a side note, if I run docker ps -a (with my local docker, not minikubes) I get:

CONTAINER ID   IMAGE                                 COMMAND                  CREATED          STATUS
    PORTS
                      NAMES
46cca50fc3b3   gcr.io/k8s-minikube/kicbase:v0.0.39   "/usr/local/bin/entr…"   55 minutes ago   Up 55 minutes
    127.0.0.1:58799->22/tcp, 127.0.0.1:58800->2376/tcp, 127.0.0.1:58802->5000/tcp, 127.0.0.1:58803->8443/tcp, 127.0.0.1:58801->32443/tcp   minikube

I was not expecting port 30001 to be mapped in minikube's container since I am accessing my app through minikube's ip, but the more I think about it the more it makes sense for port 30001 and 30002 to be mapped at the minikube's container with my local machine as well and not just inside the k8s cluster. Is this the solution? And if so, how can I map these ports? I only ran minikube start

David Maze
  • 130,717
  • 29
  • 175
  • 215
sebsmgzz
  • 361
  • 2
  • 11
  • Several options are discussed in [Expose port in minikube](https://stackoverflow.com/questions/40767164/expose-port-in-minikube); does one of the approaches there help? I think the important note in your question is the `using the Docker driver` warning, this means the `minikube ip` is an inaccessible Docker-internal container IP address. – David Maze Jul 16 '23 at 10:12
  • Did you have time to check my answer? It helped you to solve your issue? If not, I am happy to assist further. – Sai Chandra Gadde Jul 18 '23 at 14:41
  • @SaiChandraGadde Sorry for the delay, I responded your comment. The way that I found it works for me is by running `kubectl port-forward svc/identities-service 30001:80` – sebsmgzz Jul 20 '23 at 04:23

2 Answers2

0

Service exposed using NodePort should be reachable on minikube_IP:NodePort, in your case 192.168.49.2:30001,but it is getting timed out as service is being exposed on ports 51504 and 51505 on the host machine.

you can get this working by using tunnel in minikube:

minikube tunnel
kubectl get services deploymentName

this provides the external ip address needed to access the application.

For more information follow this official doc.

Sai Chandra Gadde
  • 2,242
  • 1
  • 3
  • 15
  • Hi, after running `minikube tunnel` I get the message to keep the terminal open. So in another terminal I run the command: ``` kubectl get services identities-service NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE identities-service NodePort 10.98.49.123 80:30001/TCP,443:30002/TCP 3m36s ``` Then I send a request to 10.98.49.123, but it still times out – sebsmgzz Jul 20 '23 at 04:22
0

I found that by running kubectl port-forward svc/identities-service 30001:80 I get the service to answer requests in port 30001. But I do need to have the terminal open. Is there a way for kubectl to infer this?

sebsmgzz
  • 361
  • 2
  • 11