This repository is a demo repository for my personal blog post.
In this demo repo, we are going to deploy a local Kubernetes cluster using Kind, create a load balancer using MetalLB and manage ingress using NGINX Ingress.
Two applications will be deployed in the cluster:
app-load-balancer: Kubernetes deployment exposed by service of typeLoadBalancerapp-ingress: Kubernetes deployment exposed by a service of typeClusterIpthat gets external traffic because of the Ingress.
If using a MacOS make sure you have docker-mac-net-connect installed and running (this is explained in the blog post).
- Create a Docker bridge network
The MetalLB IPs need to be in the range of the IPs of the cluster. I good strategy is to before the Kubernetes cluster creation to create the range of IPs we want our Kubernetes cluster to be in. This way the Kubernetes manifest for the MetalLB ip pool (IPAddressPool) won't need to be modified. This docker network will be used by our Kind cluster on the following step.
docker network create --subnet 172.100.0.0/16 custom-kind-network- Install Devbox dependencies of the demo
devbox shell- Create a Kind cluster and install MetalLB and Ingress NGINX
devbox run initThis installs and waits for the resource to be healthy so it might take a few minutes to finish this command execution.
- Install
app-load-balancerapplication
devbox run app-load-balancer- Install
app-ingressapplication
devbox run app-ingress- Check access to the
app-load-balancerapplication
APP_LB_IP=$(kubectl get svc app-load-balancer -n default -o jsonpath='{.status.loadBalancer.ingress[0].ip}')
echo "Open your browser on the following URL: http://${APP_LB_IP}"
curl $APP_LB_IP- Check access to the
app-ingressapplication
The app-ingress application is exposed by the NGINX Ingress Load Balancer and routed accordingly by the Ingress resource.
Get the NGINX Ingress IP
INGRESS_LB_IP=$(kubectl get svc ingress-nginx-controller -n ingress-nginx -o jsonpath='{.status.loadBalancer.ingress[0].ip}')
echo "Add $INGRESS_LB_IP to /etc/hosts"Now add this IP to the /etc/hosts file
echo "$INGRESS_LB_IP app-ingress.local" | sudo tee -a /etc/hostsNow access http://app-ingress.local. Check if the application is accessible.
When done, remember to delete the /etc/hosts entry.
- Destroy the demo