docker-compose安装minio与velero
docker-compose安装minio
创建挂载目录
mkdir -p /data/minio/{config,data,logs}
编写docker-compose.yml文件
[root@master2 minio]# cat docker-compose.yml version: '3' services: minio: image: minio/minio hostname: "minio" ports: - 9000:9000 # api 端口 - 9001:9001 # 控制台端口 environment: MINIO_ACCESS_KEY: admin #管理后台用户名 MINIO_SECRET_KEY: admin123 #管理后台密码,最小8个字符 volumes: - /data/minio/data:/data #映射当前目录下的data目录至容器内/data目录 - /data/minio/config:/root/.minio/ #映射配置目录 command: server --console-address ':9001' /data #指定容器中的目录 /data privileged: true restart: always
启动
docker-compose up -d
访问web页面
地址: 服务器ip:9001/
登录控制台创建Buckets
velero安装及测试
与Etcd备份相比,直接备份Etcd是将集群的全部资源备份起来,而velero是可以对k8s集群内对象级别进行备份。除了对k8s集群进行整体备份外,velero还可以通过对Type、NameSpace、Lable等对象进行分类备份或者恢复。
关于velero
为了提供了用于备份和恢复kubernetes集群资源和持久卷的工具。可以通过云提供商或运行Velero。
a.备份你的集群并在丢失时恢复
b.将集群资源迁移到其他集群
c.将你的生产集群复制开发和测试集群。
Velero包括:服务器端和客户端两大组件
工作原理
1.Velero每个过程
velero每个过程,如按需备份、计划备份、恢复都是一个自定义资源,使用kubernetes自定义资源,定义CRD定义并存储在etcd中。Velero还包括自定义资源以执行备份、恢复和所有相关操作的控制器。
可以备份或恢复集群中的所有对象,可以按照类型、命令空间或标签过滤对象。
Velero非常适合灾难恢复用例,以及在集群上执行系统操作(如升级)之前对应用程序状态进行快照。
2.备份工作流程
- Velero客户端调用Kubernetes API 服务器来创建一个Backup对象。
- 该BackupController注意到新的Backup对象,并进行验证。
- 在BackupController调用对象存储服务---例如:AWS S3---上传备份文件
- 默认情况下,velero backup create 为任何持久卷制作磁盘快照。可以通过指定附加标志来调整快照。运行velero backup create --help以查看可用标志。可以使用选项禁用快照---snapshot-volumes=false。
安装velero
# 安装velero客户端 $ wget https://github.com/vmware-tanzu/velero/releases/download/v1.9.0-rc.2/velero-v1.9.0-rc.2-linux-amd64.tar.gz $ tar -zxvf velero-v1.9.0-rc.2-linux-amd64.tar.gz $ cp velero /usr/local/bin && chmod +x /usr/local/bin/velero # 创建minio凭证(用户名密码与上面一样) $ vim credentials-velero [default] aws_access_key_id = admin aws_secret_access_key = admin123 # 安装velero服务端 $ velero install \ --provider aws \ --plugins velero/velero-plugin-for-aws:v1.5.0-rc.1 \ --bucket test-velero \ #在控制台创建一个bucket,为test-velero --secret-file ./credentials-velero \ --use-volume-snapshots=false \ --backup-location-config region=minio,s3ForcePathStyle="true",s3Url=http://10.70.106:9000 执行结果: Deployment/velero: created DaemonSet/restic: attempting to create resource DaemonSet/restic: created Velero is installed! ⛵ Use 'kubectl logs deployment/velero -n velero' to view the status. # 查看 $ kubectl get pods -n velero
参数说明:
–secret-file:指定认证文件 ;
–use-volume-snapshots=false:禁用快照备份功能
–use-restic:启用静态备份;
–default-volumes-to-restic:备份所有 pod 卷而不必在 pod 上应用注释;
–kubeconfig /root/.kube/config :指定k8s集群配置文件;
s3Url=http:这里是刚才部署minio存储的api接口,可以通过mino容器查看。
到此velero部署完成,注意替换<IP>.
执行手动备份
velero backup create ingress-nginx-backup \
--include-namespaces ingress-nginx --default-volumes-to-restic
创建定时备份任务
velero create schedule ingress-nginx-schedule --schedule="@every 24h" --include-namespaces ingress-nginx --default-volumes-to-restic
查看定时备份
[root@master2 minio]# velero schedule get NAME STATUS CREATED SCHEDULE BACKUP TTL LAST BACKUP SELECTOR ingress-nginx-schedule Enabled 2023-05-25 14:51:16 +0800 CST @every 24h 0s n/a <none>
恢复测试
删除ingress-nginx
[root@master1 ingress]# kubectl get pod,svc -n ingress-nginx NAME READY STATUS RESTARTS AGE pod/nginx-ingress-controller-6wj8r 1/1 Running 0 2m19s pod/nginx-ingress-controller-8wl2z 1/1 Running 0 88s pod/nginx-ingress-controller-b9hjf 0/1 Terminating 0 114s NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE service/ingress-nginx NodePort 10.97.117.175 <none> 80:32172/TCP,443:32692/TCP 72d [root@master1 ingress]# [root@master1 ingress]# [root@master1 ingress]# [root@master1 ingress]# [root@master1 ingress]# kubectl delete -f ingress-controlleryy.yaml namespace "ingress-nginx" deleted configmap "nginx-configuration" deleted configmap "tcp-services" deleted configmap "udp-services" deleted
恢复nignx-ingress
[root@master2 k8s]# velero restore create --from-backup ingress-nginx-backup --wait Restore request "ingress-nginx-backup-20230525164729" submitted successfully. Waiting for restore to complete. You may safely press ctrl-c to stop waiting - your restore will continue in the background. Restore completed with status: Completed. You may check for more information using the commands `velero restore describe ingress-nginx-backup-20230525164729` and `velero restore logs ingress-nginx-backup-20230525164729`. [root@master2 k8s]# echo $? 0 [root@master1 ingress]# kubectl get pod,svc -n ingress-nginx NAME READY STATUS RESTARTS AGE pod/nginx-ingress-controller-6jjxl 1/1 Running 0 4m37s pod/nginx-ingress-controller-qs84q 1/1 Running 0 4m37s pod/nginx-ingress-controller-rgwg4 1/1 Running 0 4m37s NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE service/ingress-nginx NodePort 10.99.118.150 <none> 80:32590/TCP,443:32614/TCP 4m37s
恢复会新建一个 restores。
查看备份:
velero get backup #备份查看
velero get schedule #查看定时备份
velero get restore #查看已有的恢复
velero get plugins #查看插件
velero命令
velero create backup NAME [flags] # 剔除 namespace --exclude-namespaces stringArray namespaces to exclude from the backup # 剔除资源类型 --exclude-resources stringArray resources to exclude from the backup, formatted as resource.group, such as storageclasses.storage.k8s.io # 包含集群资源类型 --include-cluster-resources optionalBool[=true] include cluster-scoped resources in the backup # 包含 namespace --include-namespaces stringArray namespaces to include in the backup (use '*' for all namespaces) (default *) # 包含 namespace 资源类型 --include-resources stringArray resources to include in the backup, formatted as resource.group, such as storageclasses.storage.k8s.io (use '*' for all resources) # 给这个备份加上标签 --labels mapStringString labels to apply to the backup -o, --output string Output display format. For create commands, display the object but do not send it to the server. Valid formats are 'table', 'json', and 'yaml'. 'table' is not valid for the install command. # 对指定标签的资源进行备份 -l, --selector labelSelector only back up resources matching this label selector (default <none>) # 对 PV 创建快照 --snapshot-volumes optionalBool[=true] take snapshots of PersistentVolumes as part of the backup # 指定备份的位置 --storage-location string location in which to store the backup # 备份数据多久删掉 --ttl duration how long before the backup can be garbage collected (default 720h0m0s) # 指定快照的位置,也就是哪一个公有云驱动 --volume-snapshot-locations strings list of locations (at most one per provider) where volume snapshots should be stored
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!