┌──[root@vms100.liruilongs.github.io]-[~/ansible/velero/velero-v1.10.1-rc.1-linux-amd64] └─$catexamples/minio/00-minio-deployment.yaml # Copyright 2017 the Velero contributors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License.
--- apiVersion:v1 kind:Service metadata: namespace:velero name:minio labels: component:minio spec: # ClusterIP is recommended for production environments. # Change to NodePort if needed per documentation, # but only if you run Minio in a test/trial environment, for example with Minikube. type:NodePort ports: -port:9000 name:api targetPort:9000 protocol:TCP -port:9099 name:console targetPort:9090 protocol:TCP selector: component:minio
┌──[root@vms100.liruilongs.github.io]-[~/ansible/velero/velero-v1.10.1-rc.1-linux-amd64] └─$kubectl apply -f velero_deploy.yaml CustomResourceDefinition/backuprepositories.velero.io: attempting to create resource CustomResourceDefinition/backuprepositories.velero.io: attempting to create resource client .......... BackupStorageLocation/default: attempting to create resource BackupStorageLocation/default: attempting to create resource client BackupStorageLocation/default: created Deployment/velero: attempting to create resource Deployment/velero: attempting to create resource client Deployment/velero: created Velero is installed! ⛵ Use 'kubectl logs deployment/velero -n velero' to view the status. ┌──[root@vms100.liruilongs.github.io]-[~/ansible/velero/velero-v1.10.1-rc.1-linux-amd64] └─$
部署完成的 job 会自动新建 备用文件上传用的桶
备份
全量备份,部分备份
普通备份
1 2 3 4 5 6 7 8 9 10
┌──[root@vms100.liruilongs.github.io]-[~/ansible/velero/velero-v1.10.1-rc.1-linux-amd64] └─$velero backup create velero-demo Backup request "velero-demo" submitted successfully. Run `velero backup describe velero-demo` or `velero backup logs velero-demo` for more details. ┌──[root@vms100.liruilongs.github.io]-[~/ansible/velero/velero-v1.10.1-rc.1-linux-amd64] └─$velero get backup velero-demo NAME STATUS ERRORS WARNINGS CREATED EXPIRES STORAGE LOCATION SELECTOR velero-demo InProgress 0 0 2023-01-28 22:18:45 +0800 CST 29d default <none> ┌──[root@vms100.liruilongs.github.io]-[~/ansible/velero/velero-v1.10.1-rc.1-linux-amd64] └─$
查看备份信息
1 2 3 4
┌──[root@vms100.liruilongs.github.io]-[~/ansible/velero/velero-v1.10.1-rc.1-linux-amd64] └─$velero get backup velero-demo NAME STATUS ERRORS WARNINGS CREATED EXPIRES STORAGE LOCATION SELECTOR velero-demo Completed 0 0 2023-01-28 22:18:45 +0800 CST 29d default <none>
定时备份
定时备份,每天午夜备份一次。
1 2 3 4 5 6 7
┌──[root@vms100.liruilongs.github.io]-[~/ansible/velero/velero-v1.10.1-rc.1-linux-amd64] └─$velero schedule create k8s-backup --schedule="@daily" Schedule "k8s-backup" created successfully. ┌──[root@vms100.liruilongs.github.io]-[~/ansible/velero/velero-v1.10.1-rc.1-linux-amd64] └─$velero get schedule NAME STATUS CREATED SCHEDULE BACKUP TTL LAST BACKUP SELECTOR PAUSED k8s-backup Enabled 2023-01-29 00:11:03 +0800 CST @daily 0s n/a <none> false
恢复
1 2 3 4 5 6 7 8 9 10 11 12 13 14
┌──[root@vms100.liruilongs.github.io]-[~/ansible/velero/velero-v1.10.1-rc.1-linux-amd64] └─$velero restore create --from-backup velero-demo Restore request "velero-demo-20230129001615" submitted successfully. Run `velero restore describe velero-demo-20230129001615` or `velero restore logs velero-demo-20230129001615` for more details. ┌──[root@vms100.liruilongs.github.io]-[~/ansible/velero/velero-v1.10.1-rc.1-linux-amd64] └─$velero get restore NAME BACKUP STATUS STARTED COMPLETED ERRORS WARNINGS CREATED SELECTOR velero-demo-20230129001615 velero-demo InProgress 2023-01-29 00:16:15 +0800 CST <nil> 0 0 2023-01-29 00:16:15 +0800 CST <none> ┌──[root@vms100.liruilongs.github.io]-[~/ansible/velero/velero-v1.10.1-rc.1-linux-amd64] └─$velero get restore NAME BACKUP STATUS STARTED COMPLETED ERRORS WARNINGS CREATED SELECTOR velero-demo-20230129001615 velero-demo Completed 2023-01-29 00:16:15 +0800 CST 2023-01-29 00:17:20 +0800 CST 0 135 2023-01-29 00:16:15 +0800 CST <none> ┌──[root@vms100.liruilongs.github.io]-[~/ansible/velero/velero-v1.10.1-rc.1-linux-amd64] └─$
容灾测试
删除一个命名空间测试
当前命令空间资源
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
┌──[root@vms100.liruilongs.github.io]-[~/back] └─$kubectl-ketall -n cadvisor W0129 00:34:28.299699 126128 warnings.go:70] kubevirt.io/v1 VirtualMachineInstancePresets is now deprecated and will be removed in v2. W0129 00:34:28.354853 126128 warnings.go:70] metallb.io v1beta1 AddressPool is deprecated, consider using IPAddressPool NAME NAMESPACE AGE configmap/kube-root-ca.crt cadvisor 2d4h pod/cadvisor-5v7hl cadvisor 2d4h pod/cadvisor-7dnmk cadvisor 2d4h pod/cadvisor-7l4zf cadvisor 2d4h pod/cadvisor-dj6dm cadvisor 2d4h pod/cadvisor-sjpq8 cadvisor 2d4h serviceaccount/cadvisor cadvisor 2d4h serviceaccount/default cadvisor 2d4h controllerrevision.apps/cadvisor-6cc5c5c9cc cadvisor 2d4h daemonset.apps/cadvisor cadvisor 2d4h
删除命名空间
1 2 3 4 5 6 7
┌──[root@vms100.liruilongs.github.io]-[~/back] └─$kubectl delete ns cadvisor namespace "cadvisor" deleted ^C┌──[root@vms100.liruilongs.github.io]-[~/back] └─$kubectl delete ns cadvisor --force Warning: Immediate deletion does not waitfor confirmation that the running resource has been terminated. The resource may continue to run on the cluster indefinitely. Error from server (NotFound): namespaces "cadvisor" not found
查看命名空间资源
1 2 3 4 5
┌──[root@vms100.liruilongs.github.io]-[~/back] └─$kubectl-ketall -n cadvisor W0129 00:35:25.548656 127598 warnings.go:70] kubevirt.io/v1 VirtualMachineInstancePresets is now deprecated and will be removed in v2. W0129 00:35:25.581030 127598 warnings.go:70] metallb.io v1beta1 AddressPool is deprecated, consider using IPAddressPool No resources found.
使用上面的备份恢复刚才删除的命名空间
1 2 3 4 5 6 7 8 9 10 11 12 13 14
┌──[root@vms100.liruilongs.github.io]-[~/back] └─$velero restore create --from-backup velero-demo Restore request "velero-demo-20230129003541" submitted successfully. Run `velero restore describe velero-demo-20230129003541` or `velero restore logs velero-demo-20230129003541` for more details. ┌──[root@vms100.liruilongs.github.io]-[~/back] └─$velero get restore NAME BACKUP STATUS STARTED COMPLETED ERRORS WARNINGS CREATED SELECTOR velero-demo-20230129001615 velero-demo Completed 2023-01-29 00:16:15 +0800 CST 2023-01-29 00:17:20 +0800 CST 0 135 2023-01-29 00:16:15 +0800 CST <none> velero-demo-20230129003541 velero-demo InProgress 2023-01-29 00:35:41 +0800 CST <nil> 0 0 2023-01-29 00:35:41 +0800 CST <none> ┌──[root@vms100.liruilongs.github.io]-[~/back] └─$velero get restore NAME BACKUP STATUS STARTED COMPLETED ERRORS WARNINGS CREATED SELECTOR velero-demo-20230129001615 velero-demo Completed 2023-01-29 00:16:15 +0800 CST 2023-01-29 00:17:20 +0800 CST 0 135 2023-01-29 00:16:15 +0800 CST <none> velero-demo-20230129003541 velero-demo Completed 2023-01-29 00:35:41 +0800 CST 2023-01-29 00:36:46 +0800 CST 0 135 2023-01-29 00:35:41 +0800 CST <none>
确定命名空间资源恢复
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
┌──[root@vms100.liruilongs.github.io]-[~/back] └─$kubectl-ketall -n cadvisor W0129 00:37:29.787766 130766 warnings.go:70] kubevirt.io/v1 VirtualMachineInstancePresets is now deprecated and will be removed in v2. W0129 00:37:29.819111 130766 warnings.go:70] metallb.io v1beta1 AddressPool is deprecated, consider using IPAddressPool NAME NAMESPACE AGE configmap/kube-root-ca.crt cadvisor 94s pod/cadvisor-5v7hl cadvisor 87s pod/cadvisor-7dnmk cadvisor 87s pod/cadvisor-7l4zf cadvisor 87s pod/cadvisor-dj6dm cadvisor 87s pod/cadvisor-sjpq8 cadvisor 87s serviceaccount/cadvisor cadvisor 88s serviceaccount/default cadvisor 94s controllerrevision.apps/cadvisor-6cc5c5c9cc cadvisor 63s daemonset.apps/cadvisor cadvisor 63s ┌──[root@vms100.liruilongs.github.io]-[~/back] └─$
1 2 3 4 5 6 7 8 9 10 11 12 13 14
┌──[root@vms100.liruilongs.github.io]-[~/back] └─$kubectl get all -n cadvisor Warning: kubevirt.io/v1 VirtualMachineInstancePresets is now deprecated and will be removed in v2. NAME READY STATUS RESTARTS AGE pod/cadvisor-5v7hl 1/1 Running 0 2m50s pod/cadvisor-7dnmk 1/1 Running 0 2m50s pod/cadvisor-7l4zf 1/1 Running 0 2m50s pod/cadvisor-dj6dm 1/1 Running 0 2m50s pod/cadvisor-sjpq8 1/1 Running 0 2m50s
NAME DESIRED CURRENT READY UP-TO-DATE AVAILABLE NODE SELECTOR AGE daemonset.apps/cadvisor 5 5 5 5 5 <none> 2m26s ┌──[root@vms100.liruilongs.github.io]-[~/back] └─$
恢复失败情况分析
这里需要说明一点过,如果当前有命令空间发生了删除,但是你中断了它,类似下面这样,kubevirt 通过命令行发生的删除操作,但是它的删除没有完成。或者你进行了一些其他的操作。重复的删除创建 API 资源,导致的某些问题希望恢复操作之前的集群状态
1 2 3 4 5 6 7 8 9 10 11 12 13
┌──[root@vms100.liruilongs.github.io]-[~/ansible/kubevirt] └─$kubectl get ns NAME STATUS AGE cadvisor Active 39h default Active 3d20h ingress-nginx Active 3d20h kube-node-lease Active 3d20h kube-public Active 3d20h kube-system Active 3d20h kubevirt Terminating 3d20h local-path-storage Active 3d20h metallb-system Active 3d20h velero Active 40h
这个时候,如果使用 velero 发生 备份还原操作。可以会卡在下面的两个状态 InProgress 或者 New
1 2 3 4
┌──[root@vms100.liruilongs.github.io]-[~/ansible/kubevirt] └─$velero get restore NAME BACKUP STATUS STARTED COMPLETED ERRORS WARNINGS CREATED SELECTOR velero-demo-20230130105328 velero-demo InProgress 2023-01-30 10:53:28 +0800 CST <nil> 0 0 2023-01-30 10:53:28 +0800 CST <none>
1 2 3 4
┌──[root@vms100.liruilongs.github.io]-[~/ansible/kubevirt] └─$velero get restores NAME BACKUP STATUS STARTED COMPLETED ERRORS WARNINGS CREATED SELECTOR velero-demo-20230130161258 velero-demo New <nil> <nil> 0 0 2023-01-30 16:12:58 +0800 CST <none>
如果长时间没有变化,需要把通过脚本把命名空间彻底删除,然后还原工作才可以正常进行
1 2 3 4 5 6 7 8 9 10
┌──[root@vms100.liruilongs.github.io]-[~/ansible/kubevirt] └─$velero get restores NAME BACKUP STATUS STARTED COMPLETED ERRORS WARNINGS CREATED SELECTOR ............. velero-demo-20230130161258 velero-demo Completed 2023-01-30 20:53:58 +0800 CST 2023-01-30 20:55:20 +0800 CST 0 164 2023-01-30 16:12:58 +0800 CST <none> ┌──[root@vms100.liruilongs.github.io]-[~/ansible/kubevirt] └─$date 2023年 01月 30日 星期一 21:02:49 CST ┌──[root@vms100.liruilongs.github.io]-[~/ansible/kubevirt] └─$