如何使用 Velero 备份和还原 DigitalOcean 上的 Kubernetes 集群

介绍

Velero是一个方便的备份工具,用于 Kubernetes 集群,它将 Kubernetes 对象压缩和备份到对象存储中。它还使用云提供商的区块存储 snapshot 功能拍摄集群的持久卷,然后可以将集群的对象和持久卷恢复到以前的状态。

DigitalOcean Velero Plugin允许您使用DigitalOcean区块存储来拍摄您的持久卷,和空间来备份您的Kubernetes对象。当在DigitalOcean上运行Kubernetes集群时,这允许您快速备份您的集群的状态,并在灾难中恢复它。

在本教程中,我们将在本地机器上设置和配置velero命令行工具,并将服务器组件部署到我们的Kubernetes集群中。

如果您正在寻找一个管理的Kubernetes托管服务,请查看我们的简单的,用于增长的管理的Kubernetes服务(https://www.digitalocean.com/products/kubernetes)。

前提条件

在您开始本教程之前,您应该有以下内容为您提供:

在您的本地计算机上:

您可以在 [官方 Kubernetes 文档] 中阅读有关安装和配置 kubectl 的更多信息(https://kubernetes.io/docs/tasks/tools/install-kubectl/)。 * 您可以阅读有关安装和配置 kubectl 的更多信息(https://kubernetes.io/docs/tools/tools/install-kubectl/). * 您可以学习如何安装 gitGetting Started with Git

在您的 DigitalOcean 帐户中:

  • Digital Ocean Kubernetes (https://www.digitalocean.com/products/kubernetes/) 上数字海洋滴水管上的Culbernetes集群(`1.7.5'或后版)。
  • DNS服务器运行在您的集群内。 如果您正在使用 DigitalOcean Kubernetes, 这是默认运行 。 为了更多地了解库贝伦特斯DNS服务的配置,请从库贝伦特斯官方文档中查阅Customizing DNS Service.
  • 数字海洋空间,将存储您的备份库伯内特天体。 为了学习如何创建空间,请查阅空间产品文件
  • 联合国 您的数字海洋空间访问密钥对 。 要学习如何创建一套访问密钥,请咨询如何管理行政访问空间.
  • 与数字海洋API一起使用的个人访问标志。 为学习如何创建个人访问符,请咨询[如何创建个人访问托肯 (https://www.digitalocean.com/docs/api/create-personal-access-token/). 确保您创建或使用的符牌具有 读/ 写 权限或快照无效 。 .

一旦你已经设置了所有这些,你已经准备好开始这个指南。

第1步:安装Velero客户端

Velero 备份工具由您本地计算机上安装的客户端和运行在您的 Kubernetes 集群中的服务器组成。

在您的网页浏览器中,导航到Velero GitHub repo releases page,找到与您的操作系统和系统架构相符的版本,并复制链接地址。为本指南的目的,我们将使用X86-64(或AMD64)处理器上的Ubuntu 18.04服务器作为我们的本地机器,以及Velero v1.2.0版本。

要遵循本指南,您应该下载并安装 Velero 客户端的 v1.2.0

然后,从本地计算机上的命令行,导航到临时的 /tmp 目录和 cd 到它:

1cd /tmp

使用wget和您先前复制的链接来下载发布 tarball:

1wget https://link_copied_from_release_page

一旦下载完成,请使用):

1tar -xvzf velero-v1.2.0-linux-amd64.tar.gz

/tmp目录现在应该包含提取的velero-v1.2.0-linux-amd64目录以及您刚刚下载的 tarball。

通过执行二进制来验证你可以运行velero客户端:

1./velero-v1.2.0-linux-amd64/velero help

您应该看到以下帮助输出:

 1[secondary_label Output]
 2Velero is a tool for managing disaster recovery, specifically for Kubernetes
 3cluster resources. It provides a simple, configurable, and operationally robust
 4way to back up your application state and associated data.
 5
 6If you're familiar with kubectl, Velero supports a similar model, allowing you to
 7execute commands such as 'velero get backup' and 'velero create schedule'. The same
 8operations can also be performed as 'velero backup get' and 'velero schedule create'.
 9
10Usage:
11  velero [command]
12
13Available Commands:
14  backup Work with backups
15  backup-location Work with backup storage locations
16  bug Report a Velero bug
17  client Velero client related commands
18  completion Output shell completion code for the specified shell (bash or zsh)
19  create Create velero resources
20  delete Delete velero resources
21  describe Describe velero resources
22  get Get velero resources
23  help Help about any command
24  install Install Velero
25  plugin Work with plugins
26  restic Work with restic
27  restore Work with restores
28  schedule Work with schedules
29  snapshot-location Work with snapshot locations
30  version Print the velero version and associated image
31. . .

在这一点上,你应该将velero执行程序从临时的/tmp目录中移除,并将其添加到你的PATH

1sudo mv velero-v1.2.0-linux-amd64/velero /usr/local/bin/velero

您现在已经准备好为Velero服务器配置秘密,然后将其部署到您的Kubernetes集群中。

步骤2 - 配置秘密

在设置Velero的服务器组件之前,您需要准备您的DigitalOcean Spaces密钥和API代码。 再次使用cd命令导航到临时目录 /tmp:

1cd /tmp

现在我们将下载一个副本的Velero插件的DigitalOcean. 访问 插件的Github发布页面 并复制链接到文件结束在 .tar.gz

使用wget和您先前复制的链接来下载发布 tarball:

1wget https://link_copied_from_release_page

一旦下载完成,请使用):

1tar -xvzf v1.0.0.tar.gz

/tmp目录现在应该包含提取的velero-plugin-1.0目录以及您刚刚下载的 tarball。

接下来我们将CD放入velero-plugin-1.0目录:

1cd velero-plugin-1.0.0

现在我们可以将我们的 DigitalOcean Space 和 API 代码存储为 Kubernetes Secret. 首先,使用您最喜欢的编辑器打开示例/云凭据文件。

1nano examples/cloud-credentials

文件将看起来像这样:

1[label /tmp/velero-plugin-1.0.0/examples/cloud-credentials]
2[default]
3aws_access_key_id=<AWS_ACCESS_KEY_ID>
4aws_secret_access_key=<AWS_SECRET_ACCESS_KEY>

编辑<AWS_ACCESS_KEY_ID><AWS_SECRET_ACCESS_KEY>的位置保持器以使用您的 DigitalOcean Spaces 密钥。

下一步是编辑 01-velero-secret.patch.yaml 文件,以便包含您的 DigitalOcean API 代币。

1nano examples/01-velero-secret.patch.yaml

它应该看起来像这样:

1---
2apiVersion: v1
3kind: Secret
4stringData:
5digitalocean_token: <DIGITALOCEAN_API_TOKEN>
6type: Opaque

改變整個「DIGITALOCEAN_API_TOKEN>」的位置,以便使用您的 DigitalOcean 個人 API 標記. 該行應該看起來像「digitalocean_token: 18a0d730c0e0......」。

第3步:安装Velero服务器

Velero 安装由多个 Kubernetes 对象组成,这些对象一起创建、安排和管理备份. 您刚刚下载的velero可执行可以为您生成和安装这些对象。

  • 创建)规则以授予):)以管理区块快照和空间存储。

