kubeadm 搭建K8S 1.18集群--配置etcdctl

2021-07-01 18:09:27 浏览数 (1)

1.最好在所有的master节点上执行 docker cp docker ps -a | awk ‘/k8s_etcd/{print $1}’:/usr/local/bin/etcdctl /usr/local/bin/etcdctl

2.配置etcd参数

代码语言:javascript复制
#注意修改ETCD节点ip
cat >/etc/profile.d/etcd.sh<<'EOF'
ETCD_CERET_DIR=/etc/kubernetes/pki/etcd/
ETCD_CA_FILE=ca.crt
ETCD_KEY_FILE=healthcheck-client.key
ETCD_CERT_FILE=healthcheck-client.crt
ETCD_EP=https://192.168.31.100:2379,https://192.168.31.101:2379,https://192.168.31.102:2379
alias etcd_v2="etcdctl --cert-file ${ETCD_CERET_DIR}/${ETCD_CERT_FILE} 
              --key-file ${ETCD_CERET_DIR}/${ETCD_KEY_FILE}  
              --ca-file ${ETCD_CERET_DIR}/${ETCD_CA_FILE}  
              --endpoints $ETCD_EP"
alias etcd_v3="ETCDCTL_API=3 
    etcdctl   
   --cert ${ETCD_CERET_DIR}/${ETCD_CERT_FILE} 
   --key ${ETCD_CERET_DIR}/${ETCD_KEY_FILE} 
   --cacert ${ETCD_CERET_DIR}/${ETCD_CA_FILE} 
    --endpoints $ETCD_EP"
EOF

3.手动加载一下环境变量,如果需要多个master查看,那么将脚本分发到多个节点即可

代码语言:javascript复制
[root@k8s-01 ~]# . /etc/profile.d/etcd.sh
[root@k8s-01 ~]# etcd_v3 endpoint status --write-out=table  #下面是输出
 ----------------------------- ------------------ --------- --------- ----------- ------------ ----------- ------------ -------------------- -------- 
|          ENDPOINT           |        ID        | VERSION | DB SIZE | IS LEADER | IS LEARNER | RAFT TERM | RAFT INDEX | RAFT APPLIED INDEX | ERRORS |
 ----------------------------- ------------------ --------- --------- ----------- ------------ ----------- ------------ -------------------- -------- 
| https://192.168.31.100:2379 |   c95fd6fdbb91a5 |   3.4.7 |  2.4 MB |     false |      false |         6 |       5656 |               5656 |        |
| https://192.168.31.101:2379 | cfee13793e1cc392 |   3.4.7 |  2.3 MB |      true |      false |         6 |       5656 |               5656 |        |
| https://192.168.31.102:2379 | c9662d268621483c |   3.4.7 |  2.3 MB |     false |      false |         6 |       5656 |               5656 |        |
 ----------------------------- ------------------ --------- --------- ----------- ------------ ----------- ------------ -------------------- -------- 

0 人点赞