文章目录
前言
本文将不翻墙部署一个3节点(1主2从)集群,已经在ubuntu2004上测试通过。
配置3节点集群,您的电脑最好有:
- 至少4个逻辑核心
- 至少8G内存
- 20-40G以上空闲硬盘空间(视您所使用的镜像大小)
- 我们首先在一个ubuntu虚拟机中配置好基本环境,将来作为master节点
- 然后复制出另外两份作为node节点
- 用官方
kubeadm
工具在三台虚拟机上建立集群 - 最后用redis作为负载来测试集群
接下来全部过程都使用root进行
1. 配置通用设置
安装docker
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add -
apt install docker.io
systemctl enable docker
systemctl start docker
systemctl status docker
cat > /etc/docker/daemon.json << EOF
{
"registry-mirrors": ["https://alzgoonw.mirror.aliyuncs.com"],
"live-restore": true
}
EOF
systemctl daemon-reload
systemctl restart docker
安装kubeadm、kubectl、kubelet
curl -s https://mirrors.aliyun.com/kubernetes/apt/doc/apt-key.gpg| apt-key add -
cat << EOF >/etc/apt/sources.list.d/kubernetes.list
deb http://mirrors.ustc.edu.cn/kubernetes/apt kubernetes-xenial main
EOF
apt-get update && apt-get install -y kubelet kubeadm kubectl
echo "export KUBECONFIG=/etc/kubernetes/admin.conf" >> /etc/profile
systemctl enable kubelet
systemctl daemon-reload
systemctl restart kubelet
修改配置
# 关闭防火墙
systemctl stop firewalld
systemctl disable firewalld
# 禁用Selinux
apt install selinux-utils
setenforce 0
# 禁用swap
swapoff -a
# !!! 同时把/etc/fstab包含swap那行记录删掉!!!
2. 分别配置三台虚拟机
如果你的电脑配置不高,可以将两个node调成 1G 1CPU。
- 修改hostname
echo k8s-master > /etc/hostname
我将三台虚拟机hostname分别设置为:
k8s-master
k8s-node1
k8s-node2
- 设置静态IP
查看虚拟机分配的 IP、DNS主机、网关、掩码 并将其设置为静态
ip addr
我将三台虚拟机IP分别设置为:
192.168.35.130
192.168.35.131
192.168.35.132