Uninstall Longhorn

In this section, you’ll learn how to uninstall Longhorn.

Prerequisite

To prevent Longhorn from being accidentally uninstalled (which leads to data lost), we introduce a new setting, deleting-confirmation-flag. If this flag is false, the Longhorn uninstallation job will fail. Set this flag to true to allow Longhorn uninstallation. You can set this flag using setting page in Longhorn UI or kubectl -n longhorn-system patch -p '{"value": "true"}' --type=merge lhs deleting-confirmation-flag

To prevent damage to the Kubernetes cluster, we recommend deleting all Kubernetes workloads using Longhorn volumes (PersistentVolume, PersistentVolumeClaim, StorageClass, Deployment, StatefulSet, DaemonSet, etc).

Uninstalling Longhorn from the Rancher UI

From Rancher UI, navigate to Catalog Apps tab and delete Longhorn app.

Uninstalling Longhorn using Helm

Run this command:

  1. helm uninstall longhorn -n longhorn-system

Uninstalling Longhorn using Helm Controller

Run this command:

  1. kubectl delete helmchart <HelmChart name> -n <HelmChart namespace>

Uninstalling Longhorn Using Fleet

Run the following command:

  1. kubectl delete GitRepo longhorn -n fleet-local

After the longhorn-uninstall job is completed, run the following command:

  1. kubectl delete -f https://raw.githubusercontent.com/longhorn/longhorn/v1.7.2/deploy/longhorn.yaml

Uninstalling Longhorn Using Flux

Run the following command:

  1. flux delete helmrelease longhorn-release -n longhorn-system

Uninstalling Longhorn Using Argo CD

Argo CD currently does not support the PreDelete resource hook. Instead of running argocd app delete longhorn directly, you must uninstall Longhorn using kubectl to prevent dangling resources from remaining in the longhorn-system namespace.

Uninstalling Longhorn using kubectl

  1. Create the uninstallation job to clean up CRDs from the system and wait for success:

    1. kubectl create -f https://raw.githubusercontent.com/longhorn/longhorn/v1.7.2/uninstall/uninstall.yaml
    2. kubectl get job/longhorn-uninstall -n longhorn-system -w

    Example output:

    1. $ kubectl create -f https://raw.githubusercontent.com/longhorn/longhorn/v1.7.2/uninstall/uninstall.yaml
    2. serviceaccount/longhorn-uninstall-service-account created
    3. clusterrole.rbac.authorization.k8s.io/longhorn-uninstall-role created
    4. clusterrolebinding.rbac.authorization.k8s.io/longhorn-uninstall-bind created
    5. job.batch/longhorn-uninstall created
    6. $ kubectl get job/longhorn-uninstall -n longhorn-system -w
    7. NAME COMPLETIONS DURATION AGE
    8. longhorn-uninstall 0/1 3s 3s
    9. longhorn-uninstall 1/1 20s 20s
  2. Remove remaining components:

    1. kubectl delete -f https://raw.githubusercontent.com/longhorn/longhorn/v1.7.2/deploy/longhorn.yaml
    2. kubectl delete -f https://raw.githubusercontent.com/longhorn/longhorn/v1.7.2/uninstall/uninstall.yaml

Tip: If you try kubectl delete -f https://raw.githubusercontent.com/longhorn/longhorn/v1.7.2/deploy/longhorn.yaml first and get stuck there, pressing Ctrl C then running kubectl create -f https://raw.githubusercontent.com/longhorn/longhorn/v1.7.2/uninstall/uninstall.yaml can also help you remove Longhorn. Finally, don’t forget to cleanup remaining components.

Troubleshooting

Uninstalling using Rancher UI or Helm failed, I am not sure why

You might want to check the logs of the longhorn-uninstall-xxx pod inside longhorn-system namespace to see why it failed. One reason can be that deleting-confirmation-flag is false. You can set it to true by using setting page in Longhorn UI or kubectl -n longhorn-system patch -p '{"value": "true"}' --type=merge lhs deleting-confirmation-flag then retry the Helm/Rancher uninstallation.

