diff --git a/README.md b/README.md index ff8864cb8097d01c3acd919ecc2524196c8970a1..b69b5c125de25e8761b374d3ea76011c488b215c 100644 --- a/README.md +++ b/README.md @@ -248,6 +248,11 @@ First, check the **External IP** of the load balancer: kubectl get service loadbalancer ``` +:bulb: Thanks to JSON output, you can get directly the IP address with the command: +```bash +kubectl get service loadbalancer -o=jsonpath='{.status.loadBalancer.ingress[0].ip}') +``` + Then, write a shell script that sends some (at least 10) HTTP requests in a loop via `curl`. Run your script: it should show HTTP reponses from two different IP addresses. It might take some time to show output from both instances, as metallb is not a round-robin-style load balancer. @@ -331,4 +336,31 @@ However it is possible to [set up an SSH "tunnel"](https://www.ssh.com/academy/s ```bash workstation$ kubectl get services ``` - \ No newline at end of file + + ### Expose the loadbalancer's external IP address + +As we have seen, with our cluster setup, the loadbalancer's external IP address is not routable outside the KinD host. +Without further complicating the MetalLB configuration, we can expose this address via the `socat` program, +which can do TCP-port forwarding. + +1. Install `socat` on your remote KinD host: + ```bash + kind$ apt install socat + ``` +1. Set up TCP-port-forwarding from the loadbalancer's external IP to the host's public IP: + ```bash + kind$ LB_IP=$(kubectl get service loadbalancer -o=jsonpath='{.status.loadBalancer.ingress[0].ip}') + kind$ nohup sudo socat -ly tcp-listen:80,reuseaddr,fork "tcp:${LB_IP}:80" & + kind$ sudo sh -c "echo $! > /var/run/socat.pid" + ``` + +Now you should be able to connect to your Web service from the outside: +```bash +workstation$ $ curl KIND_HOST_IP:80 +Hello from Kubernetes! My IP is 10.244.1.4 +``` + +To stop the socat port forwarding, issue: +```bash +kind$ sudo sh -c "kill $(cat /var/run/socat.pid)" +```