17

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?

Gupta
  • 5,122
  • 3
  • 27
  • 46
zarathustra
  • 1,468
  • 3
  • 14
  • 30

2 Answers2

22

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.

Tinky_
  • 294
  • 3
  • 5
  • 1
    running in the same pod ? or running in the same cluster? – Ijaz Ahmad Khan Dec 19 '18 at 23:24
  • What happen when many pods running on the same node whit NodePort? – yan Jan 08 '19 at 07:43
  • 1
    @yan 1. With NodePort it doesn't matter if you have one or multiple nodes, the port is available on every node. 2. what you usually would do is have a service available via a port, this service will then loadbalance calls to the pods running on your node. – Tinky_ Jan 09 '19 at 09:05
  • So I can't access : with NodePort. Or I had to add another service with HostPost before NodePort? – yan Jan 10 '19 at 07:21
4
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
Gupta
  • 5,122
  • 3
  • 27
  • 46