# Back up workloads with Velero

Back up the cluster's objects and the files of its volumes into one of your buckets every day with the velero add-on, and restore them into this or another cluster.

Replace _my-cluster_ with your cluster's name or id and _my-backups_ with one of your buckets.

Deutsche Cloud backs up the control plane itself (etcd, see [Back up a cluster](back-up-a-cluster.md)).
The `velero` add-on is for your workloads: it copies every namespace's objects and, with
file-system backup, the files in your pods' volumes into a bucket you choose, on a schedule.

- No key in the cluster. Velero gets temporary object-storage credentials from Deutsche Cloud for
  its service-account token. They belong to the IAM service account `eks-velero-<cluster id>`,
  which the add-on makes, whose one policy is your bucket under the prefix, and which goes when
  the add-on or the cluster goes.
- The schedule `ews-daily` runs at 03:00 UTC unless you set `schedule`, and keeps each backup
  `retentionDays` (30).
- File-system backup (on by default) copies volume files with Kopia, because Deutsche Cloud volumes
  have no snapshots. It runs a node agent on every node that is privileged and reads every pod
  volume on its node. Turn `fileSystemBackup` off to back up objects only.

## Prerequisites

- A bucket in your organization.
- Permission for `eks:CreateAddon` on the cluster and `s3:PutObject` in the bucket under the
  prefix (default `velero/<cluster id>`). In the console, also `eks:DescribeCluster` to open the
  cluster.
- The [velero CLI](https://velero.io/docs/main/basic-install/#install-the-cli) for restores, or
  `kubectl` to create a Restore object.

## Install the add-on

**Console**
1. Open **Kubernetes**, open the cluster, then choose **Add-ons**.
2. Choose **Add an add-on**, then **Backups (Velero)**.
3. Enter the bucket, and change the prefix, schedule or retention if you want.
4. Choose **Install**.

**CLI**
```sh
dcloud eks addons create my-cluster --name velero --config 'bucket="my-backups"' --config 'retentionDays=14'
```

**API**
```http
POST /eks/api/clusters/my-cluster/addons
{ "name": "velero", "config": { "bucket": "my-backups", "retentionDays": 14 } }
```

**Terraform**
```hcl
resource "dcloud_eks_addon" "velero" {
  cluster_id = dcloud_eks_cluster.main.id
  name       = "velero"
  config     = jsonencode({ bucket = "my-backups", retentionDays = 14 })
}
```

## Back up now and restore

```sh
velero backup create before-upgrade --wait
velero backup describe before-upgrade --details
velero restore create --from-backup before-upgrade --include-namespaces shop --wait
```

Velero restores what is missing and leaves what exists; delete a namespace first to restore it
as it was.

**Into another cluster:** install the add-on there with the same bucket and the first cluster's
prefix (`velero/<first cluster id>`); its backups appear in `velero backup get` within a minute.
Use another prefix for the new cluster's own backups afterwards, so the two do not mix.

## Remove

Removing the add-on deletes Velero, its namespace (with the Backup and Restore objects in it), its
schedule and its IAM service account. The backups themselves stay in the bucket: install the
add-on again with the same bucket and prefix and they are listed again within about a minute. To
delete backups for good, use `velero backup delete` before removing the add-on, or delete the
objects under the prefix in the bucket.
