I want to run an ASP.NET application in kubernetes, specifically my local minikube instance.
- 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" ]
- I am using windows and powershell so I redirected docker to my minikube's docker:
& minikube -p minikube docker-env --shell powershell | Invoke-Expression
- 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
I get minikube's IP by running
minikube ip
. Returns192.168.49.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.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
- 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
- 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.
- 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