This guide provides a comprehensive, step-by-step process to cleanly uninstall the K3s cluster and its associated components (Gateway, Longhorn, MetalLB) from a multi-node environment, ensuring a conflict-free reinstallation later.
This document applies to gateways deployed using OpsRamp provided ISO/OVA.
Why Proper Uninstallation Matters?
Uninstalling K3s without first removing associated components like NextGen Gateway, Longhorn, and MetalLB can leave behind residual resources, configurations, or persistent volumes. These leftovers may cause issues during future installations or upgrades.
Prerequisites
- Ensure you have access to all nodes in the K3s cluster.
- This procedure is valid only for OpsRamp ISO/OVA-based deployments.
- Run all commands with appropriate privileges (sudo or as root, where required).
Uninstallation Steps
Step 1: Deregister the Gateway
Before uninstalling K3s, remove the registered NextGen Gateway to avoid orphaned configurations in OpsRamp.
opsramp-collector-start uninstall -n <namespace>Replace
Step 2: Uninstall Longhorn
Longhorn includes a built-in safety flag that prevents accidental removal. Disable this flag first:
kubectl -n longhorn-system patch lhs deleting-confirmation-flag -p '{"value": "true"}' --type=merge Now, uninstall the Longhorn Helm chart:
helm uninstall longhorn -n longhorn-systemStep 3: Uninstall MetalLB
To remove MetalLB and its IP address pool configuration:
helm uninstall metallb -n kube-system
helm uninstall ipaddresspool -n kube-system Step 4: Uninstall K3s on All Nodes
To completely remove K3s, run the following command on every node in the cluster:
k3s-uninstall.shThis command will remove:- K3s services
- Kubernetes configurations
- Containerd and related directories
Final State
After completing all the steps above:
- Your environment will be free of Kubernetes and related components.
- You can safely reinstall K3s, register a new NextGen Gateway, or deploy other components without encountering leftover artifacts or configuration conflicts.
Summary of Commands
| Step | Commands |
|---|---|
| Deregister Gateway | opsramp-collector-start uninstall -n |
| Disable Longhorn Protection | kubectl patch ... deleting-confirmation-flag |
| Uninstall Longhorn | helm uninstall longhorn -n longhorn-system |
| Uninstall MetalLB | helm uninstall metallb ... |
| Remove K3s | k3s-uninstall.sh on all nodes |