반응형
출처: https://velog.io/@wanny328/kubernetes-etcdctl-command-%EA%B0%80%EC%9D%B4%EB%93%9C
etcd란?
etcd는 kuberntes의 cluster 정보를 key-value 형식으로 저장하는 DB로 kubernetes cluster 운영에 있어 매우 중요.
1. 버전 체크
$ etcdctl version
## 출력 예시
etcdctl version: 3.4.13
API version: 3.4
2. etcd 맴버 조회
$ etcdctl member list -w=table
-w=table 옵션을 주면 가독성 좋게 출력됩니다.
## 출력 예시
+------------------+---------+-------------+------------------------------+------------------------------+------------+
| ID | STATUS | NAME | PEER ADDRS | CLIENT ADDRS | IS LEARNER |
+------------------+---------+-------------+------------------------------+------------------------------+------------+
| 85792d9beda616ff | started | k8s-master2 | https://192.168.178.166:2380 | https://192.168.178.166:2379 | false |
| 90046ab4d4049c30 | started | k8s-master3 | https://192.168.178.167:2380 | https://192.168.178.167:2379 | false |
| e5a6eae61bf0e6a6 | started | k8s-master1 | https://192.168.178.165:2380 | https://192.168.178.165:2379 | false |
+------------------+---------+-------------+------------------------------+------------------------------+------------+
3. health check
$ etcdctl endpoint health --cluster -w=table
## 출력 예시
+------------------------------+--------+------------+-------+
| ENDPOINT | HEALTH | TOOK | ERROR |
+------------------------------+--------+------------+-------+
| https://192.168.178.165:2379 | true | 8.721097ms | |
| https://192.168.178.166:2379 | true | 9.55216ms | |
| https://192.168.178.167:2379 | true | 9.634818ms | |
+------------------------------+--------+------------+-------+
4. etcd 리더 및 전체 상태 조회
$ etcdctl endpoint status --cluster -w=table
## 출력 예시
+------------------------------+------------------+---------+---------+-----------+------------+-----------+------------+--------------------+--------+
| ENDPOINT | ID | VERSION | DB SIZE | IS LEADER | IS LEARNER | RAFT TERM | RAFT INDEX | RAFT APPLIED INDEX | ERRORS |
+------------------------------+------------------+---------+---------+-----------+------------+-----------+------------+--------------------+--------+
| https://192.168.178.166:2379 | 85792d9beda616ff | 3.4.3 | 9.7 MB | false | false | 21 | 325815 | 325815 | |
| https://192.168.178.167:2379 | 90046ab4d4049c30 | 3.4.3 | 9.7 MB | false | false | 21 | 325815 | 325815 | |
| https://192.168.178.165:2379 | e5a6eae61bf0e6a6 | 3.4.3 | 9.7 MB | true | false | 21 | 325815 | 325815 | |
+------------------------------+------------------+---------+---------+-----------+------------+-----------+------------+--------------------+--------+
5. etcd 백업
$ etcdctl snapshot save { 백업할 경로 }/etcd-`date +%Y%m%d_%H%M%S`
etcd-'date~' 은 생성될 snapshot 파일명으로 꼭 저 값이 아니라 원하는 값으로 변경해서 사용해도 괜찮습니다.
## 출력 예시
{"level":"info","ts":1688107398.147482,"caller":"snapshot/v3_snapshot.go:119","msg":"created temporary db file","path":"/root/etcd/etcd-20230630_154318.part"}
{"level":"info","ts":"2023-06-30T15:43:18.154+0900","caller":"clientv3/maintenance.go:200","msg":"opened snapshot stream; downloading"}
{"level":"info","ts":1688107398.154079,"caller":"snapshot/v3_snapshot.go:127","msg":"fetching snapshot","endpoint":"https://192.168.178.165:2379"}
{"level":"info","ts":"2023-06-30T15:43:18.221+0900","caller":"clientv3/maintenance.go:208","msg":"completed snapshot read; closing"}
{"level":"info","ts":1688107398.3090427,"caller":"snapshot/v3_snapshot.go:142","msg":"fetched snapshot","endpoint":"https://192.168.178.165:2379","size":"9.7 MB","took":0.16142193}
{"level":"info","ts":1688107398.3091292,"caller":"snapshot/v3_snapshot.go:152","msg":"saved","path":"/root/etcd/etcd-20230630_154318"}
Snapshot saved at /root/etcd/etcd-20230630_154318
6. etcd 복구
etcdctl snapshot restore { etcd snapshot 파일} \
--name { command 수행하는 node hostname } \
--data-dir /var/lib/etcd/recover \
--initial-cluster { master1 hostname }=https://{ master1 IP }:2380,{ master2 hostname }=https://{ master2 IP }:2380,{ master3 hostname }=https://{ master3 IP }:2380 \
--initial-advertise-peer-urls https://{ command 수행하는 노드 IP }:2380
ETCDCTL is the CLI tool used to interact with ETCD.
ETCDCTL can interact with ETCD Server using 2 API versions - Version 2 and Version 3. By default its set to use Version 2. Each version has different sets of commands.
For example ETCDCTL version 2 supports the following commands:
- etcdctl backup
- etcdctl cluster-health
- etcdctl mk
- etcdctl mkdir
- etcdctl set
Whereas the commands are different in version 3
- etcdctl snapshot save
- etcdctl endpoint health
- etcdctl get
- etcdctl put
반응형
'IT기술 관련 > 쿠버네티스' 카테고리의 다른 글
Docker vs ContainerD (0) | 2024.10.12 |
---|