我们将使用一些非默认配置选项运行velero install命令,具体来说,您需要在实际调用命令中编辑下列每个设置以匹配您的 Spaces 配置:

  • -bucket起伏 " : 更改 velero- 备份 值以匹配您的数字海洋空间的名称 。 例如,如果你将您的空间称为 备份- 桶, 选项会像这样 : - 桶备份- 桶 , `
  • -备份-位置-配置' s3Url=https://nyc3.digital oceanspaces.com, region=nyc3': (原始内容存档于2017-09-31). 更改 URL 和区域以匹配您的 Space 设置 。 具体地说,编辑两个 " nyc3 " 部分,以便与您的空间所在区域相匹配。 例如,如果您的空间位于 fra1区域, 线条看起来是这样的 :- 备份位置- 配置 第3条 Url=https://fra1. Digital Oceanspaces.com, region=fra1'. 各区域的识别标志是:nyc3'、sfo2'、sgp1'和`fra1'。 .

一旦您完成了适当的桶和备份位置设置,是时候安装Velero了。运行以下命令,在需要时取代您的值:

1velero install \
2  --provider velero.io/aws \
3  --bucket velero-backups \
4  --plugins velero/velero-plugin-for-aws:v1.0.0,digitalocean/velero-plugin:v1.0.0 \
5  --backup-location-config s3Url=https://nyc3.digitaloceanspaces.com,region=nyc3 \
6  --use-volume-snapshots=false \
7  --secret-file ./examples/cloud-credentials

