–
当前etcd集群3个节点,需要添加一个新节点
添加集群节点对应hosts文件解析,四个节点都要添加
[root@k8s-test-1 ~]#cat /etc/hosts 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6 10.216.4.14 k8s-test-1 kd1 10.216.4.15 k8s-test-2 kd2 10.216.4.131 k8s-test-3 kd3 10.216.4.133 k8s-test-4 kd4
查看当前集群节点信息
[root@k8s-test-1 ~]#echo ${ETCD_ENDPOINTS} https://10.216.4.14:2379,https://10.216.4.15:2379,https://10.216.4.131:2379
查看哪个是主
[root@k8s-test-1 ~]#source /opt/k8s/bin/environment.sh ETCDCTL_API=3 /opt/k8s/bin/etcdctl \ --cacert=/opt/k8s/work/ca.pem \ --cert=/etc/etcd/cert/etcd.pem \ --key=/etc/etcd/cert/etcd-key.pem \ --endpoints=${ETCD_ENDPOINTS} endpoint status -w table +---------------------------+------------------+---------+---------+-----------+-----------+------------+ | ENDPOINT | ID | VERSION | DB SIZE | IS LEADER | RAFT TERM | RAFT INDEX | +---------------------------+------------------+---------+---------+-----------+-----------+------------+ | https://10.216.4.14:2379 | 2f763843250a81d5 | 3.3.10 | 1.0 GB | false | 3337 | 142362718 | | https://10.216.4.15:2379 | 629ea6abbc1a7568 | 3.3.10 | 1.0 GB | false | 3337 | 142362718 | | https://10.216.4.131:2379 | 9642036ea2eae87f | 3.3.10 | 1.0 GB | true | 3337 | 142362718 | +---------------------------+------------------+---------+---------+-----------+-----------+------------+
查看id
[root@k8s-test-1 ~]#source /opt/k8s/bin/environment.sh ETCDCTL_API=3 /opt/k8s/bin/etcdctl \ --cacert=/opt/k8s/work/ca.pem \ --cert=/etc/etcd/cert/etcd.pem \ --key=/etc/etcd/cert/etcd-key.pem \ --endpoints=${ETCD_ENDPOINTS} member list -w table +------------------+---------+------------+---------------------------+---------------------------+ | ID | STATUS | NAME | PEER ADDRS | CLIENT ADDRS | +------------------+---------+------------+---------------------------+---------------------------+ | 2f763843250a81d5 | started | k8s-test-1 | https://10.216.4.14:2380 | https://10.216.4.14:2379 | | 629ea6abbc1a7568 | started | k8s-test-2 | https://10.216.4.15:2380 | https://10.216.4.15:2379 | | 9642036ea2eae87f | started | k8s-test-3 | https://10.216.4.131:2380 | https://10.216.4.131:2379 | +------------------+---------+------------+---------------------------+---------------------------+
添加,注意参数少些,如果需要添加多个,只能一个添加,启动后。才能添加另一个
[root@k8s-test-1 ~]#source /opt/k8s/bin/environment.sh ETCDCTL_API=3 /opt/k8s/bin/etcdctl \ --cacert=/opt/k8s/work/ca.pem \ --cert=/etc/etcd/cert/etcd.pem \ --key=/etc/etcd/cert/etcd-key.pem \ --endpoints=${ETCD_ENDPOINTS} member add k8s-test-4 --peer-urls="https://10.216.4.133:2380" Member 242fd1a3042c7a82 added to cluster 5a2ad62d6bc1850f ETCD_NAME="k8s-test-4" ETCD_INITIAL_CLUSTER="k8s-test-4=https://10.216.4.133:2380,k8s-test-1=https://10.216.4.14:2380,k8s-test-2=https://10.216.4.15:2380,k8s-test-3=https://10.216.4.131:2380" ETCD_INITIAL_ADVERTISE_PEER_URLS="https://10.216.4.133:2380" ETCD_INITIAL_CLUSTER_STATE="existing"
查看结果
[root@k8s-test-1 ~]#source /opt/k8s/bin/environment.sh ETCDCTL_API=3 /opt/k8s/bin/etcdctl \ --cacert=/opt/k8s/work/ca.pem \ --cert=/etc/etcd/cert/etcd.pem \ --key=/etc/etcd/cert/etcd-key.pem \ --endpoints=${ETCD_ENDPOINTS} member list -w table +------------------+-----------+------------+---------------------------+---------------------------+ | ID | STATUS | NAME | PEER ADDRS | CLIENT ADDRS | +------------------+-----------+------------+---------------------------+---------------------------+ | 242fd1a3042c7a82 | unstarted | | https://10.216.4.133:2380 | | | 2f763843250a81d5 | started | k8s-test-1 | https://10.216.4.14:2380 | https://10.216.4.14:2379 | | 629ea6abbc1a7568 | started | k8s-test-2 | https://10.216.4.15:2380 | https://10.216.4.15:2379 | | 9642036ea2eae87f | started | k8s-test-3 | https://10.216.4.131:2380 | https://10.216.4.131:2379 | +------------------+-----------+------------+---------------------------+---------------------------+
将kd1上证书文件和systemd文件拷贝到kd4上对应位置
重新生成证书,证书中添加kd4对应的ip,将证书同步到4个节点,并重启前3个节点的etcd
kd4上操作
创建数据目录
[root@k8s-test-4 ~]#source /opt/k8s/bin/environment.sh [root@k8s-test-4 ~]#echo ${ETCD_DATA_DIR} ${ETCD_WAL_DIR} /data/k8s/etcd/data /data/k8s/etcd/wal [root@k8s-test-4 ~]#mkdir -vp ${ETCD_DATA_DIR} ${ETCD_WAL_DIR}
修改systemd 中new为existing,以及对应的hostname,ip
[root@k8s-test-4 /data/k8s/etcd]#cat /etc/systemd/system/etcd.service [Unit] Description=Etcd Server After=network.target After=network-online.target Wants=network-online.target Documentation=https://github.com/coreos [Service] Type=notify WorkingDirectory=/data/k8s/etcd/data ExecStart=/opt/k8s/bin/etcd \ --data-dir=/data/k8s/etcd/data \ --wal-dir=/data/k8s/etcd/wal \ --name=k8s-test-4 \ --cert-file=/etc/etcd/cert/etcd.pem \ --key-file=/etc/etcd/cert/etcd-key.pem \ --trusted-ca-file=/etc/kubernetes/cert/ca.pem \ --peer-cert-file=/etc/etcd/cert/etcd.pem \ --peer-key-file=/etc/etcd/cert/etcd-key.pem \ --peer-trusted-ca-file=/etc/kubernetes/cert/ca.pem \ --peer-client-cert-auth \ --client-cert-auth \ --listen-peer-urls=https://10.216.4.133:2380 \ --initial-advertise-peer-urls=https://10.216.4.133:2380 \ --listen-client-urls=https://10.216.4.133:2379,http://127.0.0.1:2379 \ --advertise-client-urls=https://10.216.4.133:2379 \ --initial-cluster-token=etcd-cluster-0 \ --initial-cluster=k8s-test-1=https://10.216.4.14:2380,k8s-test-2=https://10.216.4.15:2380,k8s-test-3=https://10.216.4.131:2380,k8s-test-4=https://10.216.4.133:2380 \ --initial-cluster-state=existing \ --auto-compaction-mode=periodic \ --auto-compaction-retention=1 \ --max-request-bytes=33554432 \ --quota-backend-bytes=6442450944 \ --heartbeat-interval=250 \ --election-timeout=2000 Restart=on-failure RestartSec=5 LimitNOFILE=65536 [Install] WantedBy=multi-user.target
启动服务
systemctl daemon-reload && systemctl enable etcd && systemctl restart etcd && systemctl status etcd
查看mem,默认显示3个,加–cluster显示所有
[root@k8s-test-1 ~]#source /opt/k8s/bin/environment.sh ETCDCTL_API=3 /opt/k8s/bin/etcdctl \ --cacert=/opt/k8s/work/ca.pem \ --cert=/etc/etcd/cert/etcd.pem \ --key=/etc/etcd/cert/etcd-key.pem \ --endpoints=${ETCD_ENDPOINTS} endpoint status -w table --cluster +---------------------------+------------------+---------+---------+-----------+-----------+------------+ | ENDPOINT | ID | VERSION | DB SIZE | IS LEADER | RAFT TERM | RAFT INDEX | +---------------------------+------------------+---------+---------+-----------+-----------+------------+ | https://10.216.4.14:2379 | 2f763843250a81d5 | 3.3.10 | 1.0 GB | true | 3352 | 142408685 | | https://10.216.4.15:2379 | 629ea6abbc1a7568 | 3.3.10 | 1.0 GB | false | 3352 | 142408685 | | https://10.216.4.131:2379 | 9642036ea2eae87f | 3.3.10 | 1.0 GB | false | 3352 | 142408685 | | https://10.216.4.133:2379 | f3873401a4dbc16a | 3.3.10 | 1.0 GB | false | 3352 | 142408685 | +---------------------------+------------------+---------+---------+-----------+-----------+------------+
将各节点添加到变量ETCD_INITIAL_CLUSTER添加新节点信息,然后依次重启。
–
–
评论前必须登录!
注册