Kubernetes : What is hostPort and hostIp used for? Kubernetes : What is hostPort and hostIp used for? kubernetes kubernetes

Kubernetes : What is hostPort and hostIp used for?


If you take a look at the kubernetes API reference you'll find that hostIP is IP that is being assigned once the pod is scheduled into node.

hostIP (string) - IP address of the host to which the pod isassigned. Empty if not yet scheduled.

This can be further exposed as env inside the pod if needed (spec.hostIP)

With hostPort you can expose container port to the external network at :, where the hostIP is the IP address of the Kubernetes node where the container is running and the hostPort is the port requested by the user. You can read more about here.

If you want to reach your pod there are also other ways to do that, such as ClusterIP or NodePort depending if the request comes internally or externally. This article goes thru them and their differences.


ClusterIP (10.38.0.3) will only be accessed from within the cluster. To hit the service from outside the cluster, try nodeIP:port 192.168.150.202:8080

NodePort Service type allows us to expose our services on each Node’sIP at a static port. Therefore, it allows accessing the service fromoutside the cluster.