Will a connection to a K8 pod port be successful even if no container is mapped to the port?

6/22/2018

If I have a Kubernetes pod exposing port 8000, with an image running inside of the pod that is NOT in any way configured to connect to the pod's port 8000, will a connection to the pod's port 8000 still succeed? I'm trying to debug a scenario where Prometheus (a metrics collection tool) can communicate with my K8s pod on port 8000, but isn't receiving any metrics from the container (maybe because the container isn't mapped to the pod's port 8000).

Thanks!

-- kramsiv94
docker
kubernetes
prometheus

1 Answer

6/22/2018

When creating your image from a Dockerfile, use the EXPOSE command to expose a container port (documented here). From there, any incoming message to that host port will be forwarded into the container.

-- brianolive
Source: StackOverflow