Test kubernetes localy with microk8s on your linux machine

When one develop a software, one want to test is localy first because things never works the first time. The last time I rememebr one code that was longer than 10 mines works out of the box was about 2 years ago. The same hapen when we create the configuration (yaml) files for kububernets because and even more if we use a his packat manager named helm.

There exist many tools to deploy kubernets localy, one of them is microk8s. Microk8s is a tool (or package) developed by Canonoical, the enterpice behind the linux distributation, named ubuntu. It make our komputer to a node and do not need a virtual machine like it do Minicube, what make it much less memeory intensive. The disadvantage is that you can not have a multi node clsuter with microk8s, but most of the time this is not necesarry.

Install microk8s

Microk8s can only by installed as a snap packate on pcs that run linux. The good is that the snap packate manager (nemed snapcraft) can be installed on almost every linux distributaton and it is instaled per default on ubuntu.

First, let us make sure that snapcraft is installed on you computer, by typing:

snap --version

Second, install microk8s:

snap install microk8s --classic

By last, let us check if microk8s works:

microk8s.kubectl version

Configure kubectl

Type microk8s.kubectl can be very fastiduos, by the time. The good news are, that we can use the well known “kubectl” comand, in the same way as we use it with every other kubernetes cluster.

First, install kubectl on you machine:

snap install kubectl --classic

Second, configure it:

microk8s.kubectl config view --raw > $HOME/.kube/config

Finally, check if it works:

kubectl get nodes

Configure the helm packet manager

Helm use the $HOME/.kube/config file that we have configured in the last section. If you have not configured it yet, then just execute the last command of the kubectl section.

First, make sure that $HOME/.kube/config is configured by typing:

cat $HOME/.kube/config | grep microk8s

Second, install helm:

snap install helm

Third, initialize it:

 helm init

Third, check if it works (maybe you have to wait some seconds):

 helm ls

Deploy example app (wordpress)

To check if all works, let us install wordpress

First, install wordpress:

helm install --name wordpress stable/wordpress

Second, get the local ip and enter it on the browser:

kubectl get services

Finally, after check on the browser that all works, delete it:

helm delete --purge wordpress