你应该看到以下结果:

 1[secondary_label Output]
 2CustomResourceDefinition/backups.velero.io: attempting to create resource
 3CustomResourceDefinition/backups.velero.io: created
 4CustomResourceDefinition/backupstoragelocations.velero.io: attempting to create resource
 5CustomResourceDefinition/backupstoragelocations.velero.io: created
 6CustomResourceDefinition/deletebackuprequests.velero.io: attempting to create resource
 7CustomResourceDefinition/deletebackuprequests.velero.io: created
 8CustomResourceDefinition/downloadrequests.velero.io: attempting to create resource
 9CustomResourceDefinition/downloadrequests.velero.io: created
10CustomResourceDefinition/podvolumebackups.velero.io: attempting to create resource
11CustomResourceDefinition/podvolumebackups.velero.io: created
12CustomResourceDefinition/podvolumerestores.velero.io: attempting to create resource
13CustomResourceDefinition/podvolumerestores.velero.io: created
14CustomResourceDefinition/resticrepositories.velero.io: attempting to create resource
15CustomResourceDefinition/resticrepositories.velero.io: created
16CustomResourceDefinition/restores.velero.io: attempting to create resource
17CustomResourceDefinition/restores.velero.io: created
18CustomResourceDefinition/schedules.velero.io: attempting to create resource
19CustomResourceDefinition/schedules.velero.io: created
20CustomResourceDefinition/serverstatusrequests.velero.io: attempting to create resource
21CustomResourceDefinition/serverstatusrequests.velero.io: created
22CustomResourceDefinition/volumesnapshotlocations.velero.io: attempting to create resource
23CustomResourceDefinition/volumesnapshotlocations.velero.io: created
24Waiting for resources to be ready in cluster...
25Namespace/velero: attempting to create resource
26Namespace/velero: created
27ClusterRoleBinding/velero: attempting to create resource
28ClusterRoleBinding/velero: created
29ServiceAccount/velero: attempting to create resource
30ServiceAccount/velero: created
31Secret/cloud-credentials: attempting to create resource
32Secret/cloud-credentials: created
33BackupStorageLocation/default: attempting to create resource
34BackupStorageLocation/default: created
35Deployment/velero: attempting to create resource
36Deployment/velero: created
37Velero is installed!  Use 'kubectl logs deployment/velero -n velero' to view the status.

您可以从输出中使用kubectl命令观看部署日志.一旦部署完成,您可以转到下一步,即配置服务器。

1kubectl get deployment/velero --namespace velero
1[secondary_label Output]
2NAME READY UP-TO-DATE AVAILABLE AGE
3velero 1/1 1 1 2m

在此时,您已将Velero的服务器组件安装在您的Kubernetes集群中作为部署,您还使用Kubernetes Secret注册了您的Spaces密钥。

注意:您可以指定)。

步骤 4 — 配置快照

当我们安装Velero服务器时,选项--use-volume-snapshots=false是命令的一部分.由于我们希望在Kubernetes集群中拍摄底层区块存储设备的快照,我们需要告诉Velero使用正确的DigitalOcean区块存储插件。

