We will need 1 VM to create a single node kubernetes cluster using
We are using following setting for this purpose:
- 1 Linux machine, ubuntu-21.04-x86_64 or your choice of Ubuntu OS image, m1.medium flavor with 2vCPU, 4GB RAM, 10GB storage - also assign Floating IP to this VM.
- setup Unique hostname to the machine using the following command:
echo "<node_internal_IP> <host_name>" >> /etc/hosts hostnamectl set-hostname <host_name>
echo "192.168.0.62 microk8s" >> /etc/hosts hostnamectl set-hostname microk8s
Install MicroK8s on Ubuntu
Run the below command on the Ubuntu VM:
- SSH into microk8s machine
Switch to root user:
Update the repositories and packages:
apt-get update && apt-get upgrade -y
- Install MicroK8s:
sudo snap install microk8s --classic
- Check the status while Kubernetes starts
microk8s status --wait-ready
- Turn on the services you want:
microk8s enable dns dashboard
microk8s enable --help for a list of available services and optional features.
microk8s disable <name> turns off a service. For example other useful services
microk8s enable registry istio storage
- Start using Kubernetes
microk8s kubectl get all --all-namespaces
If you mainly use MicroK8s you can make our kubectl the default one on your command-line
alias mkctl="microk8s kubectl". Since it is a standard upstream kubectl, you
can also drive other Kubernetes clusters with it by pointing to the respective kubeconfig
file via the
- Access the Kubernetes dashboard UI:
As we see above the kubernetes-dashboard service in the kube-system namespace has a ClusterIP of 10.152.183.73 and listens on TCP port 443. The ClusterIP is randomly assigned, so if you follow these steps on your host, make sure you check the IP adress you got.
Another way to access the default token to be used for the dashboard access can be retrieved with:
- Keep running the kubernetes-dashboad on Proxy to access it via web browser:
microk8s dashboard-proxy Checking if Dashboard is running. Dashboard will be available at https://127.0.0.1:10443 Use the following token to login: eyJhbGc....
This tells us the IP address of the Dashboard and the port. The values assigned to your Dashboard will differ. Please note the displayed PORT and also the TOKEN that are required to access the kubernetes-dashboard. Make sure, the exposed PORT is opened in Security Groups for the instance following this guide.
This will show the token to login to the Dashbord shown on the url with NodePort.
You’ll need to wait a few minutes before the dashboard becomes available. If you
open a web browser on the same desktop you deployed Microk8s and point it to
https://<Floating-IP>:<PORT> (where PORT is the PORT assigned to the Dashboard
noted while running the above command), you’ll need to accept the risk
(because the Dashboard uses a self-signed certificate). And, we can enter the previously
noted TOKEN to access the kubernetes-dashboard.
Once entered correct TOKEN the kubernetes-dashboard is accessed and looks like below:
- Start and stop Kubernetes:
Kubernetes is a collection of system services that talk to each other all the
time. If you don’t need them running in the background then you will save
battery by stopping them.
microk8s stopwill those tasks for you.
- To Reset the infrastructure to a clean state:
Deploy a Container using the Kubernetes-Dashboard
Click on the + button in the top left corner of the main window. On the resulting page, click Create from form and then fill out the necessary information as shown below:
You should immediately be directed to a page that lists your new deployment as shown below:
Go back to the terminal window and issue the command:
microk8s kubectl get svc tns -n kube-system NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE tns LoadBalancer 10.152.183.90 <pending> 8080:30012/TCP 14m
Go to browser, visit
i.e. http://188.8.131.52:30012/ to check the nginx default page.
Deploy A Sample Nginx Application
- Create an alias:
alias mkctl="microk8s kubectl"
- Create a deployment, in this case Nginx:
mkctl create deployment --image nginx my-nginx
- To access the deployment we will need to expose it:
mkctl expose deployment my-nginx --port=80 --type=NodePort
mkctl get svc my-nginx NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE my-nginx NodePort 10.152.183.41 <none> 80:31225/TCP 35h
Go to browser, visit
i.e. http://184.108.40.206:31225/ to check the nginx default page.
Deploy Another Application
You can start by creating a microbot deployment with two pods via the kubectl cli:
mkctl create deployment microbot --image=dontrebootme/microbot:v1 mkctl scale deployment microbot --replicas=2
To expose the deployment to NodePort, you need to create a service:
mkctl expose deployment microbot --type=NodePort --port=80 --name=microbot-service
- View the port information:
mkctl get svc microbot-service NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE microbot-service NodePort 10.152.183.8 <none> 80:31442/TCP 35h
Go to browser, visit
i.e. http://220.127.116.11:31442/ to check the microbot default page.