Giter VIP home page Giter VIP logo

kub-vol-bak's Introduction

kub-vol-bak: Simple Kubernetes Volume Backups with Restic

Opinionated, straightforward backups for different Kubernetes volumes types. No CRDs, no daemons.

Installation

Local

Due to its simplicity, kub-vol-bak can be run locally easily. Checkout this repository, install the Python dependencies and you can start the first backup:

# get source code
git clone https://github.com/jacksgt/kub-vol-bak.git
cd kub-vol-bak

# install Python dependencies
python3 -m venv venv
source venv/bin/activate
pip3 install -r requirements.txt

# provide k8s cluster connection details
export KUBECONFIG=...

# provide backup storage details
kubectl create namespace kub-vol-bak
kubectl -n kub-vol-bak create secret generic kub-vol-bak-credentials \
    --from-literal=RESTIC_PASSWORD=hunter.2 \
    --from-literal=RESTIC_REPOSITORY=b2:my-bucket

# take backups!
./kub-vol-bak.py backup --pvc-label-selector app=frontend --dry-run

Helm

A Helm chart is available for deploying the tool with a CronJob into a Kubernetes cluster.

TODO: publish as OCI image

Set up backup storage backend

TODO: https://restic.readthedocs.io/en/latest/030_preparing_a_new_repo.html

FAQ

How does it work?

The kub-vol-bak.py Python tool implements all the application logic:

  • discovers of PVCs in the Kubernetes cluster
  • determines backup strategy for each PVC (depending on the type of PVC, a different mount strategy needs to be used)
  • spawns pods to take backups of each PVC with restic
  • monitors the pod and reports on its status

How to disable/pause backups?

A particular volume can be excluded from being backed up by adding the backup-enabled: "false" annotation, like this:

kubectl annotate pvc/<NAME> backup-enabled=false

How do I restore data?

There are no automatic restore procedures. Copy the environment variables from the kub-vol-bak-credentials secret and export them in your local shell session. Then, restic CLI can be used to restore the data locally: https://restic.readthedocs.io/en/latest/050_restore.html

What does Exception: Unable to determine backup strategy for PVC namespace/name mean?

Most likely this means that this PVC is backed by a CSI driver and the volume is currently not mounted on any node. To resolve the issue, spin up a simple pod that uses the PVC, which will force the kubelet to mount the volume on one node.

TODO

  • implement cleanup job
  • publish Helm chart with OCI image
  • add more type annotations
  • improve logging (debug,info,warning,error)
  • setup pylint + mypy
  • automate building container image to GHCR
  • add license

kub-vol-bak's People

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.