运行以下命令来启用插件并将其注册为默认快照提供商:

1velero snapshot-location create default --provider digitalocean.com/velero

您将看到以下结果:

1[secondary_label Output]
2Snapshot volume location "default" configured successfully.

步骤5 — 添加 API 代币

在之前的步骤中,我们在Velero服务器中创建了区块存储和对象存储对象,我们与服务器注册了‘digitalocean/velero-plugin:v1.0.0’插件,并在集群中安装了我们的Spaces秘密密钥。

最后一步是修补我们之前创建的云信号秘密,以使用我们的DigitalOcean API代币。

我們可以使用「kubectl edit」命令來改變 Velero 部署對象,以指向 API 標記。然而,手動編輯複雜的 YAML 對象可能很累,而且容易發生錯誤。相反,我們會使用「kubectl patch」命令,因為 Kubernetes 支援 patching objects

第一个补丁文件是您之前编辑的 examples/01-velero-secret.patch.yaml 文件,旨在将您的 API 代码添加到已包含您的 Spaces 密钥的 secrets/cloud-credentials Secret 文件中。

1cat examples/01-velero-secret.patch.yaml

它应该是这样的(你的代码代替):

1[label examples/01-velero-secret.patch.yaml]
2. . .
3---
4apiVersion: v1
5kind: Secret
6stringData:
7  digitalocean_token: <DIGITALOCEAN_API_TOKEN>
8type: Opaque

现在让我们看看部署的补丁文件:

1cat examples/02-velero-deployment.patch.yaml

你应该看到以下YAML:

 1[label examples/02-velero-deployment.patch.yaml]
 2. . .
 3---
 4apiVersion: v1
 5kind: Deployment
 6spec:
 7  template:
 8    spec:
 9      containers:
10      - args:
11        - server
12        command:
13        - /velero
14        env:
15        - name: DIGITALOCEAN_TOKEN
16          valueFrom:
17            secretKeyRef:
18              key: digitalocean_token
19              name: cloud-credentials
20        name: velero

由于这是一个补丁,我们不需要指定一个完整的 Kubernetes 对象 spec 或元数据。在这种情况下,Velero 部署已经配置了使用云信号的秘密,因为velero install命令为我们创建了它,所以这个补丁需要做的就是注册digitalocean_token作为已部署的Velero Pod环境变量。

让我们使用kubectl patch命令应用第一个秘密补丁:

1kubectl patch secret/cloud-credentials -p "$(cat examples/01-velero-secret.patch.yaml)" --namespace velero

你应该看到以下结果:

1[secondary_label Output]
2secret/cloud-credentials patched

最后,我们将修补部署,运行以下命令:

1kubectl patch deployment/velero -p "$(cat examples/02-velero-deployment.patch.yaml)" --namespace velero

您将看到下列情况,如果补丁成功:

1[secondary_label Output]
2deployment.apps/velero patched

让我们来验证修补的部署在velero名称空间中使用kubectl get工作:

1kubectl get deployment/velero --namespace velero

你应该看到以下结果:

1[secondary_label Output]
2NAME READY UP-TO-DATE AVAILABLE AGE
3velero 1/1 1 1 12s

在此时,Velero正在运行和完全配置,并准备备份和恢复您的Kubernetes集群对象和持久卷到DigitalOcean空间和区块存储。

在下一节中,我们将运行一个快速测试,以确保备份和恢复功能按预期工作。

第6步:测试备份和恢复程序

现在我们已经成功安装和配置了Velero,我们可以创建一个测试NGINX部署,具有持久的量和服务.一旦部署运行,我们将通过备份和恢复钻探,以确保Velero配置和正常工作。

确保您仍然在 /tmp/velero-plugin-1.0.0 目录中工作. examples' 目录包含一个名为 nginx-example.yaml' 的 Nginx 示例。

