1、etcd4 基础环境初始化(参考之前的文章etcd搭建)
https://blog.csdn.net/a13568hki/article/details/123581346
2、etcd集群中新增etcd4 的hosts解析,如果是dns域名提前配置,保证4台机器的地址信息可以正常解析
环境

k8s-master110.0.19.127etcd-1
k8s-node110.0.19.129etcd-2
k8s-node210.0.19.130etcd-3
k8s-node310.0.19.128etcd-4(新增)

一、重新申请证书,填写表单,增加新的etcd的IP地址

cd /root/TLS/etcd/
[root@k8s-master1 etcd]# cat ca-config.json 
{
  "signing": {
    "default": {
      "expiry": "87600h"
    },
    "profiles": {
      "www": {
         "expiry": "87600h",
         "usages": [
            "signing",
            "key encipherment",
            "server auth",
            "client auth"
        ]
      }
    }
  }
}
[root@k8s-master1 etcd]# cat ca-csr.json 
{
    "CN": "etcd CA",
    "key": {
        "algo": "rsa",
        "size": 2048
    },
    "names": [
        {
            "C": "CN",
            "L": "Beijing",
            "ST": "Beijing"
        }
    ]
}
[root@k8s-master1 etcd]# cat server-csr.json 
{
    "CN": "etcd",
    "hosts": [
        "10.0.19.127",
        "10.0.19.128",
        "10.0.19.129",
        "10.0.19.130",
        "10.0.19.131"
        ],
    "key": {
        "algo": "rsa",
        "size": 2048
    },
    "names": [
        {
            "C": "CN",
            "L": "BeiJing",
            "ST": "BeiJing"
        }
    ]
}

server-csr.json 里的hosts填写etcd的ip地址可以多写但是不能少写
向证书颁发机构申请证书

[root@k8s-master1 etcd]# cfssl gencert -initca ca-csr.json | cfssljson -bare ca -
[root@k8s-master1 etcd]# cfssl gencert -ca=ca.pem -ca-key=ca-key.pem -config=ca-config.json -profile=www server-csr.json | cfssljson -bare server
[root@k8s-master1 etcd]# ls *pem
ca-key.pem  ca.pem  server-key.pem  server.pem

4、覆盖ssl证书并重启etcd和kube-apiserver

