I've setup a simple Web API project and made an image. When I run the image directly using docker, I can't access the server using http://localhost:8080, but if I run docker inspect bridge I get back :
[
{
"Name": "bridge",
"Id": "50a9ae0ed8721eaf1e4c5b1dd811d2be55d52e3cd7c012bfeb10d7e163c5d111",
"Created": "2024-03-12T13:31:17.805598891-06:00",
"Scope": "local",
"Driver": "bridge",
"EnableIPv6": false,
"IPAM": {
"Driver": "default",
"Options": null,
"Config": [
{
"Subnet": "172.17.0.0/16",
"Gateway": "172.17.0.1"
}
]
},
"Internal": false,
"Attachable": false,
"Ingress": false,
"ConfigFrom": {
"Network": ""
},
"ConfigOnly": false,
"Containers": {
"fc3d2b13168f662685e93fdc59c5508a147d6877147b97036d4c47b2f175ed7e": {
"Name": "dreamy_mclaren",
"EndpointID": "5173755a7c8158a30b195ec4d752f029eac0d84785ce20d2968ee18544374775",
"MacAddress": "02:42:ac:11:00:02",
"IPv4Address": "172.17.0.2/16",
"IPv6Address": ""
}
},
"Options": {
"com.docker.network.bridge.default_bridge": "true",
"com.docker.network.bridge.enable_icc": "true",
"com.docker.network.bridge.enable_ip_masquerade": "true",
"com.docker.network.bridge.host_binding_ipv4": "0.0.0.0",
"com.docker.network.bridge.name": "docker0",
"com.docker.network.driver.mtu": "1500"
},
"Labels": {}
}
]
So then I try a GET request to http://172.17.0.2:8080/api/platforms and get back the expected response. I'm not sure where this subnet/gateway is coming from. By default I would expect to be able to use localhost. I went ahead and pushed the image to Dockerhub regardless. This issue is compounded when I try to setup a Deployment for this image, and a NodePort service:
platforms-depl.yaml:
apiVersion: apps/v1
kind: Deployment
metadata:
name: platforms-depl
spec:
replicas: 1
selector:
matchLabels:
app: platformservice
template:
metadata:
labels:
app: platformservice
spec:
containers:
- name: platformservice
image: itunbridge/platformservice:latest
ports:
- containerPort: 80
platforms-np-srv.yaml:
apiVersion: v1
kind: Service
metadata:
name: platformservice-srv
spec:
type: NodePort
selector:
app: platformservice
ports:
- name: platformservice
protocol: TCP
port: 80
targetPort: 80
Then I run:
kubectl apply -f platforms-depl.yaml
and
kubectl apply -f platforms-np-srv.yaml
I can see which port was assigned with kubectl get services:
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 46m
platformservice-srv NodePort 10.104.221.184 <none> 80:30201/TCP 44m
I then try: minikube service platformservice-srv --url which gives me a response of
http://192.168.59.100:30201
But none of these addresses give a response:

For some strange reason, the default
ASPNETCORE_URLSEnvironment variable was set tohttp://+:8080(as opposed tohttp://+80). After I updated my docker file:I pushed the new image to Docker Hub, then set the new image in my deployment:
kubectl set image deployment/platforms-depl platformservice=itunbridge/platformserviceandkubectl rollout status deployment/platforms-deplthen the NodePort configuration I had originally:(platforms-np-srv.yaml):
This works with value
targetPort: 80and I could access the endpoint by finding the IP assigned tominikube ip(http://192.168.59.100:30201/api/platforms)A big thank you to @DavidMaze for pointing this out and getting me to realize my Web API app was listening on port 8080.