美文网首页
velero 备份kubernetes 到oss

velero 备份kubernetes 到oss

作者: jinbulee | 来源:发表于2020-10-29 18:09 被阅读0次

    1、安装velero客户端
    在k8s集群的master 节点或者配置了kubectl 和config 的主机
    用的是阿里云文档的安装命令

    curl -o /usr/bin/velero https://public-bucket-1.oss-cn-hangzhou.aliyuncs.com/velero && chmod +x /usr/bin/velero 
    

    2、阿里云oss设置
    2.1、新建一个bucket 比如叫:velero-back ,区域选杭州,权限公共读。

    2.2、新建一个ram用户,或者直接用主账户的ram的AccessKey ID 和 AccessKey Secret
    新的ram用户需要配置oss的权限策略
    权限策略如下:

    {
        "Version": "1",
        "Statement": [
            {
                "Action": [
                    "ecs:DescribeSnapshots",
                    "ecs:CreateSnapshot",
                    "ecs:DeleteSnapshot",
                    "ecs:DescribeDisks",
                    "ecs:CreateDisk",
                    "ecs:Addtags",
                    "oss:PutObject",
                    "oss:GetObject",
                    "oss:DeleteObject",
                    "oss:GetBucket",
                    "oss:ListObjects"
                ],
                "Resource": [
                    "*"
                ],
                "Effect": "Allow"
            }
        ]
    }
    

    2.3 新建一个文件命名为 credentials-velero
    然后将新建用户或者主账户的AccessKey ID 和 AccessKey Secret 填写进去

    ALIBABA_CLOUD_ACCESS_KEY_ID=你的账户的AccessKey ID
    ALIBABA_CLOUD_ACCESS_KEY_SECRET=你的账户的AccessKey Secret
    

    3、安装服务端
    直接在credentials-velero 文件目录下执行下面的命令即可

    velero install --provider alibabacloud \
    --image registry.cn-hangzhou.aliyuncs.com/haoshuwei24/velero:v1.2.0 \
    --bucket velero-back \
    --secret-file ./credentials-velero \
    --use-volume-snapshots=false \
    --backup-location-config region=cn-hangzhou \
    --use-restic \
    --plugins registry.cn-hangzhou.aliyuncs.com/acs/velero-plugin-alibabacloud:v1.2 \
    --wait
    

    简单解释一下命令吧

    --bucket velero-back  #这里些的是oss的bucket名称
    
    --secret-file ./credentials-velero # oss 的AccessKey ID 和 AccessKey Secret文件
    
    --backup-location-config region=cn-hangzhou  #oss所在区域,如果oss区域选的是上海区域则这里等号后面填写cn-shanghai
    

    出现如下信息表示安装完成:

    Deployment/velero: attempting to create resource
    Deployment/velero: created
    DaemonSet/restic: attempting to create resource
    DaemonSet/restic: created
    Waiting for Velero deployment to be ready.
    Waiting for Velero restic daemonset to be ready.
    Velero is installed! ⛵ Use 'kubectl logs deployment/velero -n velero' to view the status.
    

    然后执行kubectl get po -n velero 看一下Pod是否创建成功
    如果有问题查看日志解决

    image.png

    4、这样服务端和客户端都安装完成,然后测试备份与恢复功能

    创建一个测试的应用,我直接用的之前安装的kubernetes-dashboard 的应用。
    目前有的Pod


    image.png

    4.1 先创建备份

    [root@master examples]# velero backup create dashboard-backup --include-namespaces kubernetes-dashboard --wait
    Backup request "dashboard-backup" submitted successfully.
    Waiting for backup to complete. You may safely press ctrl-c to stop waiting - your backup will continue in the background.
    .
    Backup completed with status: Completed. You may check for more information using the commands `velero backup describe dashboard-backup` and `velero backup logs dashboard-backup`.
    
    

    4.2 删除
    [root@master examples]# kubectl delete namespaces kubernetes-dashboard namespace "kubernetes-dashboard" deleted

    image.png
    显示 dashboard 已删除

    4.3 恢复

    [root@master examples]# velero restore create --from-backup dashboard-backup --wait
    Restore request "dashboard-backup-20201029054448" 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 dashboard-backup-20201029054448` and `velero restore logs dashboard-backup-20201029054448`.
    
    image.png

    已恢复

    相关文章

      网友评论

          本文标题:velero 备份kubernetes 到oss

          本文链接:https://www.haomeiwen.com/subject/pfklvktx.html