k8s系列-14-部署Etcd集群
老板们,点个关注吧。
kubernetes各个组件都是无状态的服务,都存储在etcd中,为了保证集群的高可用,所以etcd也是需要高可用的。
copy证书
# 创建存放证书的目录
[root@node1 ~]# mkdir -pv /etc/etcd /var/lib/etcd
mkdir: 已创建目录 "/etc/etcd"
mkdir: 已创建目录 "/var/lib/etcd"
[root@node1 ~]#
# 授权相关目录为700的权限
[root@node1 ~]# chmod 700 /var/lib/etcd
[root@node1 ~]# ll /var/lib/ | grep etcd
drwx------ 2 root root 6 3月 18 22:36 etcd
[root@node1 ~]#
# 拷贝证书
[root@node1 ~]# pwd
/root
[root@node1 ~]# cp ca.pem kubernetes-key.pem kubernetes.pem /etc/etcd/
[root@node1 ~]# ls /etc/etcd/
ca.pem kubernetes-key.pem kubernetes.pem
[root@node1 ~]#
配置etcd启动文件
[ ]
[ ]
[ ]
[ ]
[ ]
[ ]
Description=etcd
Documentation=https://github.com/coreos
[ ]
Type=notify
ExecStart=/usr/local/bin/etcd \\
--name ${ETCD_NAME} \\
--cert-file=/etc/etcd/kubernetes.pem \\
--key-file=/etc/etcd/kubernetes-key.pem \\
--peer-cert-file=/etc/etcd/kubernetes.pem \\
--peer-key-file=/etc/etcd/kubernetes-key.pem \\
--trusted-ca-file=/etc/etcd/ca.pem \\
--peer-trusted-ca-file=/etc/etcd/ca.pem \\
--peer-client-cert-auth \\
--client-cert-auth \\
--initial-advertise-peer-urls https://${ETCD_IP}:2380 \\
--listen-peer-urls https://${ETCD_IP}:2380 \\
--listen-client-urls https://${ETCD_IP}:2379,https://127.0.0.1:2379 \\
--advertise-client-urls https://${ETCD_IP}:2379 \\
--initial-cluster-token etcd-cluster-0 \\
--initial-cluster ${ETCD_NAMES[0]}=https://${ETCD_IPS[0]}:2380,${ETCD_NAMES[1]}=https://${ETCD_IPS[1]}:2380,${ETCD_NAMES[2]}=https://${ETCD_IPS[2]}:2380 \\
--initial-cluster-state new \\
--data-dir=/var/lib/etcd
Restart=on-failure
RestartSec=5
[ ]
WantedBy=multi-user.target
EOF
[ ]
启动ETCD服务
[ ]
[ ]
[ ]
[ ]
● etcd.service - etcd
Loaded: loaded (/etc/systemd/system/etcd.service; enabled; vendor preset: disabled)
Active: active (running) since 五 2022-03-18 22:56:00 CST; 1min 16s ago
Docs: https://github.com/coreos
Main PID: 3663 (etcd)
Tasks: 8
CGroup: /system.slice/etcd.service
└─3663 /usr/local/bin/etcd --name node1 --cert-file=/etc/etcd/kubernetes.pem --key-file=/etc/etcd/kubernetes-key.pem --peer-cert-file=/etc/etcd/kubernetes.pem...
3月 18 22:56:00 node1 systemd[1]: Started etcd.
3月 18 22:56:00 node1 etcd[3663]: health check for peer 2deb614427922fac could not connect: dial tcp 192.168.112.132:2380: connect: connection refused
3月 18 22:56:00 node1 etcd[3663]: health check for peer 2deb614427922fac could not connect: dial tcp 192.168.112.132:2380: connect: connection refused
3月 18 22:56:00 node1 etcd[3663]: peer 2deb614427922fac became active
3月 18 22:56:00 node1 etcd[3663]: established a TCP streaming connection with peer 2deb614427922fac (stream MsgApp v2 writer)
3月 18 22:56:00 node1 etcd[3663]: established a TCP streaming connection with peer 2deb614427922fac (stream Message writer)
3月 18 22:56:00 node1 etcd[3663]: established a TCP streaming connection with peer 2deb614427922fac (stream Message reader)
3月 18 22:56:00 node1 etcd[3663]: established a TCP streaming connection with peer 2deb614427922fac (stream MsgApp v2 reader)
3月 18 22:56:04 node1 etcd[3663]: updated the cluster version from 3.0 to 3.4
3月 18 22:56:04 node1 etcd[3663]: enabled capabilities for version 3.4
[ ]
验证etcd集群
# 输入命令
[root@node1 ~]# ETCDCTL_API=3 etcdctl member list \
--endpoints=https://127.0.0.1:2379 \
--cacert=/etc/etcd/ca.pem \
--cert=/etc/etcd/kubernetes.pem \
--key=/etc/etcd/kubernetes-key.pem
# 输出信息为:
2deb614427922fac, started, node3, https://192.168.112.132:2380, https://192.168.112.132:2379, false
a47c9892fd8a7e8a, started, node1, https://192.168.112.130:2380, https://192.168.112.130:2379, false
d884949f280137ba, started, node2, https://192.168.112.131:2380, https://192.168.112.131:2379, false
[root@node1 ~]#
至此,etcd高可用部署完毕,明天我们开始搭建worker节点上的服务。
往期推荐
添加关注,带你高效运维