If the uninstallation was an accident (you don’t actually want to uninstall Longhorn), you can cancel the uninstallation as the following.

  1. If you use Rancher UI to deploy Longhorn

    1. Open a kubectl shell on Rancher UI
    2. Find the latest revision of Longhorn release

      1. > helm list -n longhorn-system -a
      2. NAME NAMESPACE REVISION UPDATED STATUS CHART APP VERSION
      3. longhorn longhorn-system 2 2022-10-14 01:22:36.929130451 +0000 UTC uninstalling longhorn-100.2.3+up1.3.2-rc1 v1.3.2-rc1
      4. longhorn-crd longhorn-system 3 2022-10-13 22:19:05.976625081 +0000 UTC deployed longhorn-crd-100.2.3+up1.3.2-rc1 v1.3.2-rc1
    3. Rollback to the latest revision

      1. > helm rollback longhorn 2 -n longhorn-system
      2. checking 22 resources for changes
      3. ...
      4. Rollback was a success! Happy Helming!
  2. If you use Helm deploy Longhorn

    1. Open a kubectl terminal
    2. Find the latest revision of Longhorn release

      1. helm list --namespace longhorn-system -a
      2. NAME NAMESPACE REVISION UPDATED STATUS CHART APP VERSION
      3. longhorn longhorn-system 1 2022-10-14 13:45:25.341292504 -0700 PDT uninstalling longhorn-1.4.0-dev v1.4.0-dev
    3. Rollback to the latest revision

      1. helm rollback longhorn 1 -n longhorn-system
      2. Rollback was a success! Happy Helming!

I deleted the Longhorn App from Rancher UI instead of following the uninstallation procedure

Redeploy the (same version) Longhorn App. Follow the uninstallation procedure above.

Problems with CRDs

If your CRD instances or the CRDs themselves can’t be deleted for whatever reason, run the commands below to clean up. Caution: this will wipe all Longhorn state!

  1. # Delete CRD finalizers, instances and definitions
  2. for crd in $(kubectl get crd -o jsonpath={.items[*].metadata.name} | tr ' ' '\n' | grep longhorn.io); do
  3. kubectl -n ${NAMESPACE} get $crd -o yaml | sed "s/\- longhorn.io//g" | kubectl apply -f -
  4. kubectl -n ${NAMESPACE} delete $crd --all
  5. kubectl delete crd/$crd
  6. done

If you encounter the following error, it is possible that an incomplete uninstallation removed the Longhorn validation or modification webhook services, but left the same services registered.

for: "STDIN": error when patching "STDIN": Internal error occurred: failed calling webhook "validator.longhorn.io": failed to call webhook: Post "https://longhorn-admission-webhook.longhorn-system.svc:9502/v1/webhook/validation?timeout=10s": service "longhorn-admission-webhook" not found

You can run the following commands to check the status of the webhook services.

  1. $ kubectl get ValidatingWebhookConfiguration -A
  2. NAME WEBHOOKS AGE
  3. longhorn-webhook-validator 1 46d
  4. rancher.cattle.io 7 133d
  5. rke2-ingress-nginx-admission 1 133d
  6. rke2-snapshot-validation-webhook 1 133d
  7. $ kubectl get MutatingWebhookConfiguration -A
  8. NAME WEBHOOKS AGE
  9. longhorn-webhook-mutator 1 46d
  10. rancher.cattle.io 4 133d

If either or both are still registered, you can delete the configuration to remove the services from the patch operation call path.

  1. $ kubectl delete ValidatingWebhookConfiguration longhorn-webhook-validator
  2. validatingwebhookconfiguration.admissionregistration.k8s.io "longhorn-webhook-validator" deleted
  3. $ kubectl delete MutatingWebhookConfiguration longhorn-webhook-mutator
  4. mutatingwebhookconfiguration.admissionregistration.k8s.io "longhorn-webhook-mutator" deleted

The script should run successfully after the configuration is deleted.

  1. Warning: Detected changes to resource pvc-279e8c3e-bfb0-4233-8899-77b5b178c08c which is currently being deleted.
  2. volumeattachment.longhorn.io/pvc-279e8c3e-bfb0-4233-8899-77b5b178c08c configured
  3. No resources found
  4. customresourcedefinition.apiextensions.k8s.io "volumeattachments.longhorn.io" deleted

Please see link for more information.