So you want to start developing for Kubernetes, but you don’t want to have to exert the effort to deploy a full-blown Kubernetes cluster to do so. That’s a pretty common problem. And with Kubernetes retiring the support for Docker, you might find a lot of documentation on deploying a Kubernetes cluster to no longer function. On top of that, you might only have a single machine to work with (so deploying an entire cluster can be a challenge).
What do you do? When you only have a single desktop machine, and you need to get this up fast, you can always turn to Microk8s, which is a Cloud Native Computing Foundation-certified upstream Kubernetes platform that you can run from a workstation. Microk8s is easy to get up and running, so you won’t have to waste precious time deploying multiple servers.
Understand, however, Microk8s isn’t what you’d run your apps and services on for public consumption. This should be considered a development environment first and foremost.
With that said, what we’re going to do is deploy both Microk8s and the Kubernetes Dashboard, so you can enjoy a GUI tool to help you work more efficiently.
I’ll be demonstrating on Ubuntu Desktop 20.04, so you’ll want to have at least that version of Ubuntu Desktop up and running. And because the Kubernetes Dashboard is only accessible from within the cluster (at least not without some serious tweaking), your instance of Ubuntu must have a desktop GUI (so don’t try this on a headless server).
Outstanding. Let’s get to work.
The first thing we’re going to do is install Microk8s. Log into your desktop, open a terminal window, and issue the command:
sudo snap install micro8ks --classic
After the installation completes, you must then add your user to the Microk8s group and change the ownership of a newly-created directory. First, add yourself to the group with the command:
sudo usermod -a -G microk8s $USER
Next, you need to make the system aware that you’ve been added to the new group with the command (to avoid having to reboot your machine):
Finally, change the ownership of the .kube folder with:
sudo chown -f -R $USER ~/.kube
Deploying the Kubernetes Dashboard
We can now install the Kubernetes Dashboard (along with a few other addons) with the command:
microk8s enable dns dashboard storage
After this command runs, you need to discover the IP address assigned to the Dashboard. This is done with the command:
microk8s kubectl get all --all-namespaces
You should see quite a bit of output, which will include a listing for the Dashboard that looks like:
kube-system service/kubernetes-dashboard ClusterIP 10.152.183.56 <none> 443/TCP 21m
This tells us the IP address of the Dashboard and the port. The values assigned to your Dashboard will differ.
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://IP:443 (where IP is the IP address assigned to the Dashboard), you’ll need to accept the risk (because the Dashboard uses a self-signed certificate). If the connection times out, wait a few more minutes for the service to become available.
Eventually, you’ll be greeted with the Dashboard login window (Figure 1).
Before you can log into the Dashboard, you must first generate an authentication token. Go back to the terminal window and issue the command:
token=$(microk8s kubectl -n kube-system get secret | grep default-token | cut -d " " -f1) microk8s kubectl -n kube-system describe secret $token
You will be presented with a long string of characters. Copy that string and then paste it into the text area of the Dashboard log in the window (making sure to select Token). Click Sign in and, upon successful authentication, you’ll find yourself on the main Kubernetes Dashboard window (Figure 2).
Deploy a Container
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 in Figure 3).
You should immediately be directed to a page that lists your new deployment (Figure 4).
Click the name of the entry (in this case, tns) to view the details of the deployment (Figure 5).
Go back to the terminal window and issue the command:
microk8s kubectl get all --all-namespaces
You should see an IP address associated with the tns container. Copy and paste that IP address (along with port 8080) into your browser and the NGINX welcome page should appear.
Congratulations, you’ve just deployed Microk8s and the Kubernetes Dashboard to serve as an efficient and simple Kubernetes development platform.
The New Stack is a wholly owned subsidiary of Insight Partners, an investor in the following companies mentioned in this article: Docker.
The Cloud Native Computing Foundation is a sponsor of The New Stack.
Image by skylarvision from Pixabay.