使用您选择的编辑器打开此文件:

1nano examples/nginx-example.yaml

你应该看到以下文本:

 1[secondary_label Output]
 2. . .
 3---
 4apiVersion: v1
 5kind: Namespace
 6metadata:
 7  name: nginx-example
 8  labels:
 9    app: nginx
10
11---
12kind: PersistentVolumeClaim
13apiVersion: v1
14metadata:
15  name: nginx-logs
16  namespace: nginx-example
17  labels:
18    app: nginx
19spec:
20  storageClassName: do-block-storage
21  accessModes:
22    - ReadWriteOnce
23  resources:
24    requests:
25      storage: 5Gi
26
27---
28apiVersion: apps/v1
29kind: Deployment
30metadata:
31  name: nginx-deploy
32  namespace: nginx-example
33  labels:
34    app: nginx
35spec:
36  replicas: 1
37  selector:
38    matchLabels:
39      app: nginx
40  template:
41    metadata:
42      labels:
43        app: nginx
44    spec:
45      volumes:
46        - name: nginx-logs
47          persistentVolumeClaim:
48           claimName: nginx-logs
49      containers:
50      - image: nginx:stable
51        name: nginx
52        ports:
53        - containerPort: 80
54        volumeMounts:
55          - mountPath: "/var/log/nginx"
56            name: nginx-logs
57            readOnly: false
58
59---
60apiVersion: v1
61kind: Service
62metadata:
63  labels:
64    app: nginx
65  name: nginx-svc
66  namespace: nginx-example
67spec:
68  ports:
69  - port: 80
70    targetPort: 80
71  selector:
72    app: nginx
73  type: LoadBalancer

