(8 votes, average: 4.00 out of 5)
Loading...
Using MetalLB And Traefik for Load balancing on your Bare Metal Kubernetes Cluster – Part 1
Running a Kubernetes Cluster in your own data center on Bare Metal hardware can be lots of fun but also can be challenging. One of the changeless are exposing your service to an external Load Balancer, Kubernetes does not offer an implementation of an external load-balancer for bare metal cluster implementations. The Kubernetes implementations of Network Load Balancers are only available on specific Cloud Providers like AWS, GCP, Azure, etc.. and is enabled by specifying the –cloud-provider= option. leaving a gap/challenge if you create your own Bare Metal Kubernetes Cluster. While their are many workarounds to address this issue most of them are not perfect and have their own list of challenges. while I was looking for a for a solution, most recently came across a project called MetalLB, at first I was quite sceptical if its going to work, but after testing this for a while I have to say, I am quite happy with the solution. Below is a quote from the MetalLB website.Kubernetes does not offer an implementation of network load-balancers (Services of type LoadBalancer) for bare metal clusters. The implementations of Network LB that Kubernetes does ship with are all glue code that calls out to various IaaS platforms (GCP, AWS, Azure…). If you’re not running on a supported IaaS platform (GCP, AWS, Azure…), LoadBalancers will remain in the “pending” state indefinitely when created.Note: On the MetalLB project website they warn you as follows. MetalLB is a young project. You should treat it as a beta system. The project maturity page explains what that implies., however I using this for a while and it seems quite mature. One last note, I am continuing to use Traefik for internal micro services / load balancing which works great, however MetalLB helps exposing your service for external use. Now that we have that out of the way, lets see what it takes to install and configure MetalLB on your Kubernetes cluster.
Installing MetalLB on your Kubernetes cluster
You have two options to install MetalLB on your Kubernetes cluster.- Use the a per-packged MetalLBHelm chart.
- Install / configure manually by applying a YAML configuration file.
Installing MetalLB with Helm
Note: To use Helm you first need to install/configure Helm/Tiller on your Kubernetes cluster. you can see a how-to step by step process here Part 1 and here Part 2. First, lets create a configmap which will be using at helm install time, the below configmap was used with a flannel configuration. cat values.yamlconfigInline: address-pools: - name: default protocol: layer2 addresses: - 10.90.10.190-10.90.10.199Note: There are a number of networking options you can specify likeprotocol: BGP, etc.. please take a look at the MetalLB website for a full list of options. Once helm is available on your cluster, just run the below to install MetalLB (omit the -tls if your are not using a secure configuration). Note: The below configuration installs MetalLB with helm including a configmap. (otherwise you get the errors below)
helm install --name=metallb --namespace=metallb-system -f values.yaml stable/metallb --tls # If all is ok, you shuld see something like the below message at the end of the helm deploy. MetalLB is now running in the cluster. LoadBalancer Services in your cluster are now available on the IPs you defined in MetalLB's configuration. To see IP assignments, try `kubectl get services`. # Without specifying a configmap. helm install stable/metallb --name=metallb --namespace=metallb-system --tlsErrors you will see if you don’t specify / use a configmap to list your network range, etc..
MetalLB is now running in the cluster. WARNING: you specified a ConfigMap that isn't managed by Helm. LoadBalancer services will not function until you add that ConfigMap to your cluster yourself.You can also check the logs to make sure all looks good, by running the below
kubectl logs -l component=speaker -n metallb-systemIf your cluster is not configured to use RBAC, you might run somthing like the below.
helm install \ --set rbac.create=false \ -f values.yaml \ stable/metallb --name=metallb --namespace=metallb-system --tlsAn example configmap if using a BGP overlay system.
# cat values.yaml configInline: peers: - peer-address: 10.0.0.1 peer-asn: 64512 my-asn: 64512 address-pools: - name: default protocol: bgp addresses: - 10.90.10.190-10.90.10.199If all works correctly, you should now have a MetalLB working configuration. You can also check what helm report about the installation.
helm list --tls NAME REVISION UPDATED STATUS CHART APP VERSION NAMESPACE metallb 1 Mon Feb 11 19:52:17 2019 DEPLOYED metallb-0.8.4 0.7.3 metallb-systemTo remove MetalLB from your cluster, just run the below.
helm delete --purge metallb --tls
Installing MetalLB manually
To install MetalLB manually, you would do so in cases ware you don’t have a helm configuration or you would like to install a version not available in the helm repository. To MetalLB from the web just run the below.kubectl apply -f https://raw.githubusercontent.com/google/metallb/master/manifests/metallb.yamlYou can also create a deploy file, like the one below.
cat deploye_metal.yaml apiVersion: v1 kind: ConfigMap metadata: namespace: metallb-system name: config data: config: | address-pools: - name: metal-lb-ip-space protocol: layer2 addresses: - 10.90.10.190-10.90.10.199Then to install just run the below, this will already include your IP address definitions.
kubectl apply -f deploye_metal.yamlA quick check on your pods will reveal something like the below, note the metallb-controller and metallb-speaker.
kubectl get po --all-namespaces metallb-system metallb-controller-776cdd69dc-4lzcx 1/1 Running 0 9d metallb-system metallb-speaker-4xrnm 1/1 Running 0 9d metallb-system metallb-speaker-g59h6 1/1 Running 0 9d metallb-system metallb-speaker-jzh4g 1/1 Running 0 9d metallb-system metallb-speaker-k6spd 1/1 Running 0 9d
MetalLB in action
To test MetalLB working, you can deploy any pod(s) to you cluster, and specify the Cluster Type as LoadBalancer. An example Nginx deployment is below.# cat nginx_load_balance.yaml apiVersion: apps/v1beta2 kind: Deployment metadata: name: nginx spec: selector: matchLabels: app: nginx replicas: 2 template: metadata: labels: app: nginx spec: containers: - name: nginx image: nginx:1 ports: - name: http containerPort: 80 --- apiVersion: v1 kind: Service metadata: name: nginx spec: ports: - name: http port: 80 protocol: TCP targetPort: 80 selector: app: nginx type: LoadBalancerNow, just run the below to deploy to your cluster.
kubectl apply -f nginx_load_balance.yamlNow take a look on your Kubernets Cluster services, note the EXTERNAL-IP that got assigned automatically by MetalLB.
kubectl get svc --all-namespaces NAMESPACE NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE default kubernetes ClusterIP 10.30.0.1In the next post Part 2 – I will show you how to combine this with Traefik for internal Micro-services Load Balancing. I hope you enjoyed reading Using MetalLB And Traefik Load Balancing For Your Bare Metal Kubernetes Cluster, give it a thumbs up by rating the article or by just providing feedback. You might also like – realted to Docker Kubernetes / micro-services.443/TCP 14d kube-system tiller-deploy ClusterIP 10.30.4.154 44134/TCP 13d default nginx LoadBalancer 10.30.2.56 10.90.10.190 80:30827/TCP 2s ...
4
1
vote
Article Rating
Nice tutorial. But i can’t figure out yet how to use REAL external Ips.
For a simple domain.com redirect to your nginx sample its nearly impossible as 10.x.x.x cant be reached from internet, just from sshed hosts/nodes
Hi and welcome to my blog. First sorry for the delay, I was away with no access to the Internet. I am not sure I understand your question, but will try to answer accordingly. The IP Address range provided in the “configmap” are the IP’s MetalLB will use, these IP’s are the public IP’s Metal LB will auto allocate to your service. In my example it was addresses: – 10.90.10.190-10.90.10.199 Of course, the IPs need to be accessible form your kubernetes Nodes. If you closely look a bit further, you will see the below example. 10.30.2.56 (a cluster service IP)… Read more »
five star just for the diagram XD
Appreciate your blog post. Given this was written about a year ago, have you found that the following still holds true:
Kubernetes does not offer an implementation of an external load-balancer for bare metal cluster implementations.
MetalLB is still in Beta, so looking for alternative solutions.
Thanks
Hi and welcome to my blog.
I haven’t researched recently if anything changed. However, there are other commerical options available like F5 as well as nginx which is now owned by F5.
P.s. if you do find a good alternative solution, I would really appreciate if you let me know.
Thanks again for visiting my blog,
Eli