Thursday, June 27, 2019

LoadBalanced Kubernetes

Up to now we've been using a NodePort as the access to services. This can have a few significant drawbacks:
  • If you have multiple pods providing a service it can be difficult or impossible for clients to use them all effectively
  • You cannot predict the port hosting your application and that port will change every time you deploy. For example, instead of getting port 443 for each application you'd get a random port assigned between 30,000 and 32,767
Public cloud providers have their own load balancer solutions, which are generally efficient and transparent but when using on-premise or "bare metal" we need more software or hardware to do this. MetalLB is a great solution for this; it's software only, free, easy to install and configure, and while not perfect, does a good job for most use cases.

I've documented my steps for reference but I encourage you to review the official documentation [https://metallb.universe.tf/installation/]. It's well written and about as straight forward as you can get.

MetalLB Install

Not much to say here. Run the official install, be happy.
kubectl apply -f https://raw.githubusercontent.com/google/metallb/v0.8.0/manifests/metallb.yaml

MetalLB Configuration

I've opted for the simpler and universal L2 load balancing mechanism. It might not be perfect but I don't need to get the network team engaged and it works well enough for my use case. Again, the documentation [https://metallb.universe.tf/configuration/] is well written and straight forward. Here's my setup in case you want to see it.
$ cat metal-config.yaml 
apiVersion: v1
kind: ConfigMap
metadata:
  namespace: metallb-system
  name: config
data:
  config: |
    address-pools:
    - name: default
      protocol: layer2
      addresses:
      - 10.9.176.10-10.9.176.250
You can also setup multiple pools each with a different name but this is more complicated than I need.

Using LoadBalancer

If you have just the one address pool then it's as simple as specifying LoadBalancer as your service type. If you have multiple pools then you'll need to annotate your service. Again, the documentation is clear and helpful [https://metallb.universe.tf/usage/. Once the service is deployed you should have an external-ip assigned and from there you can dynamically assign a DNS address as we'll be talking about in the next article.

No comments:

Post a Comment