cp /root/TLS/etcd/{ca.pem,server.pem,server-key.pem} /opt/etcd/ssl/ #拷贝etcd的证书
scp -r /opt/etcd/ssl/* k8s-node1:/opt/etcd/ssl/
scp -r /opt/etcd/ssl/* k8s-node2:/opt/etcd/ssl/
systemctl restart etcd
systemctl restart kube-apiserver

二、加入新增加etcd4节点

命令行增加etcd4
添加新节点

#add 增加新节点
[root@k8s-master1 etcd]# ETCDCTL_API=3 /opt/etcd/bin/etcdctl --cacert=/opt/etcd/ssl/ca.pem --cert=/opt/etcd/ssl/server.pem --key=/opt/etcd/ssl/server-key.pem --endpoints="https://10.0.19.127:2379" member add etcd-4 --peer-urls=https://10.0.19.128:2380
Member 1e1a799fc9c59a7b added to cluster 983f3fe4681bf439

ETCD_NAME="etcd-4"
ETCD_INITIAL_CLUSTER="etcd-2=https://10.0.19.129:2380,etcd-4=https://10.0.19.128:2380,etcd-1=https://10.0.19.127:2380,etcd-3=https://10.0.19.130:2380"
ETCD_INITIAL_ADVERTISE_PEER_URLS="https://10.0.19.128:2380"
ETCD_INITIAL_CLUSTER_STATE="existing"
#list  查看节点状态
[root@k8s-master1 etcd]#  ETCDCTL_API=3 /opt/etcd/bin/etcdctl --cacert=/opt/etcd/ssl/ca.pem --cert=/opt/etcd/ssl/server.pem --key=/opt/etcd/ssl/server-key.pem --endpoints="https://10.0.19.127:2379" member list --write-out=table
+------------------+-----------+--------+--------------------------+--------------------------+
|        ID        |  STATUS   |  NAME  |        PEER ADDRS        |       CLIENT ADDRS       |
+------------------+-----------+--------+--------------------------+--------------------------+
|   db5a2c24a8bf7a |   started | etcd-2 | https://10.0.19.129:2380 | https://10.0.19.129:2379 |
| 1e1a799fc9c59a7b | unstarted |        | https://10.0.19.128:2380 |                          |
| 318ff80236db7a1e |   started | etcd-1 | https://10.0.19.127:2380 | https://10.0.19.127:2379 |
| ee6138446f578296 |   started | etcd-3 | https://10.0.19.130:2380 | https://10.0.19.130:2379 |
+------------------+-----------+--------+--------------------------+--------------------------+

4、可以看到上面已经增加节点但是并未启动,接下来启动,首先etcd4 的etcd.conf配置中参照上面配置更新替换,同时拷贝 /opt/etcd的安装包
拷贝软件包给新节点

[root@k8s-master1 etcd]# scp -r /opt/etcd/ k8s-node4:/opt/
[root@k8s-master1 ~]# scp /usr/lib/systemd/system/etcd.service root@k8s-node4:/usr/lib/systemd/system/

登录新增节点修改配置

[root@k8s-node4 ~]# cat /opt/etcd/cfg/etcd.conf   
#[Member]
ETCD_NAME="etcd-4"
ETCD_DATA_DIR="/var/lib/etcd/default.etcd"
ETCD_LISTEN_PEER_URLS="https://10.0.19.128:2380"
ETCD_LISTEN_CLIENT_URLS="https://10.0.19.128:2379"

#[Clustering]
ETCD_INITIAL_ADVERTISE_PEER_URLS="https://10.0.19.128:2380"
ETCD_ADVERTISE_CLIENT_URLS="https://10.0.19.128:2379"
ETCD_INITIAL_CLUSTER="etcd-2=https://10.0.19.129:2380,etcd-4=https://10.0.19.128:2380,etcd-1=https://10.0.19.127:2380,etcd-3=https://10.0.19.130:2380"
ETCD_INITIAL_CLUSTER_TOKEN="etcd-cluster"
ETCD_INITIAL_CLUSTER_STATE="existing"

启动etcd4,查看集群状态

[root@k8s-node4 ~]# systemctl daemon-reload
[root@k8s-node4 ~]#  systemctl restart etcd
[root@k8s-node4 ~]# ETCDCTL_API=3 /opt/etcd/bin/etcdctl --cacert=/opt/etcd/ssl/ca.pem --cert=/opt/etcd/ssl/server.pem --key=/opt/etcd/ssl/server-key.pem --endpoints="https://10.0.19.128:2379" member list --write-out=table
+------------------+---------+--------+--------------------------+--------------------------+
|        ID        | STATUS  |  NAME  |        PEER ADDRS        |       CLIENT ADDRS       |
+------------------+---------+--------+--------------------------+--------------------------+
|   db5a2c24a8bf7a | started | etcd-2 | https://10.0.19.129:2380 | https://10.0.19.129:2379 |
| 1e1a799fc9c59a7b | started | etcd-4 | https://10.0.19.128:2380 | https://10.0.19.128:2379 |
| 318ff80236db7a1e | started | etcd-1 | https://10.0.19.127:2380 | https://10.0.19.127:2379 |
| ee6138446f578296 | started | etcd-3 | https://10.0.19.130:2380 | https://10.0.19.130:2379 |
+------------------+---------+--------+--------------------------+--------------------------+

5、修改所有etcd配置并重

[root@k8s-master1 etcd]# cat /opt/etcd/cfg/etcd.conf|grep ETCD_INITIAL_CLUSTER
ETCD_INITIAL_CLUSTER="etcd-2=https://10.0.19.129:2380,etcd-4=https://10.0.19.128:2380,etcd-1=https://10.0.19.127:2380,etcd-3=https://10.0.19.130:2380"
[root@k8s-master1 etcd]#  systemctl restart etcd
[root@k8s-master1 ~]# /opt/etcd/bin/etcdctl --ca-file=/opt/etcd/ssl/ca.pem --cert-file=/opt/etcd/ssl/server.pem --key-file=/opt/etcd/ssl/server-key.pem --endpoints="https://10.0.19.127:2379,https://10.0.19.129:2379,https://10.0.19.130:2379" cluster-health
member db5a2c24a8bf7a is healthy: got healthy result from https://10.0.19.129:2379
member 1e1a799fc9c59a7b is healthy: got healthy result from https://10.0.19.128:2379
member 318ff80236db7a1e is healthy: got healthy result from https://10.0.19.127:2379
member ee6138446f578296 is healthy: got healthy result from https://10.0.19.130:2379
cluster is healthy

etcd扩容成功,需要把它配置到k8s

三、修改kube-apiserver服务连接的etcd地址重启

[root@k8s-master1 etcd]# cat /opt/kubernetes/cfg/*|grep 2379
--etcd-servers=https://10.0.19.127:2379,https://10.0.19.128:2379,https://10.0.19.129:2379,https://10.0.19.130:2379 \
[root@k8s-master1 etcd]# systemctl restart kube-apiserver
Logo

K8S/Kubernetes社区为您提供最前沿的新闻资讯和知识内容

更多推荐