MicroK8s is a lightweight, fast, and secure Kubernetes distribution designed for developers and IoT/edge devices. It’s a really good option for testing Kubernetes deployments, developing apps, and deploying microservices on a single machine using a real Kubernetes cluster. We’ll go through how to install MicroK8s on Ubuntu 20.04 so you can get started with using it.
System Requirements and Prerequisites
- A machine running Ubuntu 20.04 LTS
- kubectl
- 2 CPUs or more
- 2GB of free memory
- 20GB of free disk space
- A user account with sudo privileges
- The
snapd
package installed on the system. If its not installed, run the following command to install it:
sudo apt update
sudo apt install snapd
Installing MicroK8s on Ubuntu 20.04
Installing MicroK8s is a simple process, thanks to the Snap package manager. Follow the steps below to install MicroK8s on Ubuntu 20.04:
- Open a terminal window by pressing
Ctrl+Alt+T
. - Install MicroK8s using the following command:
sudo snap install microk8s --classic
- Once the installation is complete, add your user account to the
microk8s
group using the following command:
sudo usermod -aG microk8s <username>
Replace <username>
with your actual username.
At this point, MicroK8s is now installed on your Ubuntu 20.04 system.
Updating MicroK8s on Ubuntu 20.04
To update MicroK8s to the latest version, simply run the following command:
sudo snap refresh microk8s --classic
This will update MicroK8s to the latest stable release. If you want to update to a specific version, you can use the --channel
option:
sudo snap refresh microk8s --classic --channel=<channel>
Replace <channel>
with the name of the channel you want to update to (e.g. 1.21/stable
).
Once the update is complete, you can check the version of MicroK8s by running:
microk8s --version
If the update is successful, you should see the new version number displayed.
Using MicroK8s on Ubuntu 20.04
Once MicroK8s is installed, you can use the microk8s
command to manage your Kubernetes cluster.
- To start the MicroK8s cluster, run:
microk8s start
- To check the status of the cluster, run:
microk8s status
- To stop the MicroK8s cluster, run:
microk8s stop
- To enable a MicroK8s add-on, run:
microk8s enable <addon-name>
Replace <addon-name>
with the name of the add-on you want to enable. For example, to enable the dashboard
add-on, run:
microk8s enable dashboard
- To disable a MicroK8s add-on, run:
microk8s disable <addon-name>
Replace <addon-name>
with the name of the add-on you want to disable.
Microk8s provides several useful add-ons that can be easily enabled with a single command. Here are a few examples:
- Istio: Istio is an open-source service mesh that helps manage and secure microservices. To enable Istio in Microk8s, run the following command:
microk8s enable istio
- Kubeflow: Kubeflow is a toolkit that helps you train, serve, and manage machine learning models on Kubernetes. To enable Kubeflow in Microk8s, run the following command:
microk8s enable kubeflow
- MetalLB: MetalLB is a load-balancer implementation for bare metal Kubernetes clusters. To enable MetalLB in Microk8s, run the following command:
microk8s enable metallb
These are just a few examples of the many add-ons available in Microk8s. You can see a full list of addons by running the command:
microk8s enable --help
Enabling these add-ons can greatly enhance the capabilities of your Microk8s cluster and make it even more powerful for your use case.
In addition to these commands, you can also use the standard kubectl
command-line tool to interact with your MicroK8s cluster. To use kubectl
with MicroK8s, run the following command:
microk8s kubectl <kubectl-command>
Replace <kubectl-command>
with the kubectl
command you want to run.
Removing and Uninstalling Microk8s on Ubuntu 20.04
To completely remove MicroK8s from your system, use the following command:
sudo snap remove microk8s --purge
This command will remove the MicroK8s snap and all of its associated data, including all installed add-ons, containers, and configuration files.
If you want to keep your data, but remove the MicroK8s snap and its associated binaries, use the following command instead:
sudo snap remove microk8s
This command will remove the MicroK8s snap, but keep all of the associated data on your system. You can then re-install MicroK8s at a later time and all of your previous data will still be available.
If you want to remove the MicroK8s data manually, you can do so using the following commands:
sudo microk8s reset
sudo snap remove microk8s
The first command will reset MicroK8s to its default state, removing all add-ons, containers, and configuration files. The second command will remove the MicroK8s snap from your system.
Note that resetting MicroK8s will delete all data stored in the cluster, so use this command with caution.
With these commands, you can fully remove MicroK8s and its associated data from your system.
Conclusion
MicroK8s is a lightweight, fast, and secure Kubernetes distribution that is perfect for developers and IoT/edge devices. With the simple installation process and easy-to-use commands, you can quickly set up and manage a Kubernetes cluster on your Ubuntu 20.04 system.