How to Set Up Reliable Kubernetes Backup & Restore Using Longhorn

Rounded avatar

karakoo

Jul 5, 2025
Header image

How to Set Up Reliable Kubernetes Backup & Restore Using Longhorn

Why This Matters: Core Data Protection in Kubernetes

For any application running on Kubernetes, safeguarding data against loss and ensuring rapid recovery from disruptions are crucial. Businesses need to prevent data loss, maintain operational continuity, and meet compliance mandates while managing complexity and cost.

Longhorn is an open-source, cloud-native storage solution that integrates directly with Kubernetes and provides a practical way to implement robust backup and restore strategies.

For this demonstration, we use Wiki.js as the target application.

The workflow:

  • Deploy Wiki.js in Kubernetes
  • Create a sample page inside Wiki.js
  • Perform a backup of its persistent volume using Longhorn
  • Delete the page from the application
  • Restore the volume from the backup

Configuring the Backup Target

The first step is to configure a backup target, usually an S3-compatible object storage service.

Use this URI format:

s3://BUCKET_NAME@REGION/

You also need a Kubernetes Secret in the longhorn-system namespace with:

  • AWS_ACCESS_KEY_ID
  • AWS_ENDPOINTS
  • AWS_SECRET_ACCESS_KEY

Creating a Demo Document in Wiki.js

Create a simple demo document in Wiki.js. This simulates a real-world change to application data that we later back up and intentionally remove.

Performing a Persistent Volume Backup

With application data modified, take a backup of the Wiki.js persistent volume.

Within the Longhorn UI:

  • Navigate to the Volume tab.
  • Locate the persistent volume for Wiki.js and open it.
  • Click Create Backup.

The backup captures the volume state, including the newly created document.

Simulating a Disaster

Delete the document created earlier in Wiki.js. This confirms that the data is gone from the live application and sets up the restore test.

Preparing for Volume Restore

Before restoring the persistent volume, ensure that the existing volume is not in use. Delete the current Wiki.js database deployment and its PersistentVolumeClaim.

After deleting the deployment and PVC, the Longhorn volume should become detached. At that point, it is safe to remove the detached volume.

Restoring the Volume from Backup

Navigate to the Backup tab, find the previously created backup, and select Restore. You can provide a new volume name or use the previous name. Using the previous name is often the simplest option because it aligns with the existing PVC configuration.

Binding the Restored Volume to a PVC

Once the restore is complete, bind the restored PersistentVolume to a PersistentVolumeClaim.

  • Go to the Volume tab.
  • Select the restored volume.
  • Click Create PV/PVC.
  • Choose Use Previous PVC.

This creates a PVC with the correct name and binds it to the restored PV.

Verifying the Successful Restore

Redeploy the Wiki.js database deployment. It should automatically use the newly created PVC containing the restored data.

Return to Wiki.js and confirm that the deleted document is present again. This verifies a successful backup and restore operation using Longhorn.

Need Help Implementing a Robust Kubernetes Backup Strategy?

Protecting Kubernetes data with a reliable backup and restore solution is essential. If you want to implement a resilient and cost-effective disaster recovery strategy using Longhorn, Karakoo can help tailor the setup to your environment.

© 2025 Karakoo GmbH. All rights reserved. For any enquiry mail us at [email protected]