Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
Signed-off-by: Xieql <[email protected]>
  • Loading branch information
Xieql committed Oct 28, 2023
1 parent 238a06d commit 83c8bff
Show file tree
Hide file tree
Showing 6 changed files with 161 additions and 102 deletions.
89 changes: 43 additions & 46 deletions docs/content/en/docs/fleet-manager/backup/backup.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,75 +36,83 @@ Unified Backup supports two primary backup methods to cater to different require
## How to Perform a Unified Backup


In the following sections, we will present a hands-on demonstration.
Before proceeding with the content, ensure you have successfully installed the backup plugin as per the [backup plugin installation guide](/docs/fleet-manager/backup/backup-plugin).
In the subsequent sections, we'll guide you through a hands-on demonstration.
Before delving into the details, ensure you have successfully installed the backup plugin as outlined in the [backup plugin installation guide](/docs/fleet-manager/backup/backup-plugin).


For our demonstration, we'll utilize the fleet and two kind clusters which created in [backup plugin installation guide](/docs/fleet-manager/backup/backup-plugin).
For this demonstration, we will be using the `fleet` and two [kind](https://kind.sigs.k8s.io/) clusters, as created in the [backup plugin installation guide](/docs/fleet-manager/backup/backup-plugin).

Let's start by deploying a busybox example:
You can initiate the process by deploying a test application using the following command:

```console
kubectl apply -f examples/backup/busybox.yaml --kubeconfig=/root/.kube/kurator-member1.config
kubectl apply -f examples/backup/busybox.yaml --kubeconfig=/root/.kube/kurator-member2.config
kubectl apply -f examples/backup/app-backup-demo.yaml
```

Executing the above command will deploy the test busybox across two clusters within the `fleet`. For a comprehensive understanding about `app-backup-demo.yaml`, please refer to the [unified application distribution](/docs/fleet-manager/application).

Due to constraints associated with `restic`, performing a PV backup in a KIND cluster (the environment we're currently operating in) is a challenging [issue](https://github.com/vmware-tanzu/velero/issues/4962).
Hence, our subsequent examples will mainly feature `busybox`. However, in a real-world cluster setup, users can opt for the `busybox-with-pv` example.

### 1. Performing an Immediate Backup

Apply an immediate backup example:

```console
kubectl apply -f examples/backup/backup-specific-ns.yaml
kubectl apply -f examples/backup/backup-select-labels.yaml
```

Review the results:

```console
kubectl get backups.backup.kurator.dev specific-ns -o yaml
kubectl get backups.backup.kurator.dev select-labels -o yaml
```

The expected result should be:

```console
apiVersion: backup.kurator.dev/v1alpha1
kind: Backup
metadata:
annotations:
kubectl.kubernetes.io/last-applied-configuration: |
{"apiVersion":"backup.kurator.dev/v1alpha1","kind":"Backup","metadata":{"annotations":{},"name":"specific-ns","namespace":"default"},"spec":{"destination":{"fleet":"quickstart"},"policy":{"resourceFilter":{"includedNamespaces":["kurator-backup"]},"ttl":"720h"}}}
creationTimestamp: "2023-10-24T12:04:38Z"
{"apiVersion":"backup.kurator.dev/v1alpha1","kind":"Backup","metadata":{"annotations":{},"name":"select-labels","namespace":"default"},"spec":{"destination":{"fleet":"quickstart"},"policy":{"resourceFilter":{"labelSelector":{"matchLabels":{"app":"busybox"}}},"ttl":"720h"}}}
creationTimestamp: "2023-10-28T02:23:51Z"
finalizers:
- backup.kurator.dev
generation: 1
name: specific-ns
name: select-labels
namespace: default
resourceVersion: "8448571"
uid: 211a8aec-a8fa-4b73-a48c-ebe4ceb75e2f
resourceVersion: "9367135"
uid: ff2ab3c6-3af2-4a40-8e53-63f724f3f203
spec:
destination:
fleet: quickstart
policy:
resourceFilter:
includedNamespaces:
- kurator-backup
labelSelector:
matchLabels:
app: busybox
ttl: 720h
status:
backupDetails:
- backupNameInCluster: kurator-member1-backup-default-specific-ns
- backupNameInCluster: kurator-member1-backup-default-select-labels
backupStatusInCluster:
expiration: "2023-11-23T12:04:38Z"
completionTimestamp: "2023-10-27T11:28:09Z"
expiration: "2023-11-26T11:28:03Z"
formatVersion: 1.1.0
phase: InProgress
startTimestamp: "2023-10-24T12:04:38Z"
phase: Completed
progress:
itemsBackedUp: 4
totalItems: 4
startTimestamp: "2023-10-27T11:28:03Z"
version: 1
clusterKind: AttachedCluster
clusterName: kurator-member1
- backupNameInCluster: kurator-member2-backup-default-specific-ns
- backupNameInCluster: kurator-member2-backup-default-select-labels
backupStatusInCluster:
expiration: "2023-11-23T12:04:38Z"
expiration: "2023-11-27T02:23:51Z"
formatVersion: 1.1.0
phase: InProgress
startTimestamp: "2023-10-24T12:04:38Z"
startTimestamp: "2023-10-28T02:23:51Z"
version: 1
clusterKind: AttachedCluster
clusterName: kurator-member2
Expand All @@ -113,19 +121,13 @@ status:
Given the output provided, let's dive deeper to understand the various elements and their implications:

- In the spec, the `destination` field is used. By default, if no specific cluster is set, it points to all clusters within the `fleet`.
- The `policy` provides a unified strategy for the backup. The current setting of `resourceFilter` indicates the backup of all resources under the specified namespace `kurator-backup`. The policy used here only touches upon the namespace. For more advanced filtering options, refer to the [Fleet API](https://kurator.dev/docs/references/fleet-api/#fleet)
- The `policy` defines the backup strategy. Using the `resourceFilter`, it specifies that the backup should target resources with the label `app: busybox`. For more advanced filtering options, refer to the [Fleet API](https://kurator.dev/docs/references/fleet-api/#fleet)
- The `status` section displays the actual processing status of the two clusters within the fleet.

Furthermore, you can check your backup data in object storage; it will appear in the bucket used during the plugin configuration.

### 2. Performing a Scheduled Backup

Label the pod intended for backup to facilitate subsequent label-based selections:

```console
kubectl label po busybox env=test -n kurator-backup --kubeconfig=/root/.kube/kurator-member2.config
```

Apply the scheduled backup:

```console
Expand All @@ -135,7 +137,7 @@ kubectl apply -f examples/backup/backup-schedule.yaml
Review the results:

```console
kubectl get backups.backup.kurator.dev schedule-matchlabels -o yaml
kubectl get backups.backup.kurator.dev schedule -o yaml
```

The expected result should be:
Expand All @@ -146,28 +148,22 @@ kind: Backup
metadata:
annotations:
kubectl.kubernetes.io/last-applied-configuration: |
{"apiVersion":"backup.kurator.dev/v1alpha1","kind":"Backup","metadata":{"annotations":{},"name":"schedule-matchlabels","namespace":"default"},"spec":{"destination":{"clusters":[{"kind":"AttachedCluster","name":"kurator-member2"}],"fleet":"quickstart"},"policy":{"resourceFilter":{"labelSelector":{"matchLabels":{"env":"test"}}},"ttl":"240h"},"schedule":"0 0 * * *"}}
creationTimestamp: "2023-10-25T02:55:30Z"
{"apiVersion":"backup.kurator.dev/v1alpha1","kind":"Backup","metadata":{"annotations":{},"name":"schedule","namespace":"default"},"spec":{"destination":{"clusters":[{"kind":"AttachedCluster","name":"kurator-member2"}],"fleet":"quickstart"},"schedule":"*/5 * * * *"}}
creationTimestamp: "2023-10-28T02:38:39Z"
finalizers:
- backup.kurator.dev
generation: 1
name: schedule-matchlabels
name: schedule
namespace: default
resourceVersion: "8606170"
uid: 4ac4eb1c-e2cf-48a2-b197-87397d72222a
resourceVersion: "9369767"
uid: a7dd8dc1-2a56-424f-ad11-e55ec434043e
spec:
destination:
clusters:
- kind: AttachedCluster
name: kurator-member2
fleet: quickstart
policy:
resourceFilter:
labelSelector:
matchLabels:
env: test
ttl: 240h
schedule: 0 0 * * *
schedule: '*/5 * * * *'
status:
backupDetails:
- backupStatusInCluster: {}
Expand All @@ -178,14 +174,15 @@ status:
Analyzing the provided output, let's dissect its sections for a clearer comprehension:

- **Cron Expression in `spec`**:
- The `schedule` field within the `spec` uses a cron expression. This defines when a backup is to be performed.
- The `schedule` field within the `spec` uses a cron expression. This defines when a backup is to be performed.
- The expression '*/5 * * * *' means the backup will run every 5 minutes. This setting is for testing purposes only. Users should adjust this parameter based on their actual needs.
- Once set, the backup won't be executed immediately. Instead, it waits until the time specified by the cron expression.

- **Destination in `spec`**:
- The `destination` field under `spec` points to `kurator-member2`. This means the backup is specifically for this cluster within its fleet.

- **Policy in `spec`**:
- The `policy` section outlines the backup strategy. In this instance, it's set to backup resources that match certain labels.
- The `policy` section outlines the backup strategy. If no `policy` specified, all cluster resource will be backup.
- For more advanced filtering options, refer to the [Fleet API](https://kurator.dev/docs/references/fleet-api/#fleet)

- **Status Section**:
Expand All @@ -197,7 +194,7 @@ Analyzing the provided output, let's dissect its sections for a clearer comprehe
To remove the backup examples used for testing, execute:

```console
kubectl delete backups.backup.kurator.dev specific-ns schedule-matchlabels
kubectl delete backups.backup.kurator.dev select-labels schedule
```

> Please note: This command only deletes the current object in the k8s API.
Expand Down
21 changes: 21 additions & 0 deletions examples/backup/app-backup-demo.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
apiVersion: apps.kurator.dev/v1alpha1
kind: Application
metadata:
name: unified-backup-demo
namespace: default
spec:
source:
gitRepository:
interval: 3m0s
ref:
branch: main
timeout: 1m0s
url: https://github.com/kurator-dev/kurator
syncPolicies:
- destination:
fleet: quickstart
kustomization:
interval: 5m0s
path: ./examples/fleet/backup/busybox-demo
prune: true
timeout: 2m0s
10 changes: 2 additions & 8 deletions examples/backup/backup-schedule.yaml
Original file line number Diff line number Diff line change
@@ -1,18 +1,12 @@
apiVersion: backup.kurator.dev/v1alpha1
kind: Backup
metadata:
name: schedule-matchlabels
name: schedule
namespace: default
spec:
schedule: "*/5 * * * *" # Runs at every 5 minutes,just for test.
schedule: "*/5 * * * *" # Runs at every 5 minutes,for testing purposes only.
destination:
fleet: quickstart
clusters:
- kind: AttachedCluster
name: kurator-member2
policy:
resourceFilter:
labelSelector:
matchLabels:
env: test
ttl: 240h # 10 * 24 hours
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
apiVersion: backup.kurator.dev/v1alpha1
kind: Backup
metadata:
name: specific-ns
name: select-labels
namespace: default
spec:
destination:
fleet: quickstart
policy:
resourceFilter:
includedNamespaces:
- kurator-backup
labelSelector:
matchLabels:
app: busybox
ttl: 720h # 30 * 24 hours
91 changes: 91 additions & 0 deletions examples/backup/busybox-demo/busybox.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
apiVersion: v1
kind: Namespace
metadata:
name: kurator-backup
---
apiVersion: v1
kind: Pod
metadata:
name: busybox
namespace: kurator-backup
labels:
app: busybox
spec:
automountServiceAccountToken: false
hostIPC: true
containers:
- name: busybox
image: busybox:1.35
args:
- sleep
- 1d
---
apiVersion: v1
kind: Pod
metadata:
name: busybox-with-pv
namespace: kurator-backup
labels:
app: busybox-with-pv
spec:
automountServiceAccountToken: false
hostIPC: true
volumes:
- name: kurator-backup-storage
persistentVolumeClaim:
claimName: kurator-backup-claim
containers:
- name: busybox
image: busybox:1.35
args:
- sleep
- 1d
volumeMounts:
- mountPath: "/kurator-test"
name: kurator-backup-storage
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: kurator-backup-claim
namespace: kurator-backup
labels:
app: busybox-with-pv
spec:
storageClassName: kurator-backup-local
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 1Gi
---
apiVersion: v1
kind: PersistentVolume
metadata:
name: kurator-backup-volume
labels:
app: busybox-with-pv
spec:
accessModes:
- ReadWriteOnce
capacity:
storage: 1Gi
storageClassName: kurator-backup-local
persistentVolumeReclaimPolicy: Delete
local:
path: "/tmp"
nodeAffinity:
required:
nodeSelectorTerms:
- matchExpressions:
- key: kubernetes.io/hostname
operator: Exists
---
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
name: kurator-backup-local
labels:
app: busybox-with-pv
provisioner: kubernetes.io/no-provisioner
volumeBindingMode: WaitForFirstConsumer
45 changes: 0 additions & 45 deletions examples/backup/busybox.yaml

This file was deleted.

0 comments on commit 83c8bff

Please sign in to comment.