Microk8s, MetalLB, ingress-nginx - How to route external traffic? Microk8s, MetalLB, ingress-nginx - How to route external traffic? kubernetes kubernetes

Microk8s, MetalLB, ingress-nginx - How to route external traffic?


Short answer:

  1. You only need (and probably have) one IP address. You must can ping it from outside Microk8s machine.
  2. Here's the error. Remove this step

Long answer by example:

Clean Microk8s. Only one public IP (or local machine IP. In your use case, I'll use 192.168.0.90).

How do you test? For example

curl -H "Host: blue.nginx.example.com" http://PUBLIC_IP

from outside the machine.

Run the test. It must fail.

Enable microk8s dns and ingress

microk8s.enable dns ingress

Run the test. Fails?

If it's the same error then: You need metallb

  • With Internet public IP

    microk8s.enable metallb:$(curl ipinfo.io/ip)-$(curl ipinfo.io/ip)

  • With LAN IP 192.168.0.90

    microk8s.enable metallb:192.168.0.90-192.168.0.90

Run the test again

If Test NOT return 503 or 404 then: You can't do next steps. Perhaps you have a network problem or firewall filter.

The Ingress layer

Our test arrived to the Microk8s Ingress controller. He doesn't know what to do and return a 404 error (sometimes 503).

That's ok. Go next!

I'll use an example from https://youtu.be/A_PjjCM1eLA?t=984 16:24

[ Kube 32 ] Set up Traefik Ingress on kubernetes Bare Metal Cluster

set kubectl alias

alias kubectl=microk8s.kubectl
Deploy apps
kubectl create -f https://raw.githubusercontent.com/justmeandopensource/kubernetes/master/yamls/ingress-demo/nginx-deploy-main.yamlkubectl create -f https://raw.githubusercontent.com/justmeandopensource/kubernetes/master/yamls/ingress-demo/nginx-deploy-blue.yamlkubectl create -f https://raw.githubusercontent.com/justmeandopensource/kubernetes/master/yamls/ingress-demo/nginx-deploy-green.yaml
Expose apps in the internal cluster network. ClusterIP by default.
kubectl expose deploy nginx-deploy-main --port 80kubectl expose deploy nginx-deploy-blue --port 80kubectl expose deploy nginx-deploy-green --port 80

Run Test. It doesn't work... yet.

Ingress rule example: how to delivery by host name

Configure the hosts nginx.example.com, blue.nginx.example.com, and green.nginx.example.com and distribute requests to exposed deployments:

kubectl create -f https://raw.githubusercontent.com/justmeandopensource/kubernetes/master/yamls/ingress-demo/ingress-resource-2.yaml

Run this tests:

curl -H "Host: blue.nginx.example.com" http://PUBLIC_IP

Now you'll have a response like

<h1>I am <font color=blue>BLUE</font></h1>

You can play with

curl -H "Host: nginx.example.com" http://PUBLIC_IPcurl -H "Host: blue.nginx.example.com" http://PUBLIC_IPcurl -H "Host: green.nginx.example.com" http://PUBLIC_IP

Conclusion:

  • We only have 1 IP address and multiple hosts.
  • We have 3 different services using the same port.
  • The requests distribution is done using Ingress.


Just started with MicroK8s - it appears to have great promise. After combing through info sites and docs; was able to implement bare metal demonstration with Traefik Ingress Controller (with Custom Resource Definitions and Ingress Routes); Linkerd service mesh; and metallb load balancer. This was done on a VirtualBox Guest VM running Ubuntu 20.04; also included with this github link is "way" to expose Traefik Ingress Controller external IP provided by metallb external to Guest VM. See https://github.com/msb1/microk8s-traefik-linkerd-whoami .

Prefer this implementation to what is shown in Youtube link as it includes working service mesh and uses custom resource definitions for Ingress (which is unique to Traefik and one of reasons to proceed with Traefik as opposed to other Ingress Controllers).

Hope this help others - should be able to build awesome deployments with MicroK8s following this demo (which is current focus).