扫二维码与项目经理沟通
我们在微信上24小时期待你的声音
解答本文疑问/技术咨询/运营咨询/技术建议/互联网交流
etcd 是基于 Raft 的分布式 key-value 存储系统,由 CoreOS 开发,常用于服务发现、共享配置以及并发控制(如 leader 选举、分布式锁等)。kubernetes 使用 etcd 存储所有运行数据。
专业成都网站建设公司,做排名好的好网站,排在同行前面,为您带来客户和效益!创新互联建站为您提供成都网站建设,五站合一网站设计制作,服务好的网站设计公司,做网站、成都网站制作负责任的成都网站制作公司!
所有操作都是在devops机器上操作,将相关脚本编辑好,然后通过ansible 脚本模块统一执行。
#################### Variable parameter setting ######################
ETCD_INSTALL_PATH="/data/apps/k8s/etcd"
ETCD_BIN_DIR="${ETCD_INSTALL_PATH}/bin"
ETCD_DATA_DIR="${ETCD_INSTALL_PATH}/data"
ETCD_WAL_DIR="${ETCD_INSTALL_PATH}/wal"
N01="master-k8s-n01=https://10.10.10.22:2380"
N02="master-k8s-n02=https://10.10.10.23:2380"
N03="master-k8s-n03=https://10.10.10.24:2380"
ETCD_ENPOIDTS="$N01,$N02,$N03"
CA_PATH="/etc/k8s/ssl"
SOFTWARE="/root/software"
VERSION=v3.3.13
PACKAGE="etcd-${VERSION}-linux-amd64.tar.gz"
HOSTNAME=`hostname`
DOWNLOAD_URL="https://github.com/devops-apps/download/raw/master/etcd/${PACKAG}"
ETH_INTERFACE=eth2
LISTEN_IP=$(ifconfig | grep -A 1 ${ETH_INTERFACE} |grep inet |awk '{print $2}')
USER=k8s
登录devops访问etcd 的 release 页面下载最新版本的发布包并通过ansible同步到三个master三个节点/root/software目录下:
wget $DOWNLOAD_URL -P $SOFTWARE
在devops主机上使用ansible分别对三个master节点执行以下操作:
### 1.Check if the install directory exists.
if [ ! -d $ETCD_BIN_DIR ]; then
mkdir -p $ETCD_BIN_DIR
mkdir -p $ETCD_DATA_DIR
mkdir -p $ETCD_WAL_DIR
fi
### 2.Install etcd binary of kubernetes.
if [ ! -f "$SOFTWARE/etcd-${VERSION}-linux-amd64.tar.gz" ]; then
sudo wget $DOWNLOAD_URL -P $SOFTWARE >>/tmp/install.log 2>&1
fi
cd $SOFTWARE && tar -xzf etcd-${VERSION}-linux-amd64.tar.gz -C ./
cp -fp etcd-${VERSION}-linux-amd64/etcd* $ETCD_BIN_DIR
ln -sf $ETCD_BIN_DIR/{etcd,etcdctl} /usr/local/bin
sudo chmod -R 755 $ETCD_INSTALL_PATH
sudo chown -R $USER:$USER $ETCD_INSTALL_PATH
cat >/usr/lib/systemd/system/etcd.service<
systemctl etcd.service start
systemctl status etcd|grep Active
确保状态为 active (running),否则查看日志,确认原因:
sudo journalctl -u etcd
验证etcd服务状态
ETCDCTL_API=3 etcdctl \
--endpoints=${ETCD_ENPOIDTS} \
--cacert=/etc/k8s/ssl/ca.pem \
--cert=/etc/k8s/ssl/etcd.pem \
--key=/etc/k8s/ssl/etcd-key.pem endpoint health
当输出值为以下状态即为正常:
https://10.10.10.22:2379 is healthy: successfully committed proposal: took = 3.693346ms
https://10.10.10.23:2379 is healthy: successfully committed proposal: took = 2.80687ms
https://10.10.10.24:2379 is healthy: successfully committed proposal: took = 4.493037ms
查看当前leader
ETCDCTL_API=3 etcdctl \
--endpoints=${ETCD_ENPOIDTS} \
--cacert=/etc/k8s/ssl/ca.pem \
--cert=/etc/k8s/ssl/etcd.pem \
--key=/etc/k8s/ssl/etcd-key.pem endpoint status
输出:
https://10.10.10.22:2379, 641670f7677ceff, 3.3.13, 2.9 MB, false, 2, 6198986
https://10.10.10.23:2379, ce37122364c277fa, 3.3.13, 2.9 MB, true, 2, 6198986
https://10.10.10.24:2379, 4d1003897626ccde, 3.3.13, 2.9 MB, false, 2, 6198986
到这里,整个etcd集群就部署完成,关于更多的etcd操作可以阅读etcd官方文档,部署好etcd数据库,开部署kubernetes master节点相关组件,请参考:kubernetes集群安装指南:apiserver节点组件部署,关于etcd脚本请从此处获取;
我们在微信上24小时期待你的声音
解答本文疑问/技术咨询/运营咨询/技术建议/互联网交流