Deploy a Single Node Kubernetes Instance in Seconds with MicroK8s

There may be times when you want to unleash a single node instance of Kubernetes. Say, for example, you are developing an app or a service and you need to test it. Before it is launched into production, why not deploy it on a Kubernetes testbed? Or maybe you’re looking to improve your Kubernetes development chops. Instead of a full-blown Kubernetes cluster, the single node is one of the best instances for both development and testing.
But how do you get that single node up and running? There are a number of ways to make this happen. You can go the Minikube route, or launch a full-blown single node of a standard Kubernetes installation. Or, you can make use of Microk8s.
Managed by Canonical, Microk8s is a non-elastic, rails-based single-node Kubernetes tool that is focused primarily on offline development, prototyping, and testing. Microk8s includes the following features:
- Istio
- GPGPU bindings
- Daily builds
- Local storage
- Local registry
- Updates
- Dashboard
- Metrics
- Upgrades
- IngressDNS
- Conformant
Microk8s has been created as a snap package, so in order to install and use, you must have a Linux distribution that supports this particular universal packaging format. I’m going to demonstrate how to get Microk8s up and running on the Ubuntu Desktop 19.04 distribution.
Installation
The installation of Microk8s is quite simple. Before you do, however, make sure you’re distribution is updated. Once you’ve completed that process, open a terminal window and issue the command (Figure A):

Figure A: Installing Microk8s from the command line.
sudo snap install microk8s --edge --classic
Once the command completes, you’ll need to start Microk8s. This is done with the command:
sudo microk8s.start
The command should report that the service has started and pod scheduling has been enabled.
Install Additional Services
In order for Microk8s to be of any use, you need to install a few additional services. Let’s install to basic services: kube-dns and the Microk8s Dashboard. The Dashboard is a web-based Dashboard that allows you to interact and manage Kubernetes. Kube-dns schedules a DNS Pod and Service on the cluster and configures the kubeletes to instruct individual containers to use the DNS Service IP address as a DNS resolver.
To install these two services, go back to your terminal window and issue the command:
sudo microk8s.enable dns dashboard
You can also enable other services, such as:
- storage — allows you to make use of storage on the host.
- ingress — create an Ingress controller.
- gpu — enable the nvidia-docker runtime and nvidia-device-plugin-daemonset.
- istio — enable the core Istio services.
- registry — deploy a private Docker registry.
If you decide you need additional services, after you have Microk8s up and running, you can always go back and issue the microk8s.enable command (with the service you want to add) any time.
Once you’ve installed the Dashboard, you need to then find out the address in which it can be accessed. For that, issue the command:
sudo microk8s.kubectl get all --all-namespaces
The above command will print out a number of namespaces, with their associated addresses.
Figure B

Figure B: Locating the address of our Microk8s Dashboard.
Look for the IP address associated with service/kubernetes-dashboard.
Accessing the Dashboard
You can now open a web browser (on the same machine that runs Microk8s) and point it to the https://IP_ADDRESS (Where IP_ADDRESS is the kubernetes-dashboard IP address).
At this point, you will see that the dashboard requires a Token for gaining access. How do you find that token? First, you must have Microk8s list out all of the available secrets with the command:
sudo microk8s.kubectl -n kube-system get secret
This will generate a list of all the service names, with their secret name attached. As you can see (Figure C), the Kubernetes Dashboard is included in the list.

Figure C: A list of services with secrets.
To retrieve the secret token for the service in question issue the command:
sudo microk8s.kubectl -n kube-system describe secret kubernetes-dashboard-token-fv247
Make sure to modify the fv247 entry to match the secret key associated with the Kubernetes Dashboard instance for your installation.
The above command will display a long string of characters. Copy that string and then go back to the web browser. In the Dashboard token window (Figure D), select Token and then paste the copied token into the Enter token text field.

Figure D: The Kubernetes Dashboard token entry window.
Click SIGN IN and you will find yourself on the Kubernetes Dashboard (Figure E).

Figure E: Created with GIMP
At this point, you can manage Kubernetes from the web-based dashboard. Create jobs, pods, replica sets, cron jobs and so much more. Click the Create button in the upper right corner, and you can either write directly or paste the contents of a YAML or JSON file. For example, say you want to create an NGINX deployment. Copy the below contents into the editor (Figure F), and click UPLOAD.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
apiVersion: v1 kind: ReplicationController metadata: name: nginx spec: replicas: 2 selector: app: nginx template: metadata: name: nginx labels: app: nginx spec: containers: - name: nginx image: nginx ports: - containerPort: 80 |

Figure F: Uploading a YAML file for NGINX deployment.
Once that YAML file has been uploaded, click on Workloads > Pods and you should see it listed as running (Figure G).

Figure G: The NGINX deployment is up and running.
And that’s all there is to getting a single node instance of Kubernetes up and running (as well as deploying a simple Pod) with Microk8s. This tool should help to get you developing your own Kubernetes applications and services in no time.