kubernetes v1.18.2 二进制部署 ipv4 etcd 部署
2021-03-11 10:28
标签:加密 lld poi uber ase 用户 new 特定 load kubernetes v1.18.2 二进制部署 ipv4 etcd 部署 标签:加密 lld poi uber ase 用户 new 特定 load 原文地址:https://blog.51cto.com/juestnow/2492776修改服务器名
ssh 192.168.2.175 hostnamectl set-hostname k8s-master-1
ssh 192.168.2.176 hostnamectl set-hostname k8s-master-2
ssh 192.168.2.177 hostnamectl set-hostname k8s-master-3
ssh 192.168.2.185 hostnamectl set-hostname k8s-node-1
ssh 192.168.2.187 hostnamectl set-hostname k8s-node-2
设置关闭防火墙及SELINUX
# centosx
sed -i ‘s/SELINUX=.*/SELINUX=disabled/g‘ /etc/selinux/config
systemctl stop firewalld && systemctl disable firewalld
setenforce 0
# Ubuntu
systemctl stop ufw.service
systemctl disable ufw.service
安装及配置CFSSL 签发证书使用
#go 环境部署
yum install go
vi ~/.bash_profile
GOBIN=/root/go/bin/
PATH=$PATH:$GOBIN:$HOME/bin
export PATH
go get github.com/cloudflare/cfssl/cmd/cfssl
go get github.com/cloudflare/cfssl/cmd/cfssljson
签发etcd 证书
# 设置证书环境变量
# 设置证书使用时间87600h 10年
export EXPIRY_TIME="87600h"
# 签发证书IP
export ETCD_MEMBER_1_IP="192.168.2.175"
export ETCD_MEMBER_2_IP="192.168.2.176"
export ETCD_MEMBER_3_IP="192.168.2.177"
# 机器名
export ETCD_MEMBER_1_HOSTNAMES="k8s-master-1"
export ETCD_MEMBER_2_HOSTNAMES="k8s-master-2"
export ETCD_MEMBER_3_HOSTNAMES="k8s-master-3"
# etcd 集群通讯证书
export ETCD_SERVER_HOSTNAMES="\"${ETCD_MEMBER_1_HOSTNAMES}\",\"${ETCD_MEMBER_2_HOSTNAMES}\",\"${ETCD_MEMBER_3_HOSTNAMES}\""
export ETCD_SERVER_IPS="\"${ETCD_MEMBER_1_IP}\",\"${ETCD_MEMBER_2_IP}\",\"${ETCD_MEMBER_3_IP}\""
#证书所需要的配置参数
export CERT_ST="GuangDong"
export CERT_L="GuangZhou"
export CERT_O="k8s"
export CERT_OU="Qist"
export CERT_PROFILE="kubernetes"
# 设置工作目录
export HOST_PATH=`pwd`
# 创建etcd K8S 证书json 存放目录
mkdir -p ${HOST_PATH}/cfssl/{k8s,etcd}
# 创建签发证书存放目录
mkdir -p ${HOST_PATH}/cfssl/pki/{k8s,etcd}
# CA 配置文件用于配置根证书的使用场景 (profile) 和具体参数 (usage,过期时间、服务端认证、客户端认证、加密等),后续在签名其它证书时需要指定特定场景。
cat
2、etcd 二进制文件准备
wget https://github.com/etcd-io/etcd/releases/download/v3.4.7/etcd-v3.4.7-linux-amd64.tar.gz
# 解压下载好文件
tar -xvf etcd-v3.4.7-linux-amd64.tar.gz
# 创建二进制远程存放目录
ssh 192.168.2.175 mkdir -p /apps/etcd/bin
ssh 192.168.2.176 mkdir -p /apps/etcd/bin
ssh 192.168.2.177 mkdir -p /apps/etcd/bin
# 分发解压好二进制文件
cd etcd-v3.4.7-linux-amd64/
scp -r etcd* 192.168.2.175:/apps/etcd/bin
scp -r etcd* 192.168.2.176:/apps/etcd/bin
scp -r etcd* 192.168.2.177:/apps/etcd/bin
3、etcd 配置文件准备
# 创建配置文件存放目录
ssh 192.168.2.175 mkdir -p /apps/etcd/conf
ssh 192.168.2.176 mkdir -p /apps/etcd/conf
ssh 192.168.2.177 mkdir -p /apps/etcd/conf
# 192.168.2.175 配置
ssh 192.168.2.175
cat
etcd 启动文件配置
cat
etcd 启动准备
# 创建etcd 用户
ssh 192.168.2.175 useradd etcd -s /sbin/nologin -M
ssh 192.168.2.176 useradd etcd -s /sbin/nologin -M
ssh 192.168.2.177 useradd etcd -s /sbin/nologin -M
# 创建etcd 存储文件目录
ssh 192.168.2.175 mkdir -p /apps/etcd/data/default.etcd/wal
ssh 192.168.2.176 mkdir -p /apps/etcd/data/default.etcd/wal
ssh 192.168.2.177 mkdir -p /apps/etcd/data/default.etcd/wal
# 给/apps/etcd etcd 用户权限
ssh 192.168.2.175 chown -R etcd:etcd /apps/etcd/
ssh 192.168.2.176 chown -R etcd:etcd /apps/etcd/
ssh 192.168.2.177 chown -R etcd:etcd /apps/etcd/
etcd 启动
# 刷新service
systemctl daemon-reload
# 设置开机启动
systemctl enable etcd.service
# 启动etcd
systemctl start etcd.service
# 查看启动状态
systemctl status etcd.service
# 验证etcd 集群是否正常 任意节点
vi ~/.bashrc
export ETCDCTL_API=3
export ENDPOINTS=https://192.168.2.175:2379,https://192.168.2.176:2379,https://192.168.2.177:2379
alias ctl=‘/apps/etcd/bin/etcdctl --endpoints=${ENDPOINTS} --cacert=/apps/etcd/ssl/etcd-ca.pem --cert=/apps/etcd/ssl/etcd-client.pem --key=/apps/etcd/ssl/etcd-client-key.pem‘
# 保存
source ~/.bashrc
# 验证集群是否正常
[root@k8s-master-1 conf]# ctl endpoint status
https://192.168.2.175:2379, 5ba4ebb731bb27f7, 3.4.7, 20 kB, false, false, 2, 11, 11,
https://192.168.2.176:2379, 2982ccbf31a4b4e, 3.4.7, 20 kB, true, false, 2, 11, 11,
https://192.168.2.177:2379, d86131c63ec195be, 3.4.7, 20 kB, false, false, 2, 11, 11,
[root@k8s-master-1 conf]# ctl endpoint hashkv
https://192.168.2.175:2379, 1084519789
https://192.168.2.176:2379, 1084519789
https://192.168.2.177:2379, 1084519789
[root@k8s-master-1 conf]# ctl endpoint health
https://192.168.2.176:2379 is healthy: successfully committed proposal: took = 19.088204ms
https://192.168.2.175:2379 is healthy: successfully committed proposal: took = 24.073788ms
https://192.168.2.177:2379 is healthy: successfully committed proposal: took = 26.414683ms
[root@k8s-master-1 conf]# ctl member list
2982ccbf31a4b4e, started, k8s-master-2, https://192.168.2.176:2380, https://192.168.2.176:2379, false
5ba4ebb731bb27f7, started, k8s-master-1, https://192.168.2.175:2380, https://192.168.2.175:2379, false
d86131c63ec195be, started, k8s-master-3, https://192.168.2.177:2380, https://192.168.2.177:2379, false
文章标题:kubernetes v1.18.2 二进制部署 ipv4 etcd 部署
文章链接:http://soscw.com/index.php/essay/63153.html