How to Uninstall MicroK8s on Ubuntu 20.04

How to Uninstall MicroK8s on Ubuntu 20.04

MicroK8s is a lightweight, single-node Kubernetes distribution that simplifies the installation and management of Kubernetes clusters on Ubuntu. However, there may be instances where you need to uninstall MicroK8s from your Ubuntu 20.04 system. In this post, we will walk you through a step-by-step guide on how to remove MicroK8s to ensure a clean uninstallation.

Please note that the following steps assume you have administrative privileges on your Ubuntu 20.04 system.

Step 1: Stop and Disable MicroK8s Services

The first step is to stop and disable the MicroK8s services running on your Ubuntu system. Open a terminal and execute the following command:1

sudo microk8s stop
sudo microk8s disable

Step 2: Remove MicroK8s

Snap MicroK8s is installed as a snap package on Ubuntu. To remove the MicroK8s snap package, use the following command:23

sudo snap remove microk8s

Step 3: Remove MicroK8s Data and Configurations

MicroK8s stores its data and configurations in different directories. To ensure a clean uninstallation, remove these directories by executing the following commands:4

sudo rm -rf /var/snap/microk8s/
sudo rm -rf /var/snap/microk8s-common/

Step 4: Verify Removal

To verify that MicroK8s has been successfully removed from your Ubuntu system, you can check for any remaining processes. Run the following command to list the active processes:

ps aux | grep microk8s

If you see any MicroK8s-related processes in the output, terminate them using the kill command and their corresponding process IDs (PIDs).

Step 5: Clean Up Kubernetes-Related Configuration

MicroK8s may have modified some configuration files related to Kubernetes. To clean up any remaining configuration files, execute the following command:

sudo rm -rf /etc/kubernetes/

Step 6: Remove MicroK8s Aliases (Optional)

MicroK8s creates some useful aliases for Kubernetes commands. If you no longer need these aliases, remove them by editing the .bashrc file with a text editor such as nano:

nano ~/.bashrc

Locate the lines starting with alias kubectl, alias k, alias helm, and alias skaffold, and delete or comment out these lines by adding a # at the beginning of each line. Save the file and exit the text editor.

Step 7: Restart Your System (Recommended)

Although not strictly necessary, it is recommended to restart your Ubuntu 20.04 system to ensure a clean state after uninstalling MicroK8s. You can restart your system using the following command:

sudo reboot

Conclusion

By following this step-by-step guide, you can remove MicroK8s from your Ubuntu 20.04 system completely. This ensures that all the MicroK8s components, data, and configurations are removed, allowing you to start with a clean slate or install a different Kubernetes distribution if needed. Remember to exercise caution when removing system components and double-check the commands before executing them. Happy Kubernetes journey!

References

  1. MicroK8s – Command reference  | MicroK8s. (n.d.). microk8s.io. https://microk8s.io/docs/command-reference ↩︎
  2. Leem, D. (2023, July 9). Install & Uninstall MicroK8s (Ubuntu 22.04.2 LTS). The Perpetual Student. https://blog.duaneleem.com/uninstall-microk8s-ubuntu-22-04-2-lts/ ↩︎
  3. Adeola, S. (2023, November 13). How to uninstall MicroK8s – Samuel Adeola – Medium. Medium. https://medium.com/@demiladeolasam/how-to-uninstall-microk8s-c42f00893402 ↩︎
  4. MicroK8s – Configuring MicroK8s services  | MicroK8s. (n.d.). microk8s.io. https://microk8s.io/docs/configuring-services ↩︎
Published