Skip to content

Latest commit

 

History

History

local-backup

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Local Backup with Velero and Minio

This example creates a configuration that allows you to back up Kubernetes objects to your laptop (or wherever you are running idpbuilder from). It assumes that idpBuilder is on the path and that you have cloned this repository.

In short, it:

  1. Creates a MinIO installation that mounts a local directory.
  2. Creates a Velero installation that targets the in-cluster MinIO storage.

Installation

First, we need to ensure the local cluster is configured to mount a local directory. This is done through the kind configuration file that you can supply to idpbuilder.

Take a look at the kind.yaml file. The most relevant part is this bit:

nodes:
  - role: control-plane
    extraMounts:
      - hostPath: /home/ubuntu/backup # replace with your own path
        containerPath: /backup

This instructs Kind to make your machine's directory at /home/ubuntu/backup available at /backup for the Kubernetes node.

You must change this value for your own setup. This directory also must exist on your machine. For example, you may want to change it to /Users/my-name/backup.

Once you've made the change, run this command from the root of this repository.

# example: mkdir /Users/my-name/backup
mkdir <path/to/directory> 

idpbuilder create --kind-config local-backup/kind.yaml --package local-backup/

This command:

  1. Creates a standard idpbuilder installation, a kind cluster and core packages (ArgoCD, Gitea, and Ingress-Nginx).
  2. Creates two custom packages: MinIO and Velero.

Once the command exits, you can check the status of installation by going to https://argocd.cnoe.localtest.me:8443/applications.

You can also check the status with the following command:

kubectl get application -n argocd

Using it

Once MinIO and Velero ArgoCD applications are ready, you can start playing with it.

MinIO console is accessible at https://minio.cnoe.localtest.me:8443/login

You can log in to the console by obtaining credentials:

kubectl -n minio get secret root-creds -o go-template='{{ range $key, $value := .data }}{{ printf "%s: %s\n" $key ($value | base64decode) }}{{ end }}'
# example output
# rootPassword: aKKZzLnyry6OYZts17vMTf32H5ghFL4WYgu6bHujm
# rootUser: ge8019yksArb7BICt3MLY9

Once you log in, you will notice a bucket is already created for you. Velero will use this bucket to back up kubernetes objects.

image

Backup

Let's try creating a backup of an example application.

First, create an example nginx app straight from the Velero repository.

kubectl apply -f https://raw.githubusercontent.com/vmware-tanzu/velero/main/examples/nginx-app/base.yaml

Once they are created and running, create a backup.

kubectl apply -f local-backup/demo/backup.yaml

This command is equivalent to this Velero command: velero backup create nginx-backup --selector app=nginx

After you run the command, go back to the MinIO console. You will notice that file objects are created in your bucket.

img.png

You can also see these files on your local machine.

$ ls -lh /home/ubuntu/backup/idpbuilder-backups/backups/nginx-backup/
total 44K
drwxr-xr-x 2 ubuntu ubuntu 4.0K Jan 18 01:25 nginx-backup-csi-volumesnapshotclasses.json.gz
drwxr-xr-x 2 ubuntu ubuntu 4.0K Jan 18 01:25 nginx-backup-csi-volumesnapshotcontents.json.gz
drwxr-xr-x 2 ubuntu ubuntu 4.0K Jan 18 01:25 nginx-backup-csi-volumesnapshots.json.gz
drwxr-xr-x 2 ubuntu ubuntu 4.0K Jan 18 01:25 nginx-backup-itemoperations.json.gz
drwxr-xr-x 2 ubuntu ubuntu 4.0K Jan 18 01:25 nginx-backup-logs.gz
drwxr-xr-x 2 ubuntu ubuntu 4.0K Jan 18 01:25 nginx-backup-podvolumebackups.json.gz
drwxr-xr-x 2 ubuntu ubuntu 4.0K Jan 18 01:25 nginx-backup-resource-list.json.gz
drwxr-xr-x 2 ubuntu ubuntu 4.0K Jan 18 01:25 nginx-backup-results.gz
drwxr-xr-x 2 ubuntu ubuntu 4.0K Jan 18 01:25 nginx-backup-volumesnapshots.json.gz
drwxr-xr-x 2 ubuntu ubuntu 4.0K Jan 18 01:25 nginx-backup.tar.gz
drwxr-xr-x 2 ubuntu ubuntu 4.0K Jan 18 01:25 velero-backup.json

Restore

Let's simulate a cluster loss by deleting the kind cluster forcibly.

kind delete clusters localdev && docker system prune -f

Once it is destroyed, create it again.

idpbuilder create --kind-config local-backup/kind.yaml --package local-backup/

Make sure everything looks good:

$ kubectl get application -n argocd
NAME     SYNC STATUS   HEALTH STATUS
argocd   Synced        Healthy
gitea    Synced        Healthy
minio    Synced        Healthy
nginx    Synced        Healthy
velero   Synced        Healthy

Let's make sure Velero can validate the MinIO bucket:

$ kubectl get  backupstoragelocations.velero.io  -n velero
NAME      PHASE       LAST VALIDATED   AGE   DEFAULT
default   Available   4s               52m   true

Looks good. Let's make sure the backup from the destroyed cluster is available.

$ kubectl get backup -n velero
NAME           AGE
nginx-backup   1m

Target this backup to restore objects.

kubectl apply -f local-backup/demo/restore.yaml

This command is equivalent to velero restore create --from-backup nginx-backup.

Verify everything was restored:

$ kubectl get backup -n velero  -o custom-columns="NAME":.metadata.name,"PHASE":.status.phase
NAME           PHASE
nginx-backup   Completed

$ kubectl get pods -n nginx-example