Mais conteúdo relacionado Semelhante a KubernetesバックアップツールVeleroとちょっとした苦労話 (20) KubernetesバックアップツールVeleroとちょっとした苦労話3. Who are you?
3
村田 一平 (Murata Ippei)
• デグー飼ってます。
• メダカ、オトシンクルス、
クーリーローチ、ヤマトヌマエビ、飼ってます。
• TL: 41(あとイーブイ1進化でTL42)
16. クラスタの複製
こんな時に
• 開発者ごとにFluentbit, Prometheus, Harbor導入・設定済みの
クラスタを用意したい
• アップデート前に今のクラスタと同等構成で事前検証したい
16
Master Node
Worker Node
Worker Node
Worker Node
Master Node
Worker Node
Worker Node
Worker Node
Master Node
Worker Node
Worker Node
Worker Node
18. Veleroの構成
18
Master Node
Worker Node
Worker Node
Worker Node
CRD
backups
restores schedules
backupstoragelocations
volumesnapshotlocations
podvolumerestores
podvolumebacdkups resticrepositories
downloadrequests serverstatusrequests
deletebackuprequests
Velero + Restic Plugin(PV取得用プラグイン)導入時
19. Veleroの構成
19
Master Node
Worker Node
Worker Node
Worker Node
CRD
backups
restores schedules
backupstoragelocations
volumesnapshotlocations
podvolumerestores
podvolumebacdkups resticrepositories
downloadrequests serverstatusrequests
deletebackuprequests
Velero + Restic Plugin(PV取得用プラグイン)導入時
■構成はシンプル
• 司令塔となるDeployment
• 各Nodeに紐づくPVを吸い上げる
DaemonSet
(※Restic導入時)
20. Veleroの構成
20
Master Node
Worker Node
Worker Node
Worker Node
CRD
backups
restores schedules
backupstoragelocations
volumesnapshotlocations
podvolumerestores
podvolumebacdkups resticrepositories
downloadrequests serverstatusrequests
deletebackuprequests
Velero + Restic Plugin(PV取得用プラグイン)導入時
■CRDは多様
• ほとんどの機能・操作をCRDで実現
→ 操作の状況をkubectlでも確認可能
(veleroコマンドの方が使えないこと多々)
→ 消費リソースは抑え気味
• KubernetesのAPIで機能を実行
→ 非同期なので動きが読みづらいことも
21. Veleroの仕組み
21
オペレータ
# velero backup create
Master Node
Worker Node
Worker Node
Worker Node
カスタムリソースの
作成要求
(Kubernetes API)
MinIO
S3
ABS
GCS
etc
カスタムリソースの
作成要求
(Kubernetes API)
23. Backup/Restore
23
対象を絞ってのバックアップ・リストア
バックアップの例:
• Namespace
• Resource
• Label
• クラスタースコープ ※
velero restore create <backup-name> --include-namespaces <namespace1>,<namespace2>
velero restore create <backup-name> --include-resources deployments,configmaps
velero backup create <backup-name> --selector <key>=<value>
velero restore create <backup-name> --include-cluster-resources=false
※Namespaceと紐付かないもの。 PVやStorageClassなど。
kubectl api-resources でNAMSPACEDがfalseになっているリソース。
24. Backup/Restore
24
バックアップの内容はdescribe --detailsで確認可能
$ velero describe backup <backupname> --details
:(省略)
Resource List:
addons.cluster.x-k8s.io/v1alpha3/ClusterResourceSet:
- default/dummyworkload-cni-antrea
- default/dummyworkload-csi
- default/dummyworkload-default-storage-class
- default/dummyworkload-tkg-metadata
addons.cluster.x-k8s.io/v1alpha3/ClusterResourceSetBinding:
- default/dummyworkload
apiextensions.k8s.io/v1/CustomResourceDefinition:
- apps.kappctrl.k14s.io
- certificaterequests.cert-manager.io
:(省略)
25. バックアップ前後処理の実行
25
バックアップ前後に任意のコマンドが実行可能
kubectl annotate pod -n nginx-example -l app=nginx ¥
pre.hook.backup.velero.io/command='["/sbin/fsfreeze", "--freeze", "/var/log/nginx"]' ¥
pre.hook.backup.velero.io/container=fsfreeze ¥
post.hook.backup.velero.io/command='["/sbin/fsfreeze", "--unfreeze", "/var/log/nginx"]' ¥
post.hook.backup.velero.io/container=fsfreeze
※注意点
• コンテナ内にコマンドがない場合、コマンドが実行できるコンテナをPodに入れる必要あり
• fsfreezeなどボリューム操作を伴う場合はvolumeを共有する必要あり
• コマンドによっては強力な権限(privileged: true)が必要になる場合あり
ファイルシステムの静止化などで活用可能
26. リストア前後処理の実行
26
リストア前の処理についてはinitコンテナを立ち上げることで実施
$ kubectl annotate pod -n <POD_NAMESPACE> <POD_NAME>
init.hook.restore.velero.io/container-name=restore-hook
init.hook.restore.velero.io/container-image=alpine:latest
init.hook.restore.velero.io/command='["/bin/ash", "-c", "date"]'
※注意点
• リストア前の処理はv1.4.x以前だと未対応。v1.5以降を使う必要あり
リストア後の処理指定はバックアップ時と同様
27. 小ネタ1
進捗はveleroコマンドではなくPodから確認する
27
• バックアップの細かい進捗状況はveleroコマンドから確認不可
• PluginによってはVeleroの完了と非同期でバックアップを実行する ※後述、要注意
$ kubectl logs -n velero deploy/velero -f
:(省略)
time="2021-02-26T02:52:54Z" level=info msg="Processing item" backup=velero/cndo1151 logSource="pkg/backu
time="2021-02-26T02:52:54Z" level=info msg="Backing up item" backup=velero/cndo1151 logSource="pkg/backu
time="2021-02-26T02:52:54Z" level=info msg="Backed up 779 items out of an estimated total of 785 (estimate
$ velero restore logs testbk
Logs for restore "testbk" are not available until it's finished processing.
40. 苦労4:本体のバグ
E0105 21:55:15.865928 1 runtime.go:78] Observed a panic: "invalid memory address or nil pointer dereference" (runtime error: invalid memory address or nil pointer dereference) goroutine
551 [running]: k8s.io/apimachinery/pkg/util/runtime.logPanic(0x163e040, 0x26dfda0) /go/pkg/mod/k8s.io/apimachinery@v0.17.9/pkg/util/runtime/runtime.go:74 +0xa3
k8s.io/apimachinery/pkg/util/runtime.HandleCrash(0x0, 0x0, 0x0)
40
CAPIを含むクラスタをリストアすると、 capi-controller-managerがリストア後にpanicする
原因:
1. Veleroはリソースをアルファベット順で復元する
2. CRDによっては、あるリソースのオブジェクトが先に作られていることを前提としている
(今回の場合はClusterResourceSetBindingsはClusterResourceSetsが
先に起動するのを前提としている)
回避策:
Veleroの引数で起動順序を指定する(--restore-resource-priorities)
※このオプションで指定したリソースが優先的にリストア
指定しなかったものはアルファベット順
※v1.6.0で対策予定 参考: https://github.com/kubernetes-sigs/cluster-api/issues/4105
https://github.com/vmware-tanzu/velero/pull/3446
41. 苦労4:本体のバグ
E0105 21:55:15.865928 1 runtime.go:78] Observed a panic: "invalid memory address or nil pointer dereference" (runtime error: invalid memory address or nil
pointer dereference) goroutine 551 [running]: k8s.io/apimachinery/pkg/util/runtime.logPanic(0x163e040, 0x26dfda0)
/go/pkg/mod/k8s.io/apimachinery@v0.17.9/pkg/util/runtime/runtime.go:74 +0xa3 k8s.io/apimachinery/pkg/util/runtime.HandleCrash(0x0, 0x0, 0x0)
41
CAPIを含むクラスタをリストアすると、 capi-controller-managerがリストア後にpanicする
原因:
1. Veleroはリソースをアルファベット順で復元する
2. CRDによっては、あるリソースのオブジェクトが先に作られていることを前提としている
(今回の場合はClusterResourceSetBindingsはClusterResourceSetsが
先に起動するのを前提としている)
回避策:
Veleroの引数で起動順序を指定する(--restore-resource-priorities)
※このオプションで指定したリソースが優先的にリストア
指定しなかったものはアルファベット順
※v1.6.0で対策予定 参考: https://github.com/kubernetes-sigs/cluster-api/issues/4105
https://github.com/vmware-tanzu/velero/pull/3446
教訓
• リコンサイルループで復旧しないリソースもある
• CRD関連の挙動を全て把握するのは困難
→ ユースケースベースでの事前検証は大事
• 怪しいと思ったら中の人に早く聞く
(velero bugコマンド)
42. 苦労5:プラグインのバグ
# mc ls -r minio
[2021-02-23 22:33:58 PST] 0B tkg/plugins/vsphere-astrolabe-repo/ivd/data/ivd:xxxx
[2021-02-23 22:33:59 PST] 3.1KiB tkg/plugins/vsphere-astrolabe-repo/ivd/md/ivd:xxxx
[2021-02-23 22:33:59 PST] 984B tkg/plugins/vsphere-astrolabe-repo/ivd/peinfo/ivd:xxxx
42
PVのバックアップが正常に成功するも、サイズがゼロbyte ※vSphere plugin利用時
原因:
1. PVの要求サイズをテスト用に1MBと小さい値を指定していた
2 . vSphere Pluginが10MB未満のPVはデータを取りに行かない作りになっていた
対策:
PVのサイズを変更(念の為100MB程度に)
43. 苦労5: プラグインのバグ
# mc ls -r minio
[2021-02-23 22:33:58 PST] 0B tkg/plugins/vsphere-astrolabe-repo/ivd/data/ivd:xxxx
[2021-02-23 22:33:59 PST] 3.1KiB tkg/plugins/vsphere-astrolabe-repo/ivd/md/ivd:xxxx
[2021-02-23 22:33:59 PST] 984B tkg/plugins/vsphere-astrolabe-repo/ivd/peinfo/ivd:xxxx
43
PVのバックアップが正常に成功するも、サイズがゼロbyte ※vSphere plugin利用時
原因:
1. PVの要求サイズをテスト用に1MBと小さい値を指定していた
2 . vSphere Pluginが10MB未満のPVはデータを取りに行かない作りになっていた
対策:
PVのサイズを変更(念の為100MB程度に)
教訓
• 仕様として明記されていないものは
テストされていない可能性がある
• 実態にあったケースでテストする