0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

CKA 試験、ETCD バックアップ

Last updated at Posted at 2023-02-23

ETCD

ETCD概要

  • k8sのマスターでcluster情報を保存(event, cpu, RAM)
  • k8sの運用情報を保存

ETCDのバックアップのやり方

チートシート

Etcd snapshot(バックアップ)

1. backup

sudo ETCDCTL_API=3 etcdctl 
  --endpoints=https://127.0.0.1:2379 \
  --cacert=/etc/kubernetes/pki/etcd/ca.crt \
  --cert=/etc/kubernetes/pki/etcd/server.crt \
  --key=/etc/kubernetes/pki/etcd/server.key  \
  snapshot save /tmp/etcd-backup

cacert cert key でオプションをつける必要があるが、下記のコマンドで確認できる
snapshot の場所は/tmp/etcd-backup

ps -ef | grep kube | grep trusted-ca-file
ps -ef | grep kube | grep cert-file
ps -ef | grep kube | grep key-file

스크린샷 2023-02-19 23.08.14.png
스크린샷 2023-02-19 23.09.02.png
스크린샷 2023-02-19 23.09.46.png

Etcd リストア(復元)

1. 新しいパス(/var/lib/etcd-new)で バックアップしたファイルを展開する

sudo ETCDCTL_API=3 etcdctl snapshot restore --data-dir <data-dir-location> snapshotdb
sudo ETCDCTL_API=3 etcdctl snapshot restore --data-dir /var/lib/etcd-new /tmp/etcd-backup

2. etcd podのデータ保存先を/var/lib/etcd-newに変更

sudo -i
vi /etc/kubernetes/manifests/etcd.yaml

3. ファイルの中身で下記のように修正する

  - hostPath:
      path: /var/lib/etcd
      type: DirectoryOrCreate
    name: etcd-data
↓

  - hostPath:
      path: /var/lib/etcd-new
      type: DirectoryOrCreate
    name: etcd-data

스크린샷 2023-02-23 14.00.25.png
스크린샷 2023-02-23 14.00.32.png

4. 保存して、終了すると(wq)etcd podがリブートされる

下記の命令語でetcd podが自動的に再起動されることを確認

sudo docker ps -a | grep etcd
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?