• notice
  • Congratulations on the launch of the Sought Tech site

Kubernetes(k8s) etcd create snapshot and restore data method

Etcd is a highly available key-value storage system, mainly used for shared configuration and service discovery.It uses the Raft consistency algorithm to process log replication to ensure strong consistency.It can be understood that it is a highly available and strong consistency service discovery storage warehouse. This article mainly introduces Kubernetes (k8s) etcd to create snapshots and restore data methods.

Example server:

etcd1: etcd-41 192.168.31.41etcd2: etcd-42 192.168.31.42etcd3: etcd-43 192.168.31.43

1.Precautions for use

Taking a snapshot can only be done in etcdctl version 3, and it needs to be configured export ETCDCTL_API=3.The specific method can refer to the document as follows:

Reference document: Kubernetes (k8s) etcd installation and configuration of single node cluster method

2.Create test data

Create data on etcd1:

[root@etcd1 ~]# etcdctl put k8s1 cjavapy
OK
[root@etcd1 ~]# etcdctl put k8s2 Python
OK
[root@etcd1 ~]# etcdctl get k8s1
k8s1 
cjavapy
[root@etcd1 ~]# etcdctl get k8s2
k8s2 
Python

3.Create a snapshot

To create a snapshot on etcd1, the command is as follows:

[root@etcd1 ~]# etcdctl snap save snap1
Snapshot saved at snap1
[root@etcd1 ~]# ls
snap1

If you have a certificate, you need to add related parameters:

etcdctl snap save --cacert=domain1.crt --cert=node1.pem --key=node1.key --endpoints=https://127.0.0.1:2379 snap1

4.Test and restore data

1) Delete k8s1andk8s2

[root@etcd1 ~]# etcdctl del k8s11
[root@etcd1 ~]# etcdctl del k8s2
1

2) Transfer the snapshot file snap1 on etcd1 to the other two servers:

scp snap1 192.168.31.42:~scp snap1 192.168.31.43:~

3) Stop etcd services on all nodes and delete data:

systemctl stop etcdrm -rf /var/lib/etcd/*

4) Set permissions for the snapshot file snap1 on each server:

chown etcd.etcd snap1

5) Restore the data of each node through the snapshot file:

etcdctl snapshot restore snap1 --name etcd-41 --initial-cluster etcd-41=http://192.168.31.41:2380,etcd-42=http://192.168.31.42:2380,etcd-43=http:/ /192.168.31.43:2380 --initial-advertise-peer-urls http://192.168.31.41:2380 --data-dir /var/lib/etcd/cluster.etcdetcdctl snapshot restore snap1 --name etcd-42 --initial-cluster etcd-41=http://192.168.31.41:2380,etcd-42=http://192.168.31.42:2380,etcd-43=http:/ /192.168.31.43:2380 --initial-advertise-peer-urls http://192.168.31.42:2380 --data-dir /var/lib/etcd/cluster.etcdetcdctl snapshot restore snap1 --name etcd-43 --initial-cluster etcd-41=http://192.168.31.41:2380,etcd-42=http://192.168.31.42:2380,etcd-43=http:/ /192.168.31.43:2380 --initial-advertise-peer-urls http://192.168.31.43:2380 --data-dir /var/lib/etcd/cluster.etcd

6) After the restoration is complete, set the permissions of /var/lib/etcd/ in each node

chown -R etcd.etcd /var/lib/etcd/

7) Start the etcd service on each server

systemctl start etcd

8) Test the data saved before the snapshot:

[root@etcd1 ~]# etcdctl get k8s1
k8s1 
cjavapy
[root@etcd1 ~]# etcdctl get k8s2
k8s2 
Python

Tags

Technical otaku

Sought technology together

Related Topic

0 Comments

Leave a Reply

+