Git Backup Operator

A Kubernetes Operator for scheduled backup of Git repositories.
Overview
- You create a
Repository resource.
- The Operator creates a
CronJob resource from it.
- The
CronJob does the actual work.
apiVersion: gitbackup.ebiiim.com/v1beta1
kind: Repository
metadata:
name: repo1
spec:
src: https://github.com/ebiiim/gitbackup
dst: https://gitlab.com/ebiiim/gitbackup
schedule: "0 6 * * *"
gitCredentials:
name: repo1-secret # specify a Secret resource in the same namespace
Getting Started
Supported Kubernetes versions: 1.21 or higher
Installation
Make sure you have cert-manager deployed, as it is used to generate webhook certificates.
kubectl apply -f https://github.com/cert-manager/cert-manager/releases/download/v1.10.0/cert-manager.yaml
⚠️ You may have to wait a second for cert-manager to be ready.
Deploy the Operator with the following command. It creates gitbackup-system namespace and deploys CRDs, controllers and other resources.
kubectl apply -f https://github.com/ebiiim/gitbackup/releases/download/v0.1.0/gitbackup.yaml
Deploy a Repository resource
First, create a Secret resource that contains .git-credentials.
kubectl create secret generic repo1-secret --from-file=$HOME/.git-credentials
Next, create a Repository resource.
apiVersion: gitbackup.ebiiim.com/v1beta1
kind: Repository
metadata:
name: repo1
spec:
src: https://github.com/ebiiim/gitbackup
dst: https://gitlab.com/ebiiim/gitbackup
schedule: "0 6 * * *"
gitCredentials:
name: repo1-secret
Finally, confirm that resources has been created.
$ kubectl get repos
NAME AGE
repo1 5s
$ kubectl get cronjobs
NAME SCHEDULE SUSPEND ACTIVE LAST SCHEDULE AGE
gitbackup-repo1 0 6 * * * False 0 <none> 5s
NOTE: You can test the CronJob by manually triggering it.
kubectl create job --from=cronjob/<name> <job-name>
Uninstallation
Delete the Operator and resources with the following command.
kubectl delete -f https://github.com/ebiiim/gitbackup/releases/download/v0.1.0/gitbackup.yaml
Developing
This Operator uses Kubebuilder, so we basically follow the Kubebuilder way. See the Kubebuilder Documentation for details.
Prerequisites
Make sure you have the following tools installed:
Run development clusters with kind
./hack/dev-kind-reset-clusters.sh # create a K8s cluster `kind-gitbackup`
./hack/dev-kind-deploy.sh # build and deploy the Operator