Kubernetes (K8s) has become the defacto standard for containers orchestration, and since I like to do some more example about it I was needed to setup it on my system.
In the past I’ve use minikube for running a local installation of k8s on my environment but since I recently switched to Linux Mint for most of my development I decided to to use MicroK8s.
MicroK8s is a small, fast and very simple to install, even for clustering, k8s in a single package, created by Canonical the company behind Ubuntu.
One the benefits for using Microk8s on Linux is that its run natively (without virtualization), and since Mint is base on Ubuntu this installation is even easer. On Windows and Mac you will need to use Micropass to run a virtual machine with Ubuntu first.
Minikube uses virtualization in all of the OS that runs, even in linux, and for this is more resource intensive, however is developed by the same team that develop k8s, regardless both are CNF certified k8s solutions. MicroK8s tracks upstream releases of k8s to keep itself up to date with k8s development.
Installing Snap
We will install microk8s using an Snap.
Snaps are linux app packages for desktop, cloud and IoT that are easy to install, secure and cross-platform, they are self-contained, including dependencies, and they could be uninstalled without affecting the rest of your system.
From Ubuntu 14.04 LTS onwards snap is already installed, for previous versions we need to install it with apt :
After installed we could just check the version that we have using :
Installing MicroK8s
Now that we have snap we could install MicroK8s just doing :
In order tu use MicroK8s we need either to use sudo or add our username to the microk8s group:
After login in back again we could not check the status of our k8s cluster with :
If we want to stop or start our cluster we could do it using microk8s.stop
or microk8s.start
whenever we need.
MicroK8s provide several commands to manage our cluster, but embed within the installation for example if we want to see what is running in our cluster using kubectl we need to do:
Adding addons
Microk8s installation is very minimal if we like to have a dashboard we need to enable as an addon, they are several of them so we will enable some basics ones :
Using the dashboard
For using the dashboard we need first to find the IP address in our cluster, for this we could just do :
No we know that our dashboard is running at https://10.152.183.75, however we need a access token for using it, we could get the token with the following commands:
Get from secrets the default-token secret name:
Get the token, that is the value for the secret name:
Now with this token we can logon into our dashboard:
We will choose to use a token and we will use the one that we just get, and finally we will see our dashboard:
Adding a demo application
For configuring further our MicroK8s we will deploy a new application with two replicas:
Now we could check that we have actually two pods runing with :
To access to our applicacion we will expose it trough a NodePort :
We could check our services with :
And since is a NodePort we could use with the IP of our local machine at http://localhost :
If we refresh the page invalidating cache, shift+ctrl+r on Firefox, we will get different containers for this application.
Configuring Kibana
Since we original add the addon fluentd we have a Elasticsearch + Kibana for our pods logs, but we need the URL Kibana, listing the cluster info will display urls for the addons that we have installed:
However before accessing we need the user and password for managing this cluster this could obtain with the command
Now we could visit our Kibana in the url https://127.0.0.1:16443/api/v1/namespaces/kube-system/services/kibana-logging/proxy and use our admin user and password.
However if we like to browse the data when clicking on Discover we will get redirect to create an index, the pattern will be logstash*
:
And finally we will set our Time Filter field name to be @timestamp
:
Now we could click on Create index pattern to complete our index creation.
For testing our index lets deploy another service to our cluster, one application that output on the logs random name into the stdout :
We could check the log of this service with :
Now back into Kibana we could just do a simple filter kubernetes.container_name: random-generator
and select the docker
and log
fields to view the logs
of this application.
Configuring Grafana
As we did for Kibana we could grab the url for Grafana for the cluster info, this case is https://127.0.0.1:16443/api/v1/namespaces/kube-system/services/monitoring-grafana/proxy , we will need our admin user and password as we needed before.
MicroK8s has already configure some dashboard we could choose Pods and then select our default namespace an any of our random-generator pods to look some of the graphs.
The defaul Pod dashboard allow us to just select one pod let modify it to allow to choose several.
Click on the gear icon on Grafana and choose Templating :
Now on the field $podname we click on the Edit button.
We need to activate Multi-value on the Selection Options and then click now Update, sometimes the field Data Source get set to blank we need to set it to influxdb-dataset.
With this now could close the Templating and choose all of the pods for our random-generator to get an update graph with the sum of both pods.
Clean up
Now that we have test some of the tools in our MicroK8s installation we could delete the applications that we do not need anymore :
Conclusions
MicroK8s is very easy to install it took just seconds to download and get it ready, it provide many already config addons that allows use it easily and kickstart a k8s cluster very fast with everything that we need, and is really slim and fast so a really good candidate for IoT deployments.
I’ve enjoy a lot this installation and I’m looking forward to learn more of k8s using MicroK8s, they are several addons that I’ven’t tryout yet such Istio and Knative, maybe in a nearby future.
Reference