k8s部署etcd集群

1、k8s部署高可用etcd集群时遇到了一些麻烦,这个是自己其中一个etcd的配置文件

例如:

[Unit]
Description=Etcd Server
After=network.target
After=network-online.target
Wants=network-online.target
Documentation=https://github.com/coreos


[Service]
User=k8s
Type=notify
WorkingDirectory=/var/lib/etcd/

ExecStart=/opt/k8s/bin/etcd \
  --data-dir=/var/lib/etcd \
  --name=ELK-chaofeng04 \
  --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://172.16.0.54:2380 \
  --initial-advertise-peer-urls=https://172.16.0.54:2380 \
  --listen-client-urls=https://172.16.0.54:2379,https://127.0.0.1:2379 \
  --advertise-client-urls=https://172.16.0.54:2379 \
  --initial-cluster-token=etcd-cluster-0 \
  --initial-cluster ELK-chaofeng04=https://172.16.0.54:2380,ELK-chaofeng05=https://172.16.0.55:2380,ELK-chaofeng06=https://172.16.0.56:2380 \
  --initial-cluster-state=new
Restart=on-failure
RestartSec=5
LimitNOFILE=65536

[Install]
WantedBy=multi-user.target

这只是其中的一个节点上的配置文件,其他的节点上的配置文件大同小异,只是IP和hostname主机名不同罢了。

2、在部署的过程中,不会发现这三个etcd的输出是这样子的:

第一个节点:

第二个节点:

第三个节点:

通过输出会觉得第一个节点和第三个节点时有问题的,但是其实是没有的。三个节点分别只要能看到绿色的“activing(running)”就表示是成功的,当然,还可以再一步进行如下的验证,说明etcd集群没有问题:

magic17.sh的脚本如下所示:

#!/bin/bash
source /opt/k8s/bin/environment.sh
for node_ip in ${NODE_IPS[@]}
do
    echo ">>> ${node_ip}" 
    ETCDCTL_API=3 /opt/k8s/bin/etcdctl \
    --endpoints=https://${node_ip}:2379 \
    --cacert=/etc/kubernetes/cert/ca.pem \
    --cert=/etc/etcd/cert/etcd.pem \
    --key=/etc/etcd/cert/etcd-key.pem endpoint health
done

猜你喜欢

转载自www.cnblogs.com/FengGeBlog/p/10810632.html