Buy @ Amazon

Search This Blog

February 4, 2019

LoadBalancer support with Minikube for Kubernetes


Kubernetes (aka K8s) is an open source system (from Google) for managing containerized applications across multiple hosts; providing basic mechanisms for deployment, maintenance, and scaling of applications.

Minikube is a tool that makes it easy to run Kubernetes locally on your laptop/desktop. Minikube runs a single-node K8s cluster inside a VM on your laptop for users looking to try out K8s or develop with it day-to-day.

Minikube for K8s is a popular method to get your hands dirty learning K8s. And a lot of K8s examples use LoadBalancer to teach how you can expose a service to the external world with k8s.
Exposing an External IP Address to Access an Application in a Cluster is one such tutorial. This tutorial however clearly states that you need a cloud environment to work on this tutorial.

For the purpose of convenience I tried running it all on my local machine that leverages Minikube for k8s. The only trouble is that when you run the command to list services, you will observe that the LoadBalancer service will have its External-IP status as "pending" as shown below:

Minikube doesn't come bundled with a LoadBalancer. So LoadBalancer services run fine with Minikube but with no real external-load balancer being created.

Should you want to access your application services via this load balancer service, you are kind of lost without an external-ip isn't? After all, the application services are internal services having only cluster level visibility.

Thanks to minikube, we do have a work-around. The LoadBalancer service get a node port assigned too so you can access services via $ minikube service my-loadbalancer-service-name to open browser or add --url flag to output service URL to terminal. You should see something like below:
$ minikube service nginx-ils-service --url
http://192.168.39.25:30062

Not happy with the work around and want real meat in your dev-box as well? Then go about trying LoadBalancer emulation using the $ minikube tunnel command; see k8s docs for more on this.

Or a simpler approach is to patch up the EXTERNAL-IP using a kubectl command like -- 
$ kubectl patch service my-loadbalancer-service-name \
-n lb-service-namespace \
-p '{"spec": {"type": "LoadBalancer", "externalIPs":["192.168.39.25"]}}'
Note: This external-ip that was patched was derived from the output of running $ minikube ip command.

Or the cleanest approach possibly is to install a LoadBalancer in your local cluster - you may try MetalLB for this.

1 comment:

Like it or hate it, feel free to share your feedback. Cheers!