在此檔案中,我們觀察 Specs for:

  • 一个 Nginx 名称空间称为 'nginx-example' * 一个 Nginx 部署由一个单一的副本构成的 'nginx:stable' 容器图像 * 一个 5Gi 持久量声明(称为 'nginx-logs'),使用 'do-block-storage' StorageClass * A 'LoadBalancer' 服务暴露端口 `80'

使用kubectl应用创建对象:

1kubectl apply -f examples/nginx-example.yaml

你应该看到以下结果:

1[secondary_label Output]
2namespace/nginx-example created
3persistentvolumeclaim/nginx-logs created
4deployment.apps/nginx-deploy created
5service/nginx-svc created

检查部署是否成功:

1kubectl get deployments --namespace=nginx-example

你应该看到以下结果:

1[secondary_label Output]
2NAME READY UP-TO-DATE AVAILABLE AGE
3nginx-deploy 1/1 1 1 1m23s

一旦可用达到1,请使用kubectl get获取 Nginx 负载平衡器的外部 IP:

1kubectl get services --namespace=nginx-example

您应该看到my-nginx服务的内部CLUSTER-IPEXTERNAL-IP:

1[secondary_label Output]
2NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S)        AGE
3nginx-svc LoadBalancer 10.245.147.61 159.203.48.191 80:30232/TCP 3m1s

记住EXTERNAL-IP,并使用您的网页浏览器导航到它。

您应该看到以下NGINX欢迎页面:

Nginx Welcome Page

这表明您的 Nginx 部署和服务正在运行。

在模拟我们的灾难场景之前,让我们先检查 Nginx 访问日志(存储在附加到 Nginx Pod 的持久卷上):

使用kubectl get获取Pod的名称:

1kubectl get pods --namespace nginx-example
1[secondary_label Output]
2NAME READY STATUS RESTARTS AGE
3nginx-deploy-694c85cdc8-vknsk 1/1 Running 0 4m14s

现在,‘exec’到运行的 Nginx 容器中,以便在里面得到一个壳:

1kubectl exec -it nginx-deploy-694c85cdc8-vknsk --namespace nginx-example -- /bin/bash

一旦进入 Nginx 容器, Nginx 访问日志将:

1[environment second]
2cat /var/log/nginx/access.log

你应该看到一些 Nginx 访问条目:

1[environment second]
2[secondary_label Output]
310.244.0.119 - - [03/Jan/2020:04:43:04 +0000] "GET / HTTP/1.1" 200 612 "-" "Mozilla/5.0 (X11; Linux x86_64; rv:72.0) Gecko/20100101 Firefox/72.0" "-"
410.244.0.119 - - [03/Jan/2020:04:43:04 +0000] "GET /favicon.ico HTTP/1.1" 404 153 "-" "Mozilla/5.0 (X11; Linux x86_64; rv:72.0) Gecko/20100101 Firefox/72.0" "-"

记住这些(特别是时间标签),因为我们将使用它们来确认恢复过程的成功。

1exit

现在我们可以执行备份程序,将所有nginx Kubernetes 对象复制到 Spaces,并拍摄我们在部署 Nginx 时创建的持久卷的截图。

我们将使用velero命令行客户端创建一个名为nginx-backup的备份:

1velero backup create nginx-backup --selector app=nginx

--selector app=nginx指示Velero服务器只使用app=nginx标签选择器来备份Kubernetes对象。

你应该看到以下结果:

1[secondary_label Output]
2Backup request "nginx-backup" submitted successfully.
3Run `velero backup describe nginx-backup` or `velero backup logs nginx-backup` for more details.

运行velero 备份描述 nginx 备份 -details应在短时间后提供以下输出:

 1[secondary_label Output]
 2Name:         nginx-backup
 3Namespace:    velero
 4Labels:       velero.io/backup=nginx-backup
 5              velero.io/pv=pvc-6b7f63d7-752b-4537-9bb0-003bed9129ca
 6              velero.io/storage-location=default
 7Annotations:  <none>
 8
 9Phase:  Completed
10
11Namespaces:
12  Included:  *
13  Excluded:  <none>
14
15Resources:
16  Included:        *
17  Excluded:        <none>
18  Cluster-scoped:  auto
19
20Label selector:  app=nginx
21
22Storage Location:  default
23
24Snapshot PVs:  auto
25
26TTL:  720h0m0s
27
28Hooks:  <none>
29
30Backup Format Version:  1
31
32Started:    2020-01-02 23:45:30 -0500 EST
33Completed:  2020-01-02 23:45:34 -0500 EST
34
35Expiration:  2020-02-01 23:45:30 -0500 EST
36
37Resource List:
38  apps/v1/Deployment:
39    - nginx-example/nginx-deploy
40  apps/v1/ReplicaSet:
41    - nginx-example/nginx-deploy-694c85cdc8
42  v1/Endpoints:
43    - nginx-example/nginx-svc
44  v1/Namespace:
45    - nginx-example
46  v1/PersistentVolume:
47    - pvc-6b7f63d7-752b-4537-9bb0-003bed9129ca
48  v1/PersistentVolumeClaim:
49    - nginx-example/nginx-logs
50  v1/Pod:
51    - nginx-example/nginx-deploy-694c85cdc8-vknsk
52  v1/Service:
53    - nginx-example/nginx-svc
54
55Persistent Volumes:
56  pvc-6b7f63d7-752b-4537-9bb0-003bed9129ca:
57    Snapshot ID:        dfe866cc-2de3-11ea-9ec0-0a58ac14e075
58    Type:               ext4
59    Availability Zone:  
60    IOPS:               <N/A>

此输出表示nginx-backup已成功完成.资源列表显示了备份中包含的每个 Kubernetes 对象。

要从 DigitalOcean 云控制面板中确认,请导航到包含 Kubernetes 备份文件的空间。

您应该看到一个名为nginx-backup的新目录,其中包含 Velero 备份文件。

使用左侧的导航栏,转到 图片 ,然后转到** Snapshots** . 在** Snapshots** 中,转到** Volumes** . 您应该看到一个与上面的输出中列出的PVC相匹配的Snapshot。

现在我们可以测试恢复过程。

让我们先删除nginx-example的名称空间,这将删除名称空间中的所有内容,包括负载平衡器和持久卷:

1kubectl delete namespace nginx-example

验证您不再可以在负载平衡器终端访问 Nginx,并且nginx 示例部署不再运行:

1kubectl get deployments --namespace=nginx-example
1[secondary_label Output]
2No resources found in nginx-example namespace.

现在我们可以执行恢复程序,再一次使用velero客户端:

1velero restore create --from-backup nginx-backup

在这里,我们使用创建来从nginx-backup对象创建一个Velero恢复对象。

你应该看到以下结果:

1[secondary_label Output]
2Restore request "nginx-backup-20200102235032" submitted successfully.
3Run `velero restore describe nginx-backup-20200102235032` or `velero restore logs nginx-backup-20200102235032` for more details.

查看恢复部署的状态:

1kubectl get deployments --namespace=nginx-example
1[secondary_label Output]
2NAME READY UP-TO-DATE AVAILABLE AGE
3nginx-deploy 1/1 1 1 58s

检查创建持久量:

1kubectl get pvc --namespace=nginx-example
1[secondary_label Output]
2NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE
3nginx-logs Bound pvc-6b7f63d7-752b-4537-9bb0-003bed9129ca 5Gi RWO do-block-storage 75s

恢复程序还创建了 LoadBalancer。有时,该服务会用新的IP地址重新创建,您需要再次找到EXTERNAL-IP地址:

1kubectl get services --namespace nginx-example
1[secondary_label Output]
2NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S)        AGE
3nginx-svc LoadBalancer 10.245.15.83 159.203.48.191 80:31217/TCP 97s

再次导航到 Nginx 服务的外部 IP,以确认 Nginx 已启动并运行。

最后,检查恢复的持久卷上的日志,以确认日志历史在恢复后已保留。

要做到这一点,再一次使用kubectl get获取Pod的名称:

1kubectl get pods --namespace nginx-example
1[secondary_label Output]
2NAME READY STATUS RESTARTS AGE
3nginx-deploy-694c85cdc8-vknsk 1/1 Running 0 2m20s

然后exec进入它:

1kubectl exec -it nginx-deploy-694c85cdc8-vknsk --namespace nginx-example -- /bin/bash

一旦进入 Nginx 容器, Nginx 访问日志将:

1[environment second]
2cat /var/log/nginx/access.log
1[environment second]
2[secondary_label Output]
310.244.0.119 - - [03/Jan/2020:04:43:04 +0000] "GET / HTTP/1.1" 200 612 "-" "Mozilla/5.0 (X11; Linux x86_64; rv:72.0) Gecko/20100101 Firefox/72.0" "-"
410.244.0.119 - - [03/Jan/2020:04:43:04 +0000] "GET /favicon.ico HTTP/1.1" 404 153 "-" "Mozilla/5.0 (X11; Linux x86_64; rv:72.0) Gecko/20100101 Firefox/72.0" "-"

您应该看到相同的备份前访问尝试(注意时刻标记),确认持久量恢复成功。

此时,我们已经成功地将我们的 Kubernetes 对象备份到 DigitalOcean Spaces,并使用 Block Storage Volume Snapshots 使用我们的 Persistent Volumes。

结论

在本指南中,我们在基于 DigitalOcean 的 Kubernetes 集群上安装并配置了 Velero Kubernetes 备份工具。

Velero 也可以用来安排您 Kubernetes 集群的定期备份 灾难恢复. 要做到这一点,您可以使用 velero schedule 命令. Velero 也可以用来 资源迁移从一个集群到另一个集群。

若要了解更多关于 DigitalOcean Spaces 的信息,请参阅 官方 Spaces 文档. 若要了解更多关于 Block Storage Volumes 的信息,请参阅 Block Storage Volume documentation.

本教程建立在 StackPointCloud 的 ark-plugin-digitalocean GitHub 复制中找到的 README。

Published At
Categories with 技术
comments powered by Disqus