From 83c8bff8f50331a0c817857aeb390f4e47af19ab Mon Sep 17 00:00:00 2001 From: Xieql Date: Fri, 27 Oct 2023 10:23:47 +0800 Subject: [PATCH] fix Signed-off-by: Xieql --- .../en/docs/fleet-manager/backup/backup.md | 89 +++++++++--------- examples/backup/app-backup-demo.yaml | 21 +++++ examples/backup/backup-schedule.yaml | 10 +- ...ific-ns.yaml => backup-select-labels.yaml} | 7 +- examples/backup/busybox-demo/busybox.yaml | 91 +++++++++++++++++++ examples/backup/busybox.yaml | 45 --------- 6 files changed, 161 insertions(+), 102 deletions(-) create mode 100644 examples/backup/app-backup-demo.yaml rename examples/backup/{backup-specific-ns.yaml => backup-select-labels.yaml} (68%) create mode 100644 examples/backup/busybox-demo/busybox.yaml delete mode 100644 examples/backup/busybox.yaml diff --git a/docs/content/en/docs/fleet-manager/backup/backup.md b/docs/content/en/docs/fleet-manager/backup/backup.md index 488596357..0f676f807 100644 --- a/docs/content/en/docs/fleet-manager/backup/backup.md +++ b/docs/content/en/docs/fleet-manager/backup/backup.md @@ -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 @@ -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 @@ -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: @@ -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: {} @@ -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**: @@ -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. diff --git a/examples/backup/app-backup-demo.yaml b/examples/backup/app-backup-demo.yaml new file mode 100644 index 000000000..3d136f4a5 --- /dev/null +++ b/examples/backup/app-backup-demo.yaml @@ -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 diff --git a/examples/backup/backup-schedule.yaml b/examples/backup/backup-schedule.yaml index b19d42058..9d963f8e4 100644 --- a/examples/backup/backup-schedule.yaml +++ b/examples/backup/backup-schedule.yaml @@ -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 diff --git a/examples/backup/backup-specific-ns.yaml b/examples/backup/backup-select-labels.yaml similarity index 68% rename from examples/backup/backup-specific-ns.yaml rename to examples/backup/backup-select-labels.yaml index fb0ee093c..8a908e001 100644 --- a/examples/backup/backup-specific-ns.yaml +++ b/examples/backup/backup-select-labels.yaml @@ -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 diff --git a/examples/backup/busybox-demo/busybox.yaml b/examples/backup/busybox-demo/busybox.yaml new file mode 100644 index 000000000..1af29dcb8 --- /dev/null +++ b/examples/backup/busybox-demo/busybox.yaml @@ -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 diff --git a/examples/backup/busybox.yaml b/examples/backup/busybox.yaml deleted file mode 100644 index 917f8c338..000000000 --- a/examples/backup/busybox.yaml +++ /dev/null @@ -1,45 +0,0 @@ -apiVersion: v1 -kind: Namespace -metadata: - name: kurator-backup ---- -apiVersion: v1 -kind: Pod -metadata: - name: busybox - namespace: kurator-backup -spec: - containers: - - name: test-container - image: busybox - command: ["/bin/sh", "-c", "echo Hello Kurator! && sleep 3600"] ---- -apiVersion: v1 -kind: PersistentVolumeClaim -metadata: - name: test-pvc - namespace: kurator-backup -spec: - accessModes: - - ReadWriteOnce - resources: - requests: - storage: 1Gi ---- -apiVersion: v1 -kind: Pod -metadata: - name: busybox-with-pv - namespace: kurator-backup -spec: - containers: - - name: test-container - image: busybox - command: ["/bin/sh", "-c", "echo Hello Kurator!! > /test-pvc/hello.txt && sleep 3600"] - volumeMounts: - - name: test-volume - mountPath: /test-pvc - volumes: - - name: test-volume - persistentVolumeClaim: - claimName: test-pvc