This post is merely a reference guide for me to setup Kubernetes with Ingress.
LoadBalancer lives on L4 on the OSI model, Ingress services lives on L7 of the OSI model.
Use ingress for a single app with a single domain to be mapped to an IP address, use ingress to map multiple subdomains to multiple apps within your cluster.
For nicer infographs, refer to Mathhew Palmer's blogpost.
sudo snap install microk8s --classic
microk8s.start
microk8s.kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/master/deploy/static/mandatory.yaml
microk8s.enable ingress
You can skip this step if you wanna host your image on a public/private repository.
docker run -p 5000:5000 registry
git clone https://github.com/kendricktan/microk8s-ingress-example
cd microk8s-ingress-example
docker build . -t my-microk8s-app
docker tag my-microk8s-app localhost:5000/my-microk8s-app
docker push localhost:5000/my-microk8s-app
microk8s.kubectl apply -f bar-deployment.yml
microk8s.kubectl apply -f foo-deployment.yml
microk8s.kubectl apply -f ingress.yml
If you skip this step you'll get a 503 service unavailable
microk8s.kubectl expose deployment foo-app --type=LoadBalancer --port=8080
microk8s.kubectl expose deployment bar-app --type=LoadBalancer --port=8080
curl -kL https://127.0.0.1/bar
curl -kL https://127.0.0.1/foo