Let’s now create a microbot deployment with three pods via the kubectl cli. Run this on any of the control plane nodes:
microk8s kubectl create deployment microbot --image=dontrebootme/microbot:v1
microk8s kubectl scale deployment microbot --replicas=3
To expose our deployment we need to create a service:
microk8s kubectl expose deployment microbot --type=NodePort --port=80 --name=microbot-service
After a few minutes our cluster looks like this:
> microk8s kubectl get all --all-namespaces
NAMESPACE NAME READY STATUS RESTARTS AGE [0/594]
kube-system pod/calico-kube-controllers-847c8c99d-mjgqn 1/1 Running 0 1m
kube-system pod/calico-node-2x7t7 1/1 Running 0 1m
kube-system pod/calico-node-vkzg8 1/1 Running 0 1m
default pod/microbot-5f5499d479-n647g 1/1 Running 0 30s
default pod/microbot-5f5499d479-x25lc 1/1 Running 0 35s
default pod/microbot-5f5499d479-xrbf2 1/1 Running 0 40s
NAMESPACE NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
default service/kubernetes ClusterIP 10.152.183.1 <none> 443/TCP 1m
default service/microbot-service NodePort 10.152.183.99 <none> 80:30017/TCP 42s
NAMESPACE NAME DESIRED CURRENT READY UP-TO-DATE AVAILABLE NODE SELECTOR AGE
kube-system daemonset.apps/calico-node 2 2 2 2 2 kubernetes.io/os=linux 1m
NAMESPACE NAME READY UP-TO-DATE AVAILABLE AGE
kube-system deployment.apps/calico-kube-controllers 1/1 1 1 1m
default deployment.apps/microbot 3/3 3 3 40s
NAMESPACE NAME DESIRED CURRENT READY AGE
kube-system replicaset.apps/calico-kube-controllers-847c8c99d 1 1 1 1m
default replicaset.apps/microbot-5f5499d479 3 3 3 40s
At the very top, we have the microbot pods, service/microbot-service
is the second in the services list. Our service has a cluster IP through which we can access it. Notice, however, that our service is of type NodePort. This means that our deployment is also available on a port on the host machine; that port is randomly selected and in this case, it happens to be 30017.
Access the application from your browser
In order to access the microbot service from your local browser, you need to point it to the IP of one of your VMs and the port the service is exposed from.
Use the ip a
command in one of your VMs to see its IP address:
>ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: ens4: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
link/ether 52:54:00:c9:b1:2f brd ff:ff:ff:ff:ff:ff
inet 10.166.194.208/24 brd 10.166.194.255 scope global ens4
valid_lft forever preferred_lft forever
inet6 fe80::5054:ff:fec9:b12f/64 scope link
valid_lft forever preferred_lft forever
5: vxlan.calico: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1410 qdisc noqueue state UNKNOWN group default
link/ether 66:ae:23:b9:4c:ca brd ff:ff:ff:ff:ff:ff
inet 10.1.202.0/32 brd 10.1.202.0 scope global vxlan.calico
valid_lft forever preferred_lft forever
inet6 fe80::64ae:23ff:feb9:4cca/64 scope link
valid_lft forever preferred_lft forever
6: cali6d8cc5df688@if3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1440 qdisc noqueue state UP group default
link/ether ee:ee:ee:ee:ee:ee brd ff:ff:ff:ff:ff:ff link-netns cni-f8c70512-4448-aa9d-4e8a-41d780c92f43
inet6 fe80::ecee:eeff:feee:eeee/64 scope link
valid_lft forever preferred_lft forever
9: cali6f43c081ad9@if3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1440 qdisc noqueue state UP group default
link/ether ee:ee:ee:ee:ee:ee brd ff:ff:ff:ff:ff:ff link-netns cni-78561df6-7132-a1ba-9b60-30d1010d555a
inet6 fe80::ecee:eeff:feee:eeee/64 scope link
valid_lft forever preferred_lft forever
10: calic0bf7d8c9d3@if3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1440 qdisc noqueue state UP group default
link/ether ee:ee:ee:ee:ee:ee brd ff:ff:ff:ff:ff:ff link-netns cni-61873c9a-7b3c-e0ac-ab6a-bd5ea85a0b6c
inet6 fe80::ecee:eeff:feee:eeee/64 scope link
valid_lft forever preferred_lft forever
In our case, the ens4 is the designated network interface with the IP of 10.166.194.208
We can now open a browser, point it to 10.166.194.208:30017
and marvel at our microbot!