1、kubernetes組件-etcd:
etcd 是CoreOS公司開發(fā)目前是Kubernetes默認(rèn)使用的key-value數(shù)據(jù)存儲(chǔ)系統(tǒng),用于保存
kubernetes的所有集群數(shù)據(jù),etcd支持分布式集群功能,生產(chǎn)環(huán)境使用時(shí)需要為etcd數(shù)據(jù)提
供定期備份機(jī)制
官網(wǎng):https://etcd.io/
GitHub:https://github.com/etcd-io/etcd
官方文檔:
~# cat /etc/systemd/system/etcd.service
Description=Etcd Server
After=network.target
After=network-online.target
Wants=network-online.target
Documentation=https://github.com/coreos
[Service]
Type=notify
WorkingDirectory=/var/lib/etcd/ #數(shù)據(jù)保存目錄ExecStart=/usr/local/bin/etcd \ #二進(jìn)制文件路徑
--name=etcd1 \ #當(dāng)前node 名稱
--cert-file=/etc/etcd/ssl/etcd.pem
--key-file=/etc/etcd/ssl/etcd-key.pem
--peer-cert-file=/etc/etcd/ssl/etcd.pem
--peer-key-file=/etc/etcd/ssl/etcd-key.pem
--trusted-ca-file=/etc/kubernetes/ssl/ca.pem
--peer-trusted-ca-file=/etc/kubernetes/ssl/ca.pem
--initial-advertise-peer-urls=https://192.168.7.101:2380 \ #通告自己的集群端口
--listen-peer-urls=https://192.168.7.101:2380 \ #集群之間通訊端口
--listen-client-urls=https://192.168.7.101:2379,http://127.0.0.1:2379 \ #客戶端訪問地址
--advertise-client-urls=https://192.168.7.101:2379 \ #通告自己的客戶端端口
--initial-cluster-token=etcd-cluster-0 \ #創(chuàng)建集群使用的token,一個(gè)集群內(nèi)的節(jié)點(diǎn)保持一致
--initial-cluster=etcd1=https://192.168.7.101:2380,etcd2=https://192.168.7.102:2380,etcd3=https://192.168.7.103:2380 \ #集群所有的節(jié)點(diǎn)信息 --initial-cluster-state=new \ #新建集群的時(shí)候的值為new,如果是已經(jīng)存在的集群為existing。
--data-dir=/var/lib/etcd #數(shù)據(jù)目錄路徑
Restart=on-failure
RestartSec=5
LimitNOFILE=65536
[Install]
WantedBy=multi-user.target
2、etcdctl常用命令
查看成員信息
etcd有多個(gè)不同的API訪問版本,v1版本已經(jīng)廢棄,etcd v2 和 v3 本質(zhì)上是共享同一套 raft 協(xié)議代碼的兩個(gè)獨(dú)立的應(yīng)用,接口不一樣,存儲(chǔ)不一樣,數(shù)據(jù)互相隔離。也就是說如果從 Etcd v2 升級(jí)到 Etcd v3,原來v2 的數(shù)據(jù)還是只能用 v2 的接口訪問,v3 的接口創(chuàng)建的數(shù)據(jù)也只能訪問通過 v3 的接口訪問。 WARNING:
Environment variable ETCDCTL_API is not set; defaults to etcdctl v2\. #默認(rèn)使用V2版本
Set environment variable ETCDCTL_API=3 to use v3 API or ETCDCTL_API=2 to use v2 API. #設(shè)置API版本
--help查看幫助文檔
root@k8s-master1-etcd1:~# etcdctl --help
NAME:
etcdctl - A simple command line client for etcd3.
USAGE:
etcdctl [flags]
VERSION:
3.5.1
API VERSION:
3.5
COMMANDS:
alarm disarm Disarms all alarms
alarm list Lists all alarms
auth disable Disables authentication
auth enable Enables authentication
auth status Returns authentication status
check datascale Check the memory usage of holding data for different workloads on a given server endpoint.
check perf Check the performance of the etcd cluster
compaction Compacts the event history in etcd
defrag Defragments the storage of the etcd members with given endpoints
del Removes the specified key or range of keys [key, range_end)
elect Observes and participates in leader election
endpoint hashkv Prints the KV history hash for each endpoint in --endpoints
endpoint health Checks the healthiness of endpoints specified in--endpointsflag
endpoint status Prints out the status of endpoints specified in--endpointsflag
get Gets the key or a range of keys
help Help about any command
lease grant Creates leases
lease keep-alive Keeps leases alive (renew)
lease list List all active leases
lease revoke Revokes leases
lease timetolive Get lease information
lock Acquires a named lock
make-mirror Makes a mirror at the destination etcd cluster
member add Adds a member into the cluster
member list Lists all members in the cluster
member promote Promotes a non-voting member in the cluster
member remove Removes a member from the cluster
member update Updates a member in the cluster
move-leader Transfers leadership to another etcd cluster member.
put Puts the given key into the store
role add Adds a new role
role delete Deletes a role
role get Gets detailed information of a role
role grant-permission Grants a key to a role
role list Lists all roles
role revoke-permission Revokes a key from a role
snapshot restore Restores an etcd member snapshot to an etcd directory
snapshot save Stores an etcd node backend snapshot to a given file
snapshot status [deprecated] Gets backend snapshot status of a given file
txn Txn processes all the requests in one transaction
user add Adds a new user
user delete Deletes a user
user get Gets detailed information of a user
user grant-role Grants a role to a user
user list Lists all users
user passwd Changes password of user
user revoke-role Revokes a role from a user
version Prints the version of etcdctl
watch Watches events stream on keys or prefixes
OPTIONS:
--cacert="" verify certificates of TLS-enabled secure servers using this CA bundle
--cert="" identify secure client using this TLS certificate file
--command-timeout=5s timeout for short running command (excluding dial timeout)
--debug[=false] enable client-side debug logging
--dial-timeout=2s dial timeout for client connections
-d, --discovery-srv="" domain name to query for SRV records describing cluster endpoints
--discovery-srv-name="" service name to query when using DNS discovery
--endpoints=[127.0.0.1:2379] gRPC endpoints
-h, --help[=false] help for etcdctl
--hex[=false] print byte strings as hex encoded strings
--insecure-discovery[=true] accept insecure SRV records describing cluster endpoints
--insecure-skip-tls-verify[=false] skip server certificate verification (CAUTION: this option should be enabled only for testing purposes)
--insecure-transport[=true] disable transport security for client connections
--keepalive-time=2s keepalive time for client connections
--keepalive-timeout=6s keepalive timeout for client connections
--key="" identify secure client using this TLS key file
--password="" password for authentication (if this option is used, --user option shouldn't include password)
--user="" username[:password] for authentication (prompt if password is not supplied)
-w, --write-out="simple" set the output format (fields, json, protobuf, simple, table)
驗(yàn)證當(dāng)前etcd所有成員狀態(tài):
#export NODE_IPS="172.31.7.101 172.31.7.102 172.31.7.103"
# for ip in ${NODE_IPS}; do ETCDCTL_API=3 /usr/local/bin/etcdctl --endpoints=https://${ip}:2379 --cacert=/etc/kubernetes/ssl/ca.pem --cert=/etc/kubernetes/ssl/etcd.pem --key=/etc/kubernetes/ssl/etcd-key.pem endpoint health; done

顯示集群成員信息:
ETCDCTL_API=3 /usr/local/bin/etcdctl --write-out=table member list --endpoints=https://172.31.7.101:2379 --cacert=/etc/kubernetes/ssl/ca.pem --cert=/etc/kubernetes/ssl/etcd.pem --key=/etc/kubernetes/ssl/etcd-key.pem

以表格方式顯示節(jié)點(diǎn)詳細(xì)狀態(tài):
export NODE_IPS="172.31.7.101 172.31.7.102 172.31.7.103"
for ip in ${NODE_IPS}; do ETCDCTL_API=3 /usr/local/bin/etcdctl --write-out=table endpoint status --endpoints=https://${ip}:2379 --cacert=/etc/kubernetes/ssl/ca.pem --cert=/etc/kubernetes/ssl/etcd.pem --key=/etc/kubernetes/ssl/etcd-key.pem; done

查看etcd數(shù)據(jù)信息:
~# ETCDCTL_API=3 etcdctl get / --prefix --keys-only #以路徑的方式所有key信息
pod信息:
~# ETCDCTL_API=3 etcdctl get / --prefix --keys-only | grep pod
namespace信息:
~# ETCDCTL_API=3 etcdctl get / --prefix --keys-only | grep namespaces
控制器信息:
root@k8s-etcd1:~# ETCDCTL_API=3 etcdctl get / --prefix --keys-only | grep deployment
calico組件信息:
root@k8s-etcd1:~# ETCDCTL_API=3 etcdctl get / --prefix --keys-only | grep calico
</pre>
etcd增刪改查數(shù)據(jù):
添加數(shù)據(jù)
root@k8s-master1-etcd1:~# etcdctl put /name "sam"
OK
查詢數(shù)據(jù)
root@k8s-master1-etcd1:~# etcdctl get /name
/name
sam
改動(dòng)數(shù)據(jù),#直接覆蓋就是更新數(shù)據(jù)
root@k8s-master1-etcd1:~# etcdctl put /name "sam1"
OK
驗(yàn)證改動(dòng)
root@k8s-master1-etcd1:~# etcdctl get /name
/name
sam1
刪除數(shù)據(jù)
root@k8s-master1-etcd1:~# etcdctl del /name
1
root@k8s-master1-etcd1:~# etcdctl get /name
root@k8s-master1-etcd1:~#
root@k8s-master1-etcd1:~# kubectl get pods -A |grep net-test1
default net-test1 1/1 Running 5 (36m ago) 4d22h
root@k8s-master1-etcd1:~# etcdctl del /registry/pods/default/net-test1
1
root@k8s-master1-etcd1:~# kubectl get pods -A |grep net-test1
root@k8s-master1-etcd1:~#
etcd數(shù)據(jù)watch機(jī)制:
基于不斷監(jiān)看數(shù)據(jù),發(fā)生變化就主動(dòng)觸發(fā)通知客戶端,Etcd v3 的watch機(jī)制支持watch某個(gè)固定的key,也支持watch一個(gè)范圍。
在etcd node1上watch一個(gè)key,沒有此key也可以執(zhí)行watch,后期可以再創(chuàng)建:
etcdctl watch /data
在etcd node2修改數(shù)據(jù),驗(yàn)證etcd node1是否能夠發(fā)現(xiàn)數(shù)據(jù)變化
etcdctl put /data "data v1"
OK
#etcdctl put /data "data v2"
OK
驗(yàn)證etcd node1

3、etcd V3 API版本數(shù)據(jù)備份與恢復(fù):
WAL是write ahead log的縮寫,顧名思義,也就是在執(zhí)行真正的寫操作之前先寫一個(gè)日志,預(yù)寫日志。
wal: 存放預(yù)寫式日志,最大的作用是記錄了整個(gè)數(shù)據(jù)變化的全部歷程。在etcd中,所有數(shù)據(jù)的修改在提交前,都要先寫入到WAL中。
V3版本備份數(shù)據(jù):
root@k8s-master1-etcd1:~# etcdctl snapshot save /data/etcd_backup/etcd_backup_20220419.db
{"level":"info","ts":1650383531.7492867,"caller":"snapshot/v3_snapshot.go:68","msg":"created temporary db file","path":"/data/etcd_backup/etcd_backup_20220419.db.part"}
{"level":"info","ts":1650383531.7510343,"logger":"client","caller":"v3/maintenance.go:211","msg":"opened snapshot stream; downloading"}
{"level":"info","ts":1650383531.751134,"caller":"snapshot/v3_snapshot.go:76","msg":"fetching snapshot","endpoint":"127.0.0.1:2379"}
{"level":"info","ts":1650383531.787254,"logger":"client","caller":"v3/maintenance.go:219","msg":"completed snapshot read; closing"}
{"level":"info","ts":1650383531.793083,"caller":"snapshot/v3_snapshot.go:91","msg":"fetched snapshot","endpoint":"127.0.0.1:2379","size":"3.5 MB","took":"now"}
{"level":"info","ts":1650383531.7934062,"caller":"snapshot/v3_snapshot.go:100","msg":"saved","path":"/data/etcd_backup/etcd_backup_20220419.db"}
Snapshot saved at /data/etcd_backup/etcd_backup_20220419.db
root@k8s-master1-etcd1:~# ll /data/etcd_backup/etcd_backup_20220419.db
-rw------- 1 root root 3469344 Apr 19 23:52 /data/etcd_backup/etcd_backup_20220419.db
V3版本恢復(fù)數(shù)據(jù):
root@k8s-master1-etcd1:~# etcdctl snapshot restore --help
NAME:
snapshot restore - Restores an etcd member snapshot to an etcd directory
USAGE:
etcdctl snapshot restore <filename> [options] [flags]
DESCRIPTION:
Moved to `etcdctl snapshot restore ...`
OPTIONS:
--data-dir="" Path to the data directory
-h, --help[=false] help for restore
--initial-advertise-peer-urls="http://localhost:2380" List of this member's peer URLs to advertise to the rest of the cluster
--initial-cluster="default=http://localhost:2380" Initial cluster configuration for restore bootstrap
--initial-cluster-token="etcd-cluster" Initial cluster token for the etcd cluster during restore bootstrap
--name="default" Human-readable name for this member
--skip-hash-check[=false] Ignore snapshot integrity hash value (required if copied from data directory)
--wal-dir="" Path to the WAL directory (use --data-dir if none given)
GLOBAL OPTIONS:
--cacert="" verify certificates of TLS-enabled secure servers using this CA bundle
--cert="" identify secure client using this TLS certificate file
--command-timeout=5s timeout for short running command (excluding dial timeout)
--debug[=false] enable client-side debug logging
--dial-timeout=2s dial timeout for client connections
-d, --discovery-srv="" domain name to query for SRV records describing cluster endpoints
--discovery-srv-name="" service name to query when using DNS discovery
--endpoints=[127.0.0.1:2379] gRPC endpoints
--hex[=false] print byte strings as hex encoded strings
--insecure-discovery[=true] accept insecure SRV records describing cluster endpoints
--insecure-skip-tls-verify[=false] skip server certificate verification (CAUTION: this option should be enabled only for testing purposes)
--insecure-transport[=true] disable transport security for client connections
--keepalive-time=2s keepalive time for client connections
--keepalive-timeout=6s keepalive timeout for client connections
--key="" identify secure client using this TLS key file
--password="" password for authentication (if this option is used, --user option shouldn't include password)
--user="" username[:password] for authentication (prompt if password is not supplied)
-w, --write-out="simple" set the output format (fields, json, protobuf, simple, table)
還原
root@k8s-master1-etcd1:~# etcdctl snapshot restore /data/etcd_backup/etcd_backup_20220419.db --data-dir="/data/etcddir/"#將數(shù)據(jù)恢復(fù)到一個(gè)新的不存在的目錄中
自動(dòng)備份數(shù)據(jù)
~# mkdir /data/etcd-backup-dir/ -p
~# cat script.sh
#!/bin/bash
source /etc/profile
DATE=`date +%Y-%m-%d_%H-%M-%S`
ETCDCTL_API=3 /usr/bin/etcdctl snapshot save /data/etcd-backup-dir/etcd-snap

4、使用kubeasz項(xiàng)目自帶的etcd集群還原功能
查看pods資源
root@k8s-master1-etcd1:~/yaml# kubectl get pods -A
NAMESPACE NAME READY STATUS RESTARTS AGE
default net-test1 1/1 Running 0 6h37m
default net-test2 1/1 Running 0 6h37m
kube-system calico-kube-controllers-754966f84c-c8d2g 1/1 Running 0 6h49m
kube-system calico-node-csnl7 1/1 Running 0 6h49m
kube-system calico-node-czwwf 1/1 Running 0 6h49m
kube-system calico-node-smmk4 1/1 Running 0 6h49m
kube-system calico-node-wlpl9 1/1 Running 0 6h49m
kube-system coredns-79688b6cb4-kqpgs 1/1 Running 0 3h40m
kubernetes-dashboard dashboard-metrics-scraper-799d786dbf-l52xb 1/1 Running 0 149m
kubernetes-dashboard kubernetes-dashboard-fb8648fd9-p7qt6 1/1 Running 0 149m
使用94號(hào)劇本備份etcd集群
root@k8s-master1-etcd1:/etc/kubeasz# ll ./playbooks/
total 96
drwxrwxr-x 2 root root 4096 Apr 23 23:08 ./
drwxrwxr-x 12 root root 4096 Apr 23 16:33 ../
-rw-rw-r-- 1 root root 422 Apr 23 16:05 01.prepare.yml
-rw-rw-r-- 1 root root 58 Jan 5 20:19 02.etcd.yml
-rw-rw-r-- 1 root root 209 Jan 5 20:19 03.runtime.yml
-rw-rw-r-- 1 root root 482 Jan 5 20:19 04.kube-master.yml
-rw-rw-r-- 1 root root 218 Jan 5 20:19 05.kube-node.yml
-rw-rw-r-- 1 root root 408 Jan 5 20:19 06.network.yml
-rw-rw-r-- 1 root root 77 Jan 5 20:19 07.cluster-addon.yml
-rw-rw-r-- 1 root root 34 Jan 5 20:19 10.ex-lb.yml
-rw-rw-r-- 1 root root 3893 Jan 5 20:19 11.harbor.yml
-rw-rw-r-- 1 root root 1567 Jan 5 20:19 21.addetcd.yml
-rw-rw-r-- 1 root root 1520 Jan 5 20:19 22.addnode.yml
-rw-rw-r-- 1 root root 1050 Jan 5 20:19 23.addmaster.yml
-rw-rw-r-- 1 root root 3344 Jan 5 20:19 31.deletcd.yml
-rw-rw-r-- 1 root root 2018 Jan 5 20:19 32.delnode.yml
-rw-rw-r-- 1 root root 2071 Jan 5 20:19 33.delmaster.yml
-rw-rw-r-- 1 root root 1891 Jan 5 20:19 90.setup.yml
-rw-rw-r-- 1 root root 1054 Jan 5 20:19 91.start.yml
-rw-rw-r-- 1 root root 934 Jan 5 20:19 92.stop.yml
-rw-rw-r-- 1 root root 1042 Jan 5 20:19 93.upgrade.yml
-rw-rw-r-- 1 root root 1786 Jan 5 20:19 94.backup.yml
-rw-rw-r-- 1 root root 999 Jan 5 20:19 95.restore.yml
-rw-rw-r-- 1 root root 337 Jan 5 20:19 99.clean.yml
#查看幫助文檔
root@k8s-master1-etcd1:/etc/kubeasz# ./ezctl --help
Usage: ezctl COMMAND [args]
-------------------------------------------------------------------------------------
Cluster setups:
list to list all of the managed clusters
checkout <cluster> to switch default kubeconfig of the cluster
new <cluster> to start a new k8s deploy with name 'cluster'
setup <cluster> <step> to setup a cluster, also supporting a step-by-step way
start <cluster> to start all of the k8s services stopped by 'ezctl stop'
stop <cluster> to stop all of the k8s services temporarily
upgrade <cluster> to upgrade the k8s cluster
destroy <cluster> to destroy the k8s cluster
backup <cluster> to backup the cluster state (etcd snapshot)
restore <cluster> to restore the cluster state from backups
start-aio to quickly setup an all-in-one cluster with 'default' settings
Cluster ops:
add-etcd <cluster> <ip> to add a etcd-node to the etcd cluster
add-master <cluster> <ip> to add a master node to the k8s cluster
add-node <cluster> <ip> to add a work node to the k8s cluster
del-etcd <cluster> <ip> to delete a etcd-node from the etcd cluster
del-master <cluster> <ip> to delete a master node from the k8s cluster
del-node <cluster> <ip> to delete a work node from the k8s cluster
Extra operation:
kcfg-adm <cluster> <args> to manage client kubeconfig of the k8s cluster
Use "ezctl help <command>" for more information about a given command.
#開始備份
root@k8s-master1-etcd1:/etc/kubeasz# ./ezctl backup k8s-cluster-01
ansible-playbook -i clusters/k8s-cluster-01/hosts -e @clusters/k8s-cluster-
...
...
PLAY RECAP ***************************************************************************************************************************************************************************************************************************
localhost : ok=10 changed=6 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
此時(shí)在kubeasz k8s集群下有一個(gè)backup目錄,etcd備份目錄就放在這里
root@k8s-master1-etcd1:/etc/kubeasz# ll clusters/k8s-cluster-01/backup/
total 5472
drwxr-xr-x 2 root root 4096 Apr 23 23:12 ./
drwxr-xr-x 5 root root 4096 Apr 23 19:17 ../
-rw------- 1 root root 2793504 Apr 23 23:12 snapshot.db
-rw------- 1 root root 2793504 Apr 23 23:12 snapshot_202204232312.db
刪除pods做還原試驗(yàn)
root@k8s-master1-etcd1:/etc/kubeasz# kubectl get pods -A
NAMESPACE NAME READY STATUS RESTARTS AGE
default net-test2 1/1 Running 0 6h46m
kube-system calico-kube-controllers-754966f84c-c8d2g 1/1 Running 0 6h58m
kube-system calico-node-csnl7 1/1 Running 0 6h58m
kube-system calico-node-czwwf 1/1 Running 0 6h58m
kube-system calico-node-smmk4 1/1 Running 0 6h58m
kube-system calico-node-wlpl9 1/1 Running 0 6h58m
kube-system coredns-79688b6cb4-kqpgs 1/1 Running 0 3h49m
kubernetes-dashboard dashboard-metrics-scraper-799d786dbf-l52xb 1/1 Running 0 158m
kubernetes-dashboard kubernetes-dashboard-fb8648fd9-p7qt6 1/1 Running 0 158m
root@k8s-master1-etcd1:/etc/kubeasz# kubectl delete pods -n default net-test1
pod "net-test1" deleted
root@k8s-master1-etcd1:/etc/kubeasz# kubectl get pods -A
NAMESPACE NAME READY STATUS RESTARTS AGE
default net-test2 1/1 Running 0 6h54m
kube-system calico-kube-controllers-754966f84c-c8d2g 1/1 Running 0 7h7m
kube-system calico-node-csnl7 1/1 Running 0 7h7m
kube-system calico-node-czwwf 1/1 Running 0 7h7m
kube-system calico-node-smmk4 1/1 Running 0 7h7m
kube-system calico-node-wlpl9 1/1 Running 0 7h7m
kube-system coredns-79688b6cb4-kqpgs 1/1 Running 0 3h57m
kubernetes-dashboard dashboard-metrics-scraper-799d786dbf-l52xb 1/1 Running 0 166m
kubernetes-dashboard kubernetes-dashboard-fb8648fd9-p7qt6 1/1 Running 0 166m
使用95號(hào)劇本還原etcd集群
root@k8s-master1-etcd1:/etc/kubeasz# ll playbooks/
total 96
drwxrwxr-x 2 root root 4096 Apr 23 23:22 ./
drwxrwxr-x 12 root root 4096 Apr 23 16:33 ../
-rw-rw-r-- 1 root root 422 Apr 23 16:05 01.prepare.yml
-rw-rw-r-- 1 root root 58 Jan 5 20:19 02.etcd.yml
-rw-rw-r-- 1 root root 209 Jan 5 20:19 03.runtime.yml
-rw-rw-r-- 1 root root 482 Jan 5 20:19 04.kube-master.yml
-rw-rw-r-- 1 root root 218 Jan 5 20:19 05.kube-node.yml
-rw-rw-r-- 1 root root 408 Jan 5 20:19 06.network.yml
-rw-rw-r-- 1 root root 77 Jan 5 20:19 07.cluster-addon.yml
-rw-rw-r-- 1 root root 34 Jan 5 20:19 10.ex-lb.yml
-rw-rw-r-- 1 root root 3893 Jan 5 20:19 11.harbor.yml
-rw-rw-r-- 1 root root 1567 Jan 5 20:19 21.addetcd.yml
-rw-rw-r-- 1 root root 1520 Jan 5 20:19 22.addnode.yml
-rw-rw-r-- 1 root root 1050 Jan 5 20:19 23.addmaster.yml
-rw-rw-r-- 1 root root 3344 Jan 5 20:19 31.deletcd.yml
-rw-rw-r-- 1 root root 2018 Jan 5 20:19 32.delnode.yml
-rw-rw-r-- 1 root root 2071 Jan 5 20:19 33.delmaster.yml
-rw-rw-r-- 1 root root 1891 Jan 5 20:19 90.setup.yml
-rw-rw-r-- 1 root root 1054 Jan 5 20:19 91.start.yml
-rw-rw-r-- 1 root root 934 Jan 5 20:19 92.stop.yml
-rw-rw-r-- 1 root root 1042 Jan 5 20:19 93.upgrade.yml
-rw-rw-r-- 1 root root 1786 Jan 5 20:19 94.backup.yml
-rw-rw-r-- 1 root root 999 Jan 5 20:19 95.restore.yml
-rw-rw-r-- 1 root root 337 Jan 5 20:19 99.clean.yml
#幫助文檔
root@k8s-master1-etcd1:/etc/kubeasz# ./ezctl --help
Usage: ezctl COMMAND [args]
-------------------------------------------------------------------------------------
Cluster setups:
list to list all of the managed clusters
checkout <cluster> to switch default kubeconfig of the cluster
new <cluster> to start a new k8s deploy with name 'cluster'
setup <cluster> <step> to setup a cluster, also supporting a step-by-step way
start <cluster> to start all of the k8s services stopped by 'ezctl stop'
stop <cluster> to stop all of the k8s services temporarily
upgrade <cluster> to upgrade the k8s cluster
destroy <cluster> to destroy the k8s cluster
backup <cluster> to backup the cluster state (etcd snapshot)
restore <cluster> to restore the cluster state from backups
start-aio to quickly setup an all-in-one cluster with 'default' settings
Cluster ops:
add-etcd <cluster> <ip> to add a etcd-node to the etcd cluster
add-master <cluster> <ip> to add a master node to the k8s cluster
add-node <cluster> <ip> to add a work node to the k8s cluster
del-etcd <cluster> <ip> to delete a etcd-node from the etcd cluster
del-master <cluster> <ip> to delete a master node from the k8s cluster
del-node <cluster> <ip> to delete a work node from the k8s cluster
#開始還原
root@k8s-master1-etcd1:/etc/kubeasz# ./ezctl restore k8s-cluster-01
ansible-playbook -i clusters/k8s-cluster-01/hosts -e @clusters/k8s-cluster-01/config.yml playbooks/95.restore.yml
2022-04-23 23:38:48 INFO cluster:k8s-cluster-01 restore begins in 5s, press any key to abort:
...
....
PLAY RECAP ***************************************************************************************************************************************************************************************************************************
172.31.7.101 : ok=14 changed=11 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
172.31.7.102 : ok=14 changed=11 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
172.31.7.103 : ok=10 changed=7 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
172.31.7.111 : ok=3 changed=2 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
172.31.7.112 : ok=3 changed=2 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
#驗(yàn)證
root@k8s-master1-etcd1:/etc/kubeasz# kubectl get pods -A
NAMESPACE NAME READY STATUS RESTARTS AGE
default net-test1 1/1 Running 0 7h10m
default net-test2 1/1 Running 0 7h10m
kube-system calico-kube-controllers-754966f84c-c8d2g 1/1 Running 2 (53s ago) 7h23m
kube-system calico-node-csnl7 1/1 Running 0 7h23m
kube-system calico-node-czwwf 1/1 Running 0 7h23m
kube-system calico-node-smmk4 1/1 Running 0 7h23m
kube-system calico-node-wlpl9 1/1 Running 0 7h23m
kube-system coredns-79688b6cb4-kqpgs 1/1 Running 0 4h14m
kubernetes-dashboard dashboard-metrics-scraper-799d786dbf-l52xb 1/1 Running 0 3h3m
kubernetes-dashboard kubernetes-dashboard-fb8648fd9-p7qt6 1/1 Running 0 3h3m