I don't understand why you would use HAProxy here. Generally on k8s, you'd use a LoadBalancer (backed by eg. metallb on bare metal) to route external traffic into your cluster. This goes for both 'normal' payloads/services and the Kubernetes API endpoint itself.
In addition, it seems like the quorum configuration shown here is pretty poor - only uses two nodes. This is a recipe for split-brain.
Which will be internally backed by exactly the kind of infra the OP is describing.
* MetalLB doesn't work in most cloud environments because the networking is weird.
* MetalLB is extremely new while VIP+Nginx/HAP has been working forever and is the standard choice for implementing a HA LB.
* MetalLB plays the same exact role as what the OP is laying just in a different style that has nothing to do with k8s. MetalLB could have been unicast VRRP for all it matters. The value is the code to instrument the LB from within k8s which can work with any external LB.
In k8s load balancers are inherently external to the cluster and need to maintain their state. It doesn't really matter how this is accomplished but Pacemaker/Corosync is the "off the shelf and supported by your distro with good docs" option.
"Why don't you just use $managed_k8s?" -- Because it defeats the purpose of learning how to administer it.
Sibebar:
Why is everybody treating k8s like it's something special and magical here and needs it's own solution? Your k8s cluster is a group of app servers with a little bit of networking sprinkle so that you can reach every app from any node and some API sprinkle to allow the app servers to instrument external resources.
The k8s cluster needs something outside itself to route traffic to all the nodes. There isn't a way around this. From an infra perspective a k8s cluster is a black box of generic app servers that want to be able to control the LB with an API integration. Nothing else.
> MetalLB doesn't work in most cloud environments because the networking is weird.
Sure, but most cloud environments are handled by other LoadBalancer controllers specific to that environment. See: Kubernetes Cloud Controller Manager.
> MetalLB is extremely new while VIP+Nginx/HAP has been working forever and is the standard choice for implementing a HA LB.
I do not disagree with that. Hell, I've filed/fixed metallb issues myself already.
> MetalLB plays the same exact role as what the OP is laying just in a different style that has nothing to do with k8s. MetalLB could have been unicast VRRP for all it matters. The value is the code to instrument the LB from within k8s which can work with any external LB.
Sure, but the author is not describing it to act as a Kube LoadBalancer, but as a separate entity with its own configuration. So to actually then use Kubernetes meaningfully they still need to bring something that actually fulfills LoadBalancer requests. Might as well use the same code for both cases.
> In k8s load balancers are inherently external to the cluster and need to maintain their state. It doesn't really matter how this is accomplished but Pacemaker/Corosync is the "off the shelf and supported by your distro with good docs" option.
Why? You can easily keep all state and components within k8s, as MetalLB does.
> The k8s cluster needs something outside itself to route traffic to all the nodes. There isn't a way around this.
Sure, that's called BGP to a ToR that can then ECMP-route traffic where needed, and that's what metallb gives you.
> Why? You can easily keep all state and components within k8s, as MetalLB does.
I guess I should have said "its own state." I mean you can shove just about any software into a container and get k8s to run it but the point is that k8s can't load balance by itself without managing an environment specific external resource. Because I would count BGP as using the router in the same way that it would use HAProxy.
Would "load balancers are necessarily on the outside of the cluster" be better phrasing?
Are you sure? All encountered k8s installations (including ones rolled from scratch by me) use Ingress controllers as the option for getting traffic into the cluster. Community NGINX Ingress controller is the de facto standard. One need to use LoadBalancer service type because of its managed origin (metallb is a different beast and I wouldn't recommend it, if you need to load balance traffic to your ingresses on on-premises infra, it's better to do it outside of k8s). Anyway, you lose all flexibility and observability of Ingress solutions with LoadBalancer service types if you use them directly as traffic routers to your backend.
They're complementary - LoadBalancer Services are L3, Ingresses are L4+. More often than not in-cluster Ingress providers (eg. nginx-ingress-controller) will in fact use LoadBalancers to actually route L3 traffic into the cluster in the first place.
Without being able to create LoadBalancer services there's no easy way to get any traffic into your cluster other than using NodePorts, and these have tons of shortcomings.
NodePort is a bad practice for a such case, you are right. You get additional unnecessary routing on CNI level between the cluster nodes just to get traffic into the Ingress controller pod, for example. The solution here is to use hostNetwork mode with the pool of workers solely dedicated to scheduling Ingress controllers. Traffic directly hits NGINX/Envoy/HAProxy/Traefik/whatever and gets into the cluster without additional intermediates. You need a load balancing solution for this pool of Ingress controllers, that's right, but as I said before, this setup gives you the flexibility to cook load balancing as you desire.
BTW, community NGINX Ingress controller is able to ingress L3 (TCP) traffic into the cluster.
> You need a load balancing solution for this pool of Ingress controllers, that's right, but as I said before, this setup gives you the flexibility to cook load balancing as you desire.
Sure, but this means that you cannot use LoadBalancers, which is painful. It means every payload has to be configured both at k8s level and then externally. That somewhat defeats the use of k8s as a self-service platform internally in an organization (other dev/ops teams need to go through a centralized ops channel to get traffic ingressing into the cluster if for some reason they can't use an Ingress).
> BTW, community NGINX Ingress controller is able to ingress L3 (TCP) traffic into the cluster.
Yes, but it's configurable via a single ConfigMap (which limits self-service if you're running a multi-tenant orga-wide cluster, unless you bring your own automation), and still you only have one namespace of ports, ie. a single external address for all ports - unless you complicate your 'external' LB system even further.
With all these caveats, I really don't understand why not just run metallb.
Do you know whether ingress controllers like nginx-ingress-controller honor the readiness status of pods from a service and so only sends traffic to ready pods from the concerned deployment?
I remember seeing documentation on this a while ago, but I can't seem to find any documentation from nginx-ingress that talks about how nginx-ingress uses readinessprobe or livenessprobe.
I was looking into this because if I have a pod with 3 containers, if 1 container wasn't running, nginx-ingress stopped serving traffic. I actually want to continue serving traffic if a certain container is still running, not all 3 running necessarily
Do you know or have any documentation on how nginx-ingress actually does its readiness/liveness checks?
ingress-nginx doesn't do readiness/liveness checks itself; the kubelet does[1].
If any of the containers in a Pod aren't ready, the endpoints controller[2] removes the Endpoint object corresponding to that Pod. ingress-nginx watches these Endpoints objects[3] to determine which Pods it should send traffic to.
Edit: As to your use case, I think you should remove the readiness probe from that one container you don't care about.
Yes, Ingress resources implicitly assume that you want to get HTTP(S) traffic into the cluster, but as for example, ingress-nginx is able to expose gRPC via additional annotations and generic L3 via related ConfigMap.
This isn't always true. On GKE for example, LoadBalancer is very expensive first of all. Second of all, if you use LetsEncrypt such as cert-manager, the GKE load balancer is awful to configure and takes forever to get a cert.
Also by using the GKE load balancer for ingress, you lose out on a lot of things, like password protection, or certain rules you want with nginx.
I've tried my best to stick with GKE LoadBalancer, but it's just an awful experience. Now I have GKE to load balance traffic to nginx-ingress, the level 3 load balancer is just not flexible enough and in general annoying to configure.
I think you're conflating the GKE Ingress Controller (which you don't have to use, and yes, confusingly it's named the GCLB controller, but that's because it configures L7 GCP LB's, not because it's there for k8s LBs) with the GKE load balancer controller/provider for LoadBalancer services (which you do have to use, even if you run nginx-ingress-controller).
And yes, I agree that both are extremely slow to reconfigure and the that Ingress controller is inflexible.
I'm not saying that you need to always use a LoadBalancer for all payloads. But you do need one to ingress traffic in a sensible manner if you're running your own N-I-C (which you have to do on bare metal, and which, as you said, you end up using even on GKE).
Keep an open mind, you can add as many HAProxy as you like, here for practical reasons it is shown with only 2 but it could be 3, 5, 7 ...
In time, this LB is for handling the availability and balance of the Control Plane, without direct exposure from the Master Nodes.
In addition, it seems like the quorum configuration shown here is pretty poor - only uses two nodes. This is a recipe for split-brain.