RyanMillerC / k3s-backup

Back up k3s host mount (local-path-provisioner) Persistent Volumes (PVs) by temporarily draining applications Pods, backing up the PV's host directory to an NFS mount, and restoring the application Pod count.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

hostPath PV Backup

Back up Kubernetes hostPath (local-path-provisioner) Persistent Volumes (PVs) by temporarily draining applications Pods, backing up the PV's host directory to an NFS mount, and restoring the application Pod count.

The playbook backup-apps.yml calls the backup_app role for every application specified in vars.yml. backup_app calls the backup_pvc role for every PVC mounted to the given app's deployment. Each application Deployment will have it's Pods temporarily reduced to 0 replicas. This is important so that databases and other stateful workloads can cleanly write to disk before the backup is taken. After the backup is complete, the Deployment will be reset to X number of replica Pods.

I'm running this against a k3s cluster in my homelab with local-path-provisioner installed.

Limitations

  • Only works with hostPath PVs!
  • The playbook scales down each deployment one-by-one, meaning temporarily application downtime.

Usage

Prereqs

Install kubernetes Python package on k3s host:

$ sudo /usr/libexec/platform-python -m pip install kubernetes

Running

Initialize the back up:

$ make

You can run this in second terminal window to watch the Pods cycle:

$ kubectl get pods -A -w

About

Back up k3s host mount (local-path-provisioner) Persistent Volumes (PVs) by temporarily draining applications Pods, backing up the PV's host directory to an NFS mount, and restoring the application Pod count.


Languages

Language:Makefile 100.0%