etcd-集群

在前文的基础上做etcd集群
一般情况etcd用三节点集群,这里机器受限,用原来的1master+2node的环境基础修改为双etcd集群。主要是配置!
首先两台机器上都要安装etcd
yum install -y etcd
安装完成后就开始修改配置
1,两个机器修改etcd.conf
在192.168.1.5上vi /etc/etcd/etcd.conf

ETCD_DATA_DIR="/var/lib/etcd/etcd01"
ETCD_LISTEN_PEER_URLS="http://192.168.1.5:2380"
ETCD_LISTEN_CLIENT_URLS="http://192.168.1.5:2379,http://127.0.0.1:2379"
ETCD_NAME="etcd01"
ETCD_INITIAL_ADVERTISE_PEER_URLS="http://192.168.1.5:2380"
ETCD_ADVERTISE_CLIENT_URLS="http://192.168.1.5:2379,http://127.0.0.1:2379"
ETCD_INITIAL_CLUSTER="etcd01=http://192.168.1.5:2380,etcd02=http://192.168.1.6:2380"
ETCD_INITIAL_CLUSTER_TOKEN="etcd-cluster"
ETCD_INITIAL_CLUSTER_STATE="new"

在192.168.1.6上vi /etc/etcd/etcd.conf

ETCD_DATA_DIR="/var/lib/etcd/etcd02"
ETCD_LISTEN_PEER_URLS="http://192.168.1.6:2380"
ETCD_LISTEN_CLIENT_URLS="http://192.168.1.6:2379,http://127.0.0.1:2379"
ETCD_NAME="etcd02"
ETCD_INITIAL_ADVERTISE_PEER_URLS="http://192.168.1.6:2380"
ETCD_ADVERTISE_CLIENT_URLS="http://192.168.1.6:2379,http://127.0.0.1:2379"
ETCD_INITIAL_CLUSTER="etcd01=http://192.168.1.5:2380,etcd02=http://192.168.1.6:2380"
ETCD_INITIAL_CLUSTER_TOKEN="etcd-cluster"
ETCD_INITIAL_CLUSTER_STATE="new"

要点解析:
ETCD_DATA_DIR="/var/lib/etcd/etcd01" #节点存储etcd01目录,自行创建
ETCD_LISTEN_PEER_URLS="http://192.168.1.5:2380" #监听URL,用于节点之间通讯
ETCD_LISTEN_CLIENT_URLS="http://192.168.1.5:2379,http://127.0.0.1:2379
#对外提供服务的地址:比如 http://ip:2379,http://127.0.0.1:2379 ,客户端会连接到这里和 etcd 交互。
ETCD_NAME="etcd01" #etcd节点名字
ETCD_INITIAL_ADVERTISE_PEER_URLS="http://192.168.1.5:2380" #该节点同伴监听地址,这个值会告诉集群中其他节点
ETCD_ADVERTISE_CLIENT_URLS="http://192.168.1.5:2379,http://127.0.0.1:2379" #对外公告的该节点客户端监听地址,这个值会告诉集群中其他节点
ETCD_INITIAL_CLUSTER="etcd01=http://192.168.1.5:2380,etcd02=http://192.168.1.6:2380" #集群中所有节点的信息
ETCD_INITIAL_CLUSTER_TOKEN="etcd-cluster" #集群的token
ETCD_INITIAL_CLUSTER_STATE="new" #
另外127.0.0.1:2379这个地址很重要必须一并配置上。

2修改启动文件
vi /usr/lib/systemd/system/etcd.service

[Unit]
Description=Etcd Server
After=network.target
After=network-online.target
Wants=network-online.target
[Service]
Type=notify
WorkingDirectory=/var/lib/etcd/
EnvironmentFile=-/etc/etcd/etcd.conf
User=etcd
ExecStart=/bin/bash -c "GOMAXPROCS=$(nproc) /usr/bin/etcd --name=\"${ETCD_NAME}\" --data-dir=\"${ETCD_DATA_DIR}\" --listen-client-urls=\"${ETCD_LISTEN_CLIENT_URLS}\" --listen-peer-urls=\"${ETCD_LISTEN_PEER_URLS}\" --advertise-client-urls=\"${ETCD_ADVERTISE_CLIENT_URLS}\" --initial-cluster-token=\"${ETCD_INITIAL_CLUSTER_TOKEN}\" --initial-cluster=\"${ETCD_INITIAL_CLUSTER}\" --initial-cluster-state=\"${ETCD_INITIAL_CLUSTER_STATE}\" "
Restart=on-failure
LimitNOFILE=65536
[Install]
WantedBy=multi-user.target

要把配置文件的内容添加到启动选项ExecStart中

3.修改flannel网络

cat /etc/sysconfig/flanneld 
FLANNEL_ETCD_ENDPOINTS="http://192.168.1.5:2379,http://192.168.1.6:2379"
FLANNEL_ETCD_PREFIX="/atomic.io/network"
#FLANNEL_OPTIONS=""

添加所有endpoint地址

4.修改master的apiserver的配置

KUBE_ETCD_SERVERS="--etcd-servers=http://192.168.1.5:2379,192.168.1.6:2379"

5重启服务
systemctl daemon-reload
systemctl enable etcd.service
systemctl start etcd.service

for SERVICES in etcd kube-apiserver kube-controller-manager kube-scheduler; do systemctl restart $SERVICES;done

6,重新定义网路

kubectl get pods --all-namespaces -o wide
kubectl get svc --all-namespaces -o wide

.在etcd中定义flannel网络
etcdctl mk /atomic.io/network/config '{"Network":"172.17.0.0/16"}'

分别重启两个机器的node服务

etcdctl member list 查看集群状态
[root@k8s-master home]# etcdctl member list
50bd23ff02a14a31: name=etcd02 peerURLs=http://192.168.1.6:2380 clientURLs=http://127.0.0.1:2379,http://192.168.1.6:2379 isLeader=false
c59bcebe80c5afdb: name=etcd01 peerURLs=http://192.168.1.5:2380 clientURLs=http://127.0.0.1:2379,http://192.168.1.5:2379 isLeader=true















本文转自super李导51CTO博客,原文链接:http://blog.51cto.com/superleedo/2054944 ,如需转载请自行联系原作者



上一篇:SOA分析设计过程


下一篇:使用 kubeadm 创建 kubernetes 1.9 集群