<p>I am trying to understand Kubernetes High Availability for calls that originate outside the cluster.  (For my new On-Premises Kubernetes cluster)</p>
<p>For Example: a desktop application needs to call a service hosted in Kubernetes.</p>
<p>I see two primary ways this can happen, NodePort and Ingress.</p>
<h2>NodePort</h2>
<p>What will happen during a node failure with NodePort seem fairly obvious.  Any calls that are using the newly offline node as the node they are addressing will fail.  If you are using a NodePort you need to make sure you have some way of detecting that the node you are using is down, and moving traffic to another node.  (And recovering any lost traffic that happened before you detected the downtime.)</p>
<p>This seems like the job of a load balancer.  It can do health monitoring and send the traffic to nodes that are up.</p>
<h2>Ingress</h2>
<p>I am less sure about how an Ingress Controller and an Ingress resource work.  It seems like there is a bit of magic here.  Does the Ingress controller use NodePort under the hood?  I see a lot of assumptions around a load balancer balancer that are not explained in the posts I read.  Is it expected that there will be a load balancer in place outside the cluster?</p>
<p>In which case what is the difference between NodePort with a load balancer and Ingress with a load balancer?  The load balancer presents a single URL to the calling systems and then it does its best to make the call get to a Kubernetes Node that is up (either via NodePort or Ingress Controller).  (Which makes me ask why both are present if both really require a load balancer to hide the node that gets called.)</p>
<p>But I am again confused because you use a single URL to send to an Ingress resource, so how is the node decided by the load balancer?</p>
<p>As I look at this, it seems that Kubernetes only has High Availability inside the cluster.  From outside the cluster, it is the job of the caller to ensure that the node they will be addressing, either via your own ping system, or a load balancer.</p>
<p><strong>Does Kubernetes have any features to help with node down times?</strong> From the point of view of a desktop application addressing the cluster, not from the point of view of the pods keeping the service up.</p>

Vaccano
<p>There's a couple pieces to this question - answering them in turn. The default service types in Kubernetes are ClusterIP, NodePort, and LoadBalancer.</p>
<h3>What's a service?</h3>
<blockquote>
<p>In Kubernetes, a Service is an abstraction which defines a logical set of Pods and a policy by which to access them (sometimes this pattern is called a micro-service).</p>
</blockquote>
<p>Basically, it's a logical load balancer in front of a collection of pods, determined by pod labels.</p>
<h3>How does a ClusterIP work?</h3>
<p>ClusterIP is an internal service, which means the IP address assigned to the service is internal to the cluster. It works by some magic in kube-proxy (read the <a href="https://kubernetes.io/docs/concepts/services-networking/service/" rel="nofollow noreferrer">documentation</a> if you'd like to know more). Dead pods are automatically removed from the load balancing.</p>
<h3>How does NodePort work?</h3>
<p>NodePort is an external service, which works by opening ports in the host machine. A ClusterIP is automatically created (<a href="https://kubernetes.io/docs/concepts/services-networking/service/#publishing-services-service-types" rel="nofollow noreferrer">reference</a>), and through more kube-proxy magic, traffic hitting the NodePort is sent to the ClusterIP, which is in turn sent to a backend pod as appropriate.</p>
<p>You are correct that if the node whose NodePort you are hitting goes down, you won't be able to reach your application.</p>
<pre><code>   traffic
      |
      v
--------------    --------------    --------------
|            |    |            |    |            |
|  NodePort  |    |  NodePort  |    |  NodePort  |
|            |    |            |    |            |
--------------    --------------    --------------
</code></pre>
<h3>How does LoadBalancer work?</h3>
<p>LoadBalancer is an external service, which works by load balancing traffic across the open NodePorts on each node. This means under the cover, when you create a LoadBalancer, a NodePort is created. Generally, this works with a cloud provider: a cloud provider load balancer resource is created that routes traffic to the NodePorts on each node. Health checks are built into the cloud provider load balancer to determine which nodes are up.</p>
<pre><code>                     traffic
                        |
                        v
              --------------------
              |                  |
              |  Cloud Provider  |
              |  Load Balancer   |
              |                  |
              --------------------
      |-----------------|------------------|
      v                 v                  v
--------------    --------------    --------------
|            |    |            |    |            |
|  NodePort  |    |  NodePort  |    |  NodePort  |
|            |    |            |    |            |
--------------    --------------    --------------
</code></pre>
<h3>How does an ingress controller work?</h3>
<p>An ingress controller is (generally) a software component running on the cluster which provides L7 routing (as opposed to L4 routing provided by LoadBalancer). Usually, this will automatically create a LoadBalancer service because the ingress controller is a set of pods running inside the cluster.</p>
<p>Flow occurs something like this:</p>
<p><a href="https://i.stack.imgur.com/3IXQC.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/3IXQC.png" alt="Ingress controller traffic" /></a></p>
<p>Image borrowed from <a href="https://azure.microsoft.com/en-us/blog/application-gateway-ingress-controller-for-azure-kubernetes-service/" rel="nofollow noreferrer">here</a>.</p>
<p>Note the green arrows in front of the pods actually indicate load balancing with ClusterIPs.</p>
<h3>What should I use for external traffic?</h3>
<p>Use LoadBalancer or ingress controller. Don't use NodePort for exactly the reason you described: you have no way of knowing the node is down.</p>
