In order to learn kubernetes, I had to install a single node kubernetes cluster on my dev machine. About 2 years ago, minikube
was the only one available. I found out the steps to install it were not easy nor simple. Besides it doesn’t have LoadBalancer type of service. Therefore there was no external IP (of the cluster) for accessing the service. Unfortunately, the ingress controller didn’t work either.
Luckily, a month ago I found microk8s. It’s a snap
to install it on my dev machine running Ubuntu 16.04.6 LTS (xenial):
$ sudo snap install microk8s --classic
# Add user 'ryan'
$ sudo usermod -a -G microk8s ryan
$ sudo chown -f -R ryan ~/.kube
# Check status
$ sudo microk8s.status --wait-ready
# Access it:
$ sudo microk8s.kubectl get namespaces
microk8s
comes with many plugins. One of them is metallb – the LoadBalancer. Below is the list of steps to expose your service with a LoadBalancer:
1. Add more IP addresses to the network interface
My network interface is eno1
. You can check which one by using ip addr
command. I added IP address range 192.168.1.[120-124].
$ ip addr
2: eno1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether e0:3f:49:af:89:80 brd ff:ff:ff:ff:ff:ff
inet 192.168.1.101/24 brd 192.168.1.255 scope global dynamic eno1
$ sudo ip addr add 192.168.1.120/24 broadcast 192.168.1.255 dev eno1 label eno1:1
$ sudo ip addr add 192.168.1.121/24 broadcast 192.168.1.255 dev eno1 label eno1:2
$ sudo ip addr add 192.168.1.122/24 broadcast 192.168.1.255 dev eno1 label eno1:3
$ sudo ip addr add 192.168.1.123/24 broadcast 192.168.1.255 dev eno1 label eno1:4
$ sudo ip addr add 192.168.1.124/24 broadcast 192.168.1.255 dev eno1 label eno1:5
$ ip addr
2: eno1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether e0:3f:49:af:89:80 brd ff:ff:ff:ff:ff:ff
inet 192.168.1.101/24 brd 192.168.1.255 scope global dynamic eno1
valid_lft 66892sec preferred_lft 66892sec
inet 192.168.1.120/24 brd 192.168.1.255 scope global secondary eno1:1
valid_lft forever preferred_lft forever
inet 192.168.1.121/24 brd 192.168.1.255 scope global secondary eno1:2
valid_lft forever preferred_lft forever
inet 192.168.1.122/24 brd 192.168.1.255 scope global secondary eno1:3
valid_lft forever preferred_lft forever
inet 192.168.1.123/24 brd 192.168.1.255 scope global secondary eno1:4
valid_lft forever preferred_lft forever
inet 192.168.1.124/24 brd 192.168.1.255 scope global secondary eno1:5
valid_lft forever preferred_lft forever
2. Enable microk8s metallb add-on:
$ sudo microk8s.enable metallb
Enabling MetalLB
Enter the IP address range (e.g., 10.64.140.43-10.64.140.49): 192.168.1.120-192.168.1.124
3. Test it by running nginx
with 2 replicas:
$ microk8s.kubectl run nginx --image nginx --replicas 2
$ microk8s.kubectl expose deployment nginx \
--port 8090 --target-port 80 \
--type LoadBalancer \
--selector=run=nginx \
--name nginx
$ kubectl get svc/nginx
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
nginx LoadBalancer 10.152.183.245 192.168.1.120 8090:30389/TCP 4s
Open http://192.168.1.120:8090 on the browser!