Uninstalling K3S without first removing components like the gateway, Longhorn, and MetalLB can leave behind configuration files, resources, and data that may conflict with future installations. By following the correct uninstallation steps, you can avoid these conflicts and ensure a smooth reinstallation process.

This guide provides a step-by-step process to safely uninstall the K3S cluster and its associated components, ensuring a clean environment for future installations.

  1. Before uninstalling K3S, you need to deregister the gateway. Run the following command, replacing with the appropriate namespace:
    opsramp-collector-start uninstall -n <namespace>
  2. Uninstall Longhorn Helm Chart:
    • Longhorn has a safety flag to prevent accidental uninstallation. Before you can uninstall Longhorn, you need to set this flag to true:
      kubectl -n longhorn-system patch -p '{"value": "true"}' --type=merge lhs deleting-confirmation-flag
    • Once the flag is set, uninstall the Longhorn Helm chart with the following command:
      helm uninstall longhorn -n longhorn-system
  3. Uninstall the MetalLB Helm chart using the following commands:
    helm uninstall metallb -n kube-system
     
    helm uninstall ipaddresspool -n kube-system
  4. After clearing all the associated data, uninstall the K3S service. Run the following command on all available nodes to uninstall K3S:
    k3s-uninstall.sh
  5. Once K3S is uninstalled, everything will be cleared from your system, allowing you to reinstall K3S and its components from scratch without encountering previous conflicts.