Rancher 2 provides 4 options in the "Ports" section when deploying a new workload:
- NodePort
- HostPort
- Cluster IP
- Layer-4 Load Balancer
What are the differences? Especially between NodePort, HostPort and Cluster IP?
Rancher 2 provides 4 options in the "Ports" section when deploying a new workload:
What are the differences? Especially between NodePort, HostPort and Cluster IP?
HostPort (nodes running a pod): Similiar to docker, this will open a port on the node on which the pod is running (this allows you to open port 80 on the host). This is pretty easy to setup an run, however:
Don’t specify a hostPort for a Pod unless it is absolutely necessary. When you bind a Pod to a hostPort, it limits the number of places the Pod can be scheduled, because each combination must be unique. If you don’t specify the hostIP and protocol explicitly, Kubernetes will use 0.0.0.0 as the default hostIP and TCP as the default protocol. kubernetes.io
NodePort (On every node): Is restricted to ports between port 30,000 to ~33,000. This usually only makes sense in combination with an external loadbalancer (in case you want to publish a web-application on port 80)
If you explicitly need to expose a Pod’s port on the node, consider using a NodePort Service before resorting to hostPort. kubernetes.io
Cluster IP (Internal only): As the description says, this will open a port only available for internal applications running in the same cluster. A service using this option is accessbile via the internal cluster-ip.
Host Port |
Node Port |
Cluster IP |
---|---|---|
When a pod is using a hostPort , a connection to the node’s port is forwarded directly to the pod running on that node |
With a NodePort service, a connection to the node’s port is forwarded to a randomly selected pod (possibly on another node ) |
Exposes the Service on an internal IP in the cluster. This type makes the Service only reachable from within the cluster. |
pods using a hostPort , the node’s port is only bound on nodes that run such pods |
NodePort services bind the port on all nodes, even on those that don’t run such a pod |
NA |
The hostPort feature is primarily used for exposing system services, which are deployed to every node using DaemonSets |
NA | NA |
General Ask Question
Q: What happens when many pods running on the same node whit NodePort?
A: With NodePort
it doesn't matter if you have one or multiple nodes, the port is available on every node.