First steps with Micro K8S
MicroK8s is a small and lightweight Kubernetes distribution developed by Canonical that can be leveraged for different use cases ranging from installing your own one-node cluster for learning purposes to deploy a much more complex setup involving several nodes. It can runs on different operating systems and architectures like Windows, macOS, ARM, Linux, etc.
Installing
To install it on Linux, you can just follow this instructions [1], but here you have a summary on the fundamental steps:
Since it is available as a Snap package, we can install it by running:
sudo snap install microk8s --classic --channel=1.21
Create a group and add your user to it:
sudo usermod -a -G microk8s $USER
sudo chown -f -R $USER ~/.kube
Test the status:
microk8s status --wait-ready
The following command will show the available endpoints as well:
> kubectl cluster-info
Kubernetes control plane is running at https://kubernetes.devops.com:16443
CoreDNS is running at https://kubernetes.devops.com:16443/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy
Metrics-server is running at https://kubernetes.devops.com:16443/api/v1/namespaces/kube-system/services/https:metrics-server:/proxy
To further debug and diagnose cluster problems, use 'kubectl cluster-info dump'.
To stop the cluster, just type:
microk8s stop
Add-ons
It is recommended to install the add-on dns, which deploys the CoreDNS server to get address resolution and discovery services. This way all the services deployed on Kubernetes can communicate with each other by using names instead of IPs. The following command will install the DNS service.
microk8s enable dns
The storage add-on creates a default Storage Class for allocating storage from the host directory, which means that pods will be able to mount your host folders. Of course, this is just a simple solution for one node cluster, to share storage on several nodes you’ll need something more advanced as Gluster:
microk8s enable storage
Although it is not essential, the ingress add-on is needed to deploy reverse proxies and load balancers, which are fundamental to expose services to your host or to the Internet:
microk8s enable ingress
Registry add-on
The registry add-on can be used to improve the productivity by reducing the time spent in uploading and downloading container images.
microk8s enable registry
By default, the registry is running on a NodePort 32000 of the localhost. You can push your images onto it by doing:
docker push localhost:32000/your-image
or publishing at build time by tagging those images properly:
docker build . -t localhost:32000/my-image:latest
The storage size of the registry can be modified by:
microk8s enable registry:size=30Gi
Installing kubectl
MicroK8S includes its own distribution of [kubectl] that can be executed as:
microk8s kubectl
But I recommend to install the one available for your operating system’s repositories, in the case of Debian:
sudo apt install kubectl
First steps to manage your cluster
If you installed kubectl, you have a .kube/config
file which contains the
configuration to access all the K8S clusters installed on your machine or even
on others, like for example GKE or AWS clusters.
To get the configuration needed to populate the config
file just run this:
microk8s config > .kube/config
If you have a previous configuration stored on your
config
file just use another file to merge both afterwards
To test that kubectl is properly installed just run:
> kubectl get nodes
NAME STATUS ROLES AGE VERSION
linux-laptop Ready <none> 91d v1.20.6-34+e4abae43f6acde
Deploying your first application
To finish this post we are going to deploy the image of a NGINX server by running:
kubectl create deployment nginx --image=nginx
Let’s get info about the pods:
> kubectl get pods
NAME READY STATUS RESTARTS AGE
nginx-6799fc88d8-jj5d4 1/1 Running 0 65m