三台KVM,分别是node0、node1、node2,使用ubuntu 20.10系统
node0是master,node1和node2是worker
以下是三台虚拟机上都有安装的组件
1、禁止swap
swapoff -a
vi /etc/fstab,将swap那行注释掉
2、安装docker
apt install docker
然后修改driver为systemd
cat > /etc/docker/daemon.json { "registry-mirrors": [ "https://docker.mirrors.ustc.edu.cn", "http://hub-mirror.c.163.com" ], "insecure-registries":[ "http://registry.my-lnk.tech" ], "max-concurrent-downloads": 10, "exec-opts": ["native.cgroupdriver=systemd"], "log-driver": "json-file", "log-level": "warn", "log-opts": { "max-size": "10m", "max-file": "3" }, "data-root": "/var/lib/docker", "storage-driver": "overlay2" }
3、安装kubelet kubeadm kubectl
apt update && apt install -y apt-transport-https
curl https://mirrors.aliyun.com/kubernetes/apt/doc/apt-key.gpg | apt-key add -
cat <<EOF >/etc/apt/sources.list.d/kubernetes.list
deb https://mirrors.aliyun.com/kubernetes/apt/ kubernetes-xenial main
EOF
apt update
# 查看可安装版本
apt-cache madison kubelet
# 安装版本
apt install -y kubelet kubeadm kubectl
# 配置自启动
sudo systemctl enable kubelet && sudo systemctl start kubelet
以下是在MASTER上执行的命令,本次安装以1.20.2版本
export MASTER_IP=192.168.122.100 #MASTER主机的IP
export APISERVER_NAME=my.k8s.demo #域名
export POD_SUBNET=10.100.0.1/16 #子网,可以不改
echo "${MASTER_IP} ${APISERVER_NAME}" >> /etc/hosts
curl -sSL https://kuboard.cn/install-script/v1.20.x/init_master.sh | sh -s 1.20.2
安装完成后,如果全部成功,执行如下命令生成JOIN码:
kubeadm token create --print-join-command
kubeadm join my.k8s.demo:6443 --token ollefx.h2sylxwwb04m6a0n --discovery-token-ca-cert-hash sha256:b941724b5f1a7970ee6929c9c8dc0130029b23ba5cc03ae2f825597363882fe8
以下是在两台worker上分别都执行:
export MASTER_IP=192.168.122.100
export APISERVER_NAME=my.k8s.demo
echo "${MASTER_IP} ${APISERVER_NAME}" >> /etc/hosts
kubeadm join my.k8s.demo:6443 --token ollefx.h2sylxwwb04m6a0n --discovery-token-ca-cert-hash sha256:b941724b5f1a7970ee6929c9c8dc0130029b23ba5cc03ae2f825597363882fe8
等待所有镜像下载完毕,如果成功后在MASTER上执行打印如下:
root@k8s-master:/mnt/share# kubectl get nodes NAME STATUS ROLES AGE VERSION k8s-master Ready control-plane,master 76m v1.20.2 k8s-node1 Ready <none> 34m v1.20.2 k8s-node2 Ready <none> 33m v1.20.2