关于kubernetes:查看k8s中etcd集群的状态

34次阅读

共计 2523 个字符,预计需要花费 7 分钟才能阅读完成。

1 下载安装 etcdctl 客户端命令工具

1.1 应用脚本下载与服务端雷同版本的 etcdctl 软件包

[shutang@centos03.com etcd]$ pwd
/home/shutang/k8s/etcd
[shutang@centos03.com etcd]$ ls
download.sh
[shutang@centos03.com etcd]$ cat download.sh
#!/bin/bash
ETCD_VER=v3.4.3
ETCD_DIR=etcd-download
DOWNLOAD_URL=https://github.com/coreos/etcd/releases/download

# Download
mkdir ${ETCD_DIR}
cd ${ETCD_DIR}
wget ${DOWNLOAD_URL}/${ETCD_VER}/etcd-${ETCD_VER}-linux-amd64.tar.gz
tar -xzvf etcd-${ETCD_VER}-linux-amd64.tar.gz

# install
cd etcd-${ETCD_VER}-linux-amd64
cp etcdctl /usr/local/bin/

1.2 执行脚本,而后配置环境变量和别名

[shutang@centos03.com etcd] bash download.sh

# 创立该文件
[shutang@centos03.com profile.d]$ cat etcd.sh
export ETCDCTL_API=3
alias etcdctl='etcdctl --endpoints=https://centos01.com:2379,https://centos02.com:2379,https://centos03.com:2379 --cacert=/etc/kubernetes/pki/etcd/ca.crt --cert=/etc/kubernetes/pki/etcd/server.crt --key=/etc/kubernetes/pki/etcd/server.key'

[shutang@centos03.com profile.d]$ source etcd.sh
# 这里须要留神要保障两个证书文件和一个私钥文件具备可读权限,以便普通用户能够应用 etcdctl 命令 

2 普通用户能够应用 etcdctl 命令

2.1 查看 etcd 集群成员列表

[shutang@centos03.com profile.d]$ etcdctl member list
fw57bbcfbe9bc95, started, centos03.com, https://192.168.0.100:2380, https://192.168.0.100:2379, false
ds8968b39130b7a, started, centos02.com, https://192.168.0.101:2380, https://192.168.0.101:2379, false
fs663af9b5wfr85, started, centos01.com, https://192.168.0.102:2380, https://192.168.0.102:2379, false

2.2 查看 endpoints 状态

[shutang@centos03.com profile.d]$ etcdctl endpoint status --write-out=table
+------------------------------+------------------+---------+---------+-----------+------------+-----------+------------+--------------------+--------+
|           ENDPOINT           |        ID        | VERSION | DB SIZE | IS LEADER | IS LEARNER | RAFT TERM | RAFT INDEX | RAFT APPLIED INDEX | ERRORS |
+------------------------------+------------------+---------+---------+-----------+------------+-----------+------------+--------------------+--------+
| https://centos03.com:2379 |  fw57bbcfbe9bc95 |   3.4.3 |   36 MB |      true |      false |         4 |    8387884 |            8387884 |        |
| https://centos03.com:2379 | ds8968b39130b7a |   3.4.3 |   36 MB |     false |      false |         4 |    8387884 |            8387884 |        |
| https://centos03.com:2379 |  fs663af9b5wfr85 |   3.4.3 |   36 MB |     false |      false |         4 |    8387884 |            8387884 |        |
+------------------------------+------------------+---------+---------+-----------+------------+-----------+------------+--------------------+--------+

2.3 查看 etcd endpoints 的衰弱

[shutang@centos03.com profile.d]$ etcdctl endpoint health
https://centos03.com:2379 is healthy: successfully committed proposal: took = 12.253777ms
https://centos02.com:2379 is healthy: successfully committed proposal: took = 13.902653ms
https://centos01.com:2379 is healthy: successfully committed proposal: took = 15.32191ms

正文完
 0