TL;DR
To remove Rancher completely from a cluster where it was installed (irreversible, backup taken):
| |
To fix a single thing without razing everything, read on.
Namespace stuck in Terminating
cattle-system, cattle-fleet-system, cattle-impersonation-system, local, the cluster-fleet-* ones, or any namespace Rancher created, stay in Terminating forever:
| |
Two different cases:
metadata.finalizerscontainscontroller.cattle.io/namespace-auth(or any*.cattle.io). Rancher put it there and only Rancher removes it; if Rancher is gone, nobody will. Remove it yourself:1kubectl patch ns cattle-system --type=merge -p '{"metadata":{"finalizers":[]}}'spec.finalizerscontainskubernetesandstatus.conditionssaysSomeResourcesRemainorDiscoveryFailed. The API server will not delete the namespace because resources remain inside, almost always CRs of an API group whose service disappeared (a Rancherapiservice). Before forcing, look at what it is:1 2 3kubectl api-resources --verbs=list --namespaced -o name \ | xargs -n1 kubectl -n cattle-system get --ignore-not-found --show-kind 2>/dev/null kubectl get apiservice | grep -v True # dead APIs that break discoveryDelete the dead
apiserviceor the CRs with finalizers, and the namespace goes away on its own. Forcingspec.finalizersto empty is the last resort and leaves orphans behind:1 2kubectl get ns cattle-system -o json | jq '.spec.finalizers=[]' \ | kubectl replace --raw /api/v1/namespaces/cattle-system/finalize -f -
Cluster that cannot be deleted
An imported cluster that no longer exists stays in Removing in the UI, or kubectl delete never finishes. There are two objects with finalizers, one per API:
| |
Then clean up the cluster-fleet-default-<name>-<hash> namespace and whatever clusters.fleet.cattle.io remain in fleet-default.
The webhook that rejects everything
rancher-webhook validates and mutates *.cattle.io resources (and some core ones, such as namespaces and ServiceAccounts on managed clusters). If the pod is gone or broken, every change fails with:
| |
Export the configurations, delete them, let the pod come back healthy, and restore them:
| |
If you are uninstalling, do not restore them: they are the first thing to remove so the rest of the deletion can proceed.
Getting access back
Lost admin password, or the admin user disabled by mistake:
| |
ensure-default-admin re-enables the user and gives the administrator role back; reset-password only changes the password.
Traps
rancher-cleanupdeletes the downstream cluster objects (the clusters keep running, but are no longer registered) and everything Rancher installed: monitoring, logging, Gatekeeper. Longhorn stays. Do not run it on the Rancher cluster you want to keep.- Backup first:
kubectl get -A -o yamlof the*.cattle.ioresources you care about, or Rancher’s backup-operator. Finalizers go away in a second; what was behind them does not come back. kubectl delete ns --force --grace-period=0does nothing for a namespace in Terminating: the block is in the finalizers, not in the grace period.- Rancher puts the finalizers back while it is alive: if you are cleaning a cluster still connected to a Rancher, disconnect it first (delete the
cattle-cluster-agent) or your patches undo themselves. - The
*.cattle.ioCRDs survive a Helm uninstall;rancher-cleanupremoves them, a manual uninstall does not.
See also
- k3s: cluster reset after losing quorum — the other cluster surgery worth keeping at hand.
- rancher-cleanup and the Rancher technical FAQ.