Setup MicroK8s Kubernetes cluster on Ubuntu with ingress and dashboard
So far I have been using only Docker Desktop and the Kubernetes provided with it. It is good enough for development, but I wanted to expose my services so I can access them through the internet and to know that they will start again on machine restart. In addition I would like to run them in a virtual machine (VM), so Windows is no longer an option. That means I need something else. For me the option is Linux and the new question is what small Kubernetes cluster to use. First I was going to use k3s, but after some more research I have decided to go with MicroK8s. Not saying this will be final, but for now will continue with that.
I like Ubuntu and this was part of why I picked MicroK8s. During the installation of the server I have picked the some packages available.
After the installation is complete reboot the VM and log in.
Now it is time to enable some Add-Ons. I think they don’t need an explanation.
sudo microk8s enable ingress sudo microk8s enable dashboard sudo microk8s enable dns sudo microk8s enable storage
One Add-on that needs a little explanation is host-access. This add-on enables the access to services running on the host machine via fixed IP address.
sudo microk8s enable host-access
The code above will create a new local interface named lo:microk8s with default IP address 10.0.1.1.
If you want to use different IP address you can provide it when enabling the add-on.
sudo microk8s enable host-access:ip=<ip-address>
To be able to login into the Dashboard you need a token. You can get it with these commands:
token=$(sudo microk8s kubectl -n kube-system get secret | grep default-token | cut -d " " -f1) sudo microk8s kubectl -n kube-system describe secret $token
Forward the port and enable to be accessed outside of the machine
sudo microk8s kubectl port-forward -n kube-system service/kubernetes-dashboard 10443:443 --address 0.0.0.0
Good that now we have the cluster. It comes with it’s own version of kubectl, but this is not very convenient for me since I have only one installation on the VM and prefer to use only kubectl instead of microk8s kubectl.
Update the apt package index and install packages needed to use the Kubernetes apt repository.
sudo apt-get update sudo apt-get install -y apt-transport-https ca-certificates curl
Download the Google Cloud public signing key.
sudo curl -fsSLo /usr/share/keyrings/kubernetes-archive-keyring.gpg https://packages.cloud.google.com/apt/doc/apt-key.gpg
Add the Kubernetes apt repositoty.
echo "deb [signed-by=/usr/share/keyrings/kubernetes-archive-keyring.gpg] https://apt.kubernetes.io/ kubernetes-xenial main" | sudo tee /etc/apt/sources.list.d/kubernetes.list
Update the apt package index with the new repository and install kubectl.
sudo apt-get update sudo apt-get install -y kubectl
Now we need to do some configuration so the kubectl points to the right cluster.
cd $HOME mkdir .kube cd .kube sudo microk8s config > config
Then connect MicroK8s to kubectl
kubectl config use-context microk8s
Verify the kubectl configuration
Install Helm through snap
sudo snap install helm --classic
When using Helm you will get a warning
WARNING: Kubernetes configuration file is group-readable. This is insecure. Location: /home/administrator/.kube/config
WARNING: Kubernetes configuration file is world-readable. This is insecure. Location: /home/administrator/.kube/config
To fix it execute these commands
sudo chmod o-r ~/.kube/config sudo chmod g-r ~/.kube/config
That’s it for now. It was very easy to install and configure on Ubuntu Linux.