本次etcd增加节点背景: rpm方式安装的etcd单节点,再增加一个etcd节点

    操作如下:

1.先在已经安装的etcd上操作加入节点

新加入的节点状态为:unstarted,待节点etcd服务启动正常,etcd中的信息也会补充完整

[root@k8s1-1 ~]#  export ETCDCTL_API=3
[root@k8s1-1 ~]# etcdctl member list
362b84762ea9a455, started, etcd0, http://192.168.191.20:2380, http://192.168.191.20:2379
[root@k8s1-1 ~]# etcdctl member list -w table
+------------------+---------+-------+----------------------------+----------------------------+
|        ID        | STATUS  | NAME  |         PEER ADDRS         |        CLIENT ADDRS        |
+------------------+---------+-------+----------------------------+----------------------------+
| 362b84762ea9a455 | started | etcd0 | http://192.168.191.20:2380 | http://192.168.191.20:2379 |
+------------------+---------+-------+----------------------------+----------------------------+
[root@k8s1-1 ~]# etcdctl  member add etcd1  --peer-urls="http://192.168.191.21:2380"
Member d4d3abee9c372d84 added to cluster 3ba4906e88e142aa
ETCD_NAME="etcd1"
ETCD_INITIAL_CLUSTER="etcd0=http://192.168.191.20:2380,etcd1=http://192.168.191.21:2380"
ETCD_INITIAL_ADVERTISE_PEER_URLS="http://192.168.191.21:2380"
ETCD_INITIAL_CLUSTER_STATE="existing"

[root@k8s1-1 ~]# etcdctl member list -w table
+------------------+-----------+-------+----------------------------+----------------------------+
|        ID        |  STATUS   | NAME  |         PEER ADDRS         |        CLIENT ADDRS        |
+------------------+-----------+-------+----------------------------+----------------------------+
| 362b84762ea9a455 |   started | etcd0 | http://192.168.191.20:2380 | http://192.168.191.20:2379 |
| d4d3abee9c372d84 | unstarted |       | http://192.168.191.21:2380 |                            |
+------------------+-----------+-------+----------------------------+----------------------------+

2.新加入节点的etcd配置文件

[root@k8s2-1 ~]# cat /etc/etcd/etcd.conf  | grep -Ev '^$|#'
ETCD_DATA_DIR="/var/lib/etcd/default.etcd"
ETCD_LISTEN_PEER_URLS="http://0.0.0.0:2380"
ETCD_LISTEN_CLIENT_URLS="http://0.0.0.0:2379"
ETCD_NAME="etcd1"
ETCD_INITIAL_ADVERTISE_PEER_URLS="http://192.168.191.21:2380"
ETCD_ADVERTISE_CLIENT_URLS="http://192.168.191.21:2379"
ETCD_INITIAL_CLUSTER="etcd0=http://192.168.191.20:2380,etcd1=http://192.168.191.21:2380"
ETCD_INITIAL_CLUSTER_TOKEN="etcd-cluster"
ETCD_INITIAL_CLUSTER_STATE="existing"

    启动etcd服务

3.查看etcd0节点上的mem信息

[root@k8s1-1 ~]# etcdctl member list -w table

+------------------+---------+-------+----------------------------+----------------------------+
|        ID        | STATUS  | NAME  |         PEER ADDRS         |        CLIENT ADDRS        |
+------------------+---------+-------+----------------------------+----------------------------+
| 362b84762ea9a455 | started | etcd0 | http://192.168.191.20:2380 | http://192.168.191.20:2379 |
| d4d3abee9c372d84 | started | etcd1 | http://192.168.191.21:2380 | http://192.168.191.21:2379 |
+------------------+---------+-------+----------------------------+----------------------------+

修改etcd0节点中的集群ip信息

[root@k8s1-1 ~]# grep -Ev '#|^$' /etc/etcd/etcd.conf
ETCD_DATA_DIR="/var/lib/etcd/default.etcd"
ETCD_LISTEN_PEER_URLS="http://0.0.0.0:2380"
ETCD_LISTEN_CLIENT_URLS="http://localhost:2379,http://192.168.191.20:2379"
ETCD_NAME="etcd0"
ETCD_INITIAL_ADVERTISE_PEER_URLS="http://192.168.191.20:2380"
ETCD_ADVERTISE_CLIENT_URLS="http://192.168.191.20:2379"
ETCD_INITIAL_CLUSTER="etcd0=http://192.168.191.20:2380,etcd1=http://192.168.191.21:2380"    #etcd1新加入的配置
ETCD_INITIAL_CLUSTER_TOKEN="etcd-cluster"

启动etcdo节点的服务

不要忘记修改apiservice中的etcd-server集群ip执行添加即可:http://xxx.xxx.xxx.xxx:2380