您好,登錄后才能下訂單哦!
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<<EOF
[Unit]
Description=Etcd Server
After=network.target
After=network-online.target
Wants=network-online.target
[Service]
Type=notify
User=${USER}
WorkingDirectory=${ETCD_DATA_DIR}
# set GOMAXPROCS to number of processors
ExecStart=/bin/bash -c "GOMAXPROCS=$(nproc) ${ETCD_BIN_DIR}/etcd \\
--name=${HOSTNAME} \\
--data-dir=${ETCD_DATA_DIR} \\
--wal-dir=${ETCD_WAL_DIR} \\
--cert-file=${CA_PATH}/etcd.pem \\
--key-file=${CA_PATH}/etcd-key.pem \\
--trusted-ca-file=${CA_PATH}/ca.pem \\
--peer-cert-file=${CA_PATH}/etcd.pem \\
--peer-key-file=${CA_PATH}/etcd-key.pem \\
--peer-trusted-ca-file=${CA_PATH}/ca.pem \\
--peer-client-cert-auth=true \\
--client-cert-auth=true \\
--listen-peer-urls=https://${LISTEN_IP}:2380 \\
--initial-advertise-peer-urls=https://${LISTEN_IP}:2380 \\
--listen-client-urls=https://${LISTEN_IP}:2379,https://127.0.0.1:2379 \\
--advertise-client-urls=https://${LISTEN_IP}:2379 \\
--initial-cluster-token=etcd-cluster-0 \\
--initial-cluster=${ETCD_ENPOIDTS} \\
--initial-cluster-state=new \\
--auto-tls=true \\
--auto-compaction-mode=periodic \\
--auto-compaction-retention=1 \\
--max-request-bytes=33554432 \\
--quota-backend-bytes=6442450944 \\
--heartbeat-interval=250 \\
--election-timeout=2000 \\
--peer-auto-tls=true"
Restart=on-failure
RestartSec=5
LimitNOFILE=65536
[Install]
WantedBy=multi-user.target
EOF
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腳本請從此處獲取;
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。