🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
[TOC] ## 检查 `--endpoints` 标志中指定的端点的健康状况 ```shell $ etcdctl --cacert /data/etcd/certs/ca.pem --cert /data/etcd/certs/etcd.pem --key /data/etcd/certs/etcd-key.pem --endpoints=https://192.168.31.95:2379,https://192.168.31.78:2379,https://192.168.31.253:2379 -w table endpoint health +-----------------------------+--------+-------------+-------+ | ENDPOINT | HEALTH | TOOK | ERROR | +-----------------------------+--------+-------------+-------+ | https://192.168.31.95:2379 | true | 11.955566ms | | | https://192.168.31.253:2379 | true | 11.740747ms | | | https://192.168.31.78:2379 | true | 13.177638ms | | +-----------------------------+--------+-------------+-------+ ``` ## 打印在 `--endpoints` 标志中指定的端点的状态 ```shell $ etcdctl --cacert /data/etcd/certs/ca.pem --cert /data/etcd/certs/etcd.pem --key /data/etcd/certs/etcd-key.pem --endpoints=https://192.168.31.95:2379,https://192.168.31.78:2379,https://192.168.31.253:2379 -w table endpoint status +-----------------------------+------------------+---------+---------+-----------+------------+-----------+------------+--------------------+--------+ | ENDPOINT | ID | VERSION | DB SIZE | IS LEADER | IS LEARNER | RAFT TERM | RAFT INDEX | RAFT APPLIED INDEX | ERRORS | +-----------------------------+------------------+---------+---------+-----------+------------+-----------+------------+--------------------+--------+ | https://192.168.31.95:2379 | a691716a7d43ab3b | 3.4.16 | 20 MB | false | false | 422 | 6635467 | 6635467 | | | https://192.168.31.78:2379 | f833bfe4fb9c10d3 | 3.4.16 | 20 MB | false | false | 422 | 6635467 | 6635467 | | | https://192.168.31.253:2379 | 10f52b9841a7c5f5 | 3.4.16 | 20 MB | true | false | 422 | 6635467 | 6635467 | | +-----------------------------+------------------+---------+---------+-----------+------------+-----------+------------+--------------------+--------+ ``` ## 列出集群中的所有成员 ```shell $ etcdctl --cacert /data/etcd/certs/ca.pem --cert /data/etcd/certs/etcd.pem --key /data/etcd/certs/etcd-key.pem --endpoints=https://192.168.31.95:2379,https://192.168.31.78:2379,https://192.168.31.253:2379 -w table member list +------------------+---------+--------+-----------------------------+-----------------------------+------------+ | ID | STATUS | NAME | PEER ADDRS | CLIENT ADDRS | IS LEARNER | +------------------+---------+--------+-----------------------------+-----------------------------+------------+ | 10f52b9841a7c5f5 | started | etcd03 | https://192.168.31.253:2380 | https://192.168.31.253:2379 | false | | a691716a7d43ab3b | started | etcd01 | https://192.168.31.95:2380 | https://192.168.31.95:2379 | false | | f833bfe4fb9c10d3 | started | etcd02 | https://192.168.31.78:2380 | https://192.168.31.78:2379 | false | +------------------+---------+--------+-----------------------------+-----------------------------+------------+ ``` ## 列出所有警报 ```shell $ etcdctl --cacert /data/etcd/certs/ca.pem --cert /data/etcd/certs/etcd.pem --key /data/etcd/certs/etcd-key.pem --endpoints=https://192.168.31.95:2379,https://192.168.31.78:2379,https://192.168.31.253:2379 alarm list ``` ## 取消所有告警 ```shell $ etcdctl --cacert /data/etcd/certs/ca.pem --cert /data/etcd/certs/etcd.pem --key /data/etcd/certs/etcd-key.pem --endpoints=https://192.168.31.95:2379,https://192.168.31.78:2379,https://192.168.31.253:2379 alarm disarm ``` ## 将 etcd 节点后端快照存储到给定文件 ```shell $ etcdctl --cacert /data/etcd/certs/ca.pem --cert /data/etcd/certs/etcd.pem --key /data/etcd/certs/etcd-key.pem --endpoints=https://192.168.31.95:2379 snapshot save test.db {"level":"info","ts":1643265635.9790843,"caller":"snapshot/v3_snapshot.go:119","msg":"created temporary db file","path":"test.db.part"} {"level":"info","ts":"2022-01-27T14:40:35.987+0800","caller":"clientv3/maintenance.go:200","msg":"opened snapshot stream; downloading"} {"level":"info","ts":1643265635.9875786,"caller":"snapshot/v3_snapshot.go:127","msg":"fetching snapshot","endpoint":"https://192.168.31.95:2379"} {"level":"info","ts":"2022-01-27T14:40:36.372+0800","caller":"clientv3/maintenance.go:208","msg":"completed snapshot read; closing"} {"level":"info","ts":1643265636.4018934,"caller":"snapshot/v3_snapshot.go:142","msg":"fetched snapshot","endpoint":"https://192.168.31.95:2379","size":"20 MB","took":0.419497734} {"level":"info","ts":1643265636.4020233,"caller":"snapshot/v3_snapshot.go:152","msg":"saved","path":"test.db"} Snapshot saved at test.db ``` ## 获取给定文件的后端快照状态 ```shell etcdctl --cacert /data/etcd/certs/ca.pem --cert /data/etcd/certs/etcd.pem --key /data/etcd/certs/etcd-key.pem --endpoints=https://192.168.31.95:2379,https://192.168.31.78:2379,https://192.168.31.253:2379 -w table snapshot status test.db +----------+----------+------------+------------+ | HASH | REVISION | TOTAL KEYS | TOTAL SIZE | +----------+----------+------------+------------+ | 799dfde1 | 5828796 | 2250 | 20 MB | +----------+----------+------------+------------+ ``` ## 查看所有的key ```shell etcdctl --cacert /data/etcd/certs/ca.pem --cert /data/etcd/certs/etcd.pem --key /data/etcd/certs/etcd-key.pem --endpoints=https://192.168.31.95:2379,https://192.168.31.78:2379,https://192.168.31.253:2379 get / --prefix --keys-only ``` ## 查看value 由于k8s的etcd数据为了性能考虑,k8s默认etcd中的数据是通过protobuf格式存储,直接get key看到是乱码情况 ```shell etcdctl --cacert /data/etcd/certs/ca.pem --cert /data/etcd/certs/etcd.pem --key /data/etcd/certs/etcd-key.pem --endpoints=https://192.168.31.95:2379,https://192.168.31.78:2379,https://192.168.31.253:2379 get /registry/services/endpoints/default/kubernetes /registry/services/endpoints/default/kubernetes k8s v1 Endpoints kubernetesdefault"*$00231595-b1a8-468d-9ada-b6f2619fa0b52z ++be-a-i_e_+e_U-da+e+Fie+d_V1: {"f:_+b_e+_":{}}9  192.168.31.103  192.168.31.79 httpsTCP" ``` openshift项目已经开发了一个强大的辅助工具etcdhelper可以读取etcd内容并解码protobuf,请参考 https://github.com/openshift/origin/tree/master/tools/etcdhelper 项目编译安装。 > 下面提供了附件放在百度云上,下载好可以直接使用。 etcdhelper 连接 etcd 参数 ```shell $ etcdhelper -h Usage of etcdhelper: -cacert string Server TLS CA certificate. -cert string TLS client certificate. -endpoint string etcd endpoint. (default "https://127.0.0.1:2379") -key string TLS client key. ``` > 注意:endpoint执行写一个etcd节点即可,不能写多个。 命令使用的方法 ```shell etcdhelper dump 备份数据 ls [<key>] 查看key路径 get <key> 查看value内容 ``` 查看 etcd 记录k8s中 endpoints 资源的 kubernetes 详情信息 ```shell # 由于etcdctl的命令需要添加很多认证参数和endpoints的参数,因此可以使用别名的方式来简化命令。 $ echo 'alias etcdhelper="etcdhelper -endpoint https://192.168.31.95:2379 -cacert /data/etcd/certs/ca.pem -cert /data/etcd/certs/etcd.pem -key /data/etcd/certs/etcd-key.pem"' >> ~/.bashrc $ etcdhelper get /registry/services/endpoints/default/kubernetes /v1, Kind=Endpoints { "kind": "Endpoints", "apiVersion": "v1", "metadata": { "name": "kubernetes", "namespace": "default", "uid": "00231595-b1a8-468d-9ada-b6f2619fa0b5", "creationTimestamp": "2021-09-06T07:47:46Z", "managedFields": [ { "manager": "kube-apiserver", "operation": "Update", "apiVersion": "v1", "time": "2021-09-06T07:47:46Z", "fieldsType": "FieldsV1", "fieldsV1": {"f:subsets":{}} } ] }, "subsets": [ { "addresses": [ { "ip": "192.168.31.103" }, { "ip": "192.168.31.79" } ], "ports": [ { "name": "https", "port": 6443, "protocol": "TCP" } ] } ] } ``` ## 附件 链接:https://pan.baidu.com/s/1yL3ZUtZgSnoooAau69U48w 提取码:1u4e