k8s部署之ETCD集群

k8s部署之ETCD集群

1.etcd下载

etcd下载地址:https://github.com/coreos/etcd/releases
从github etcd的发布页面选取相应的版本用 wget url 来下载   如:
wget https://github.com/coreos/etcd/releases/download/v3.3.5/etcd-v3.3.5-linux-amd64.tar.gz
下载完成后用 tar -zxvf etcd-v3.3.5-linux-amd64.tar.gz 文件解压
cd etcd-v3.3.5-linux-amd64 进入目录 把etcd etcdctl两个文件复制到要安装的目录
mkdir /var/lib/etcd/

2.etcd配置文件

生成etcd运行时的配置文件
cat > etcd <<EOF
#[Member]
ETCD_NAME="etcd01"
ETCD_DATA_DIR="/var/lib/etcd/default.etcd"
ETCD_LISTEN_PEER_URLS="https://192.168.1.6:2380"
ETCD_LISTEN_CLIENT_URLS="https://192.168.1.6:2379"

#[Clustering]
ETCD_INITIAL_ADVERTISE_PEER_URLS="https://192.168.1.6:2380"
ETCD_ADVERTISE_CLIENT_URLS="https://192.168.1.6:2379"
ETCD_INITIAL_CLUSTER="etcd01=https://192.168.1.6:2380,etcd02=https://192.168.1.7:2380,etcd03=https://192.168.1.8:2380"
ETCD_INITIAL_CLUSTER_TOKEN="etcd-cluster"
ETCD_INITIAL_CLUSTER_STATE="new"
EOF

3.生成etcd服务配置文件

运行时的配置文件我们生成好了,现在我们来生成etc服务化的 .service文件

cat > etcd.service <<EOF
[Unit]
Description=Etcd Server
After=network.target
After=network-online.target
Wants=network-online.target

[Service]
Type=notify
EnvironmentFile=-/opt/kubernetes/cfg/etcd
ExecStart=/opt/kubernetes/bin/etcd \
--name=${ETCD_NAME} \
--data-dir=${ETCD_DATA_DIR} \
--listen-peer-urls=${ETCD_LISTEN_PEER_URLS} \
--listen-client-urls=${ETCD_LISTEN_CLIENT_URLS},http://127.0.0.1:2379 \
--advertise-client-urls=${ETCD_ADVERTISE_CLIENT_URLS} \
--initial-advertise-peer-urls=${ETCD_INITIAL_ADVERTISE_PEER_URLS} \
--initial-cluster=${ETCD_INITIAL_CLUSTER} \
--initial-cluster-token=${ETCD_INITIAL_CLUSTER} \
--initial-cluster-state=new \
--cert-file=/opt/kubernetes/ssl/server.pem \
--key-file=/opt/kubernetes/ssl/server-key.pem \
--peer-cert-file=/opt/kubernetes/ssl/server.pem \
--peer-key-file=/opt/kubernetes/ssl/server-key.pem \
--trusted-ca-file=/opt/kubernetes/ssl/ca.pem \
--peer-trusted-ca-file=/opt/kubernetes/ssl/ca.pem
Restart=on-failure
LimitNOFILE=65536

[Install]
WantedBy=multi-user.target
EOF

文件生成后我们把文件复制到服务目录去

cp etcd.service /usr/lib/systemd/system

然后就可以启动服务,服务自启

systemctl start etcd
systemctl enable etcd

以这些步骤做完之后我们就可以用我们之前的免密登录来把相关文件复制到其它的服务器,然后修改配置文件启动服务。
至此我们的etcd就可以以集群的方式来运行了

没有更多推荐了,返回首页