主机配置为16G内存的win10系统,在VMware Workstation 15上创建两个Ubuntu虚拟机,分别作为主节点master(10.64.17.99)和从节点node(10.64.17.111)。相关的软件版本如下表所示:
名称 | 版本 | 安装节点 |
---|---|---|
ubuntu | 22.04.1 | master, node |
docker | 20.10.12 | master, node |
kubernetes | 1.20.2 | master |
kubeedge | 1.10.0 | master, node |
ubuntu在虚拟机上的安装可参考相关文档,本文中分配了2核CPU、4G内存和60G硬盘空间。
cd /etc/apt/
sudo cp sources.list sources.list.bak
sudo vi sources.list #本文使用中科大源
sudo apt-get update #换源后要更新列表
sudo apt-get upgrade
中科大的源如下(源码暂时用不上,相关地址注释掉),也可以视网络情况使用阿里、清华等源
deb https://mirrors.ustc.edu.cn/ubuntu/ focal main restricted universe multiverse
#deb-src https://mirrors.ustc.edu.cn/ubuntu/ focal main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ focal-updates main restricted universe multiverse
#deb-src https://mirrors.ustc.edu.cn/ubuntu/ focal-updates main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ focal-backports main restricted universe multiverse
#deb-src https://mirrors.ustc.edu.cn/ubuntu/ focal-backports main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ focal-security main restricted universe multiverse
#deb-src https://mirrors.ustc.edu.cn/ubuntu/ focal-security main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ focal-proposed main restricted universe multiverse
#deb-src https://mirrors.ustc.edu.cn/ubuntu/ focal-proposed main restricted universe multiverse
先安装net-tools、vim等常用的工具软件
sudo apt-get install -y \
net-tools \
vim \
ca-certificates \
curl \
gnupg \
lsb-release \
apt-transport-https
添加 Docker 官方 GPG 密钥:
sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
设置存储库:
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update #换源后不要忘记更新列表
sudo apt-cache madison docker-ce #查看可安装的版本,此步可选
sudo apt-get install docker-ce=20.10.12 docker-ce-cli=20.10.12 containerd.io docker-compose-plugin
访问国外服务器网速较慢,可做如下配置。
sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors": ["https://82m9ar63.mirror.aliyuncs.com"],
"exec-opts": ["native.cgroupdriver=systemd"], #注意:node节点的驱动为cgroupfs
"log-driver": "json-file",
"log-opts": {
"max-size": "100m"
},
"storage-driver": "overlay2"
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker
sudo docker run hello-world #检查是否安装成功(即显示"Hello from Docker!...")
新装的系统没有开防火墙(可在参考文档中查找方法),本文只说明关闭防火墙的方法。
sudo swapoff -a #关闭交换分区
sudo vim /etc/fstab # 注释掉swap分区那一行,永久禁用swap分区
设置2个k8s.conf文件,允许 iptables 检查桥接流量
cat <<EOF | sudo tee /etc/modules-load.d/k8s.conf
br_netfilter
EOF
cat <<EOF | sudo tee /etc/sysctl.d/k8s.conf
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
EOF
sudo sysctl --system #应用设置
下载公开签名秘钥并添加阿里云镜像源
sudo curl https://mirrors.aliyun.com/kubernetes/apt/doc/apt-key.gpg | sudo apt-key add -
sudo cat <<EOF >/etc/apt/sources.list.d/kubernetes.list
deb https://mirrors.aliyun.com/kubernetes/apt/ kubernetes-xenial main
EOF
sudo apt-get update
开始安装
sudo apt-get install -y kubelet=1.20.2-00 kubeadm=1.20.2-00 kubectl=1.20.2-00
sudo systemctl enable --now kubelet #使服务生效
在/etc/hosts中设置地址映射
sudo vim /etc/hosts
主节点和从节点的地址如下(用ifconfig查询地址):
10.64.17.99 master
10.64.17.111 node
初始化
sudo kubeadm init \
--apiserver-advertise-address=10.64.17.99 \
--control-plane-endpoint=master \
--image-repository registry.cn-hangzhou.aliyuncs.com/google_containers --kubernetes-version v1.20.2 \
--service-cidr=10.96.0.0/12 \
--pod-network-cidr=10.244.0.0/16
初始化成功后,按系统提示信息进行配置
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
安装网络组件
curl https://docs.projectcalico.org/manifests/calico.yaml -O
sudo kubectl apply -f calico.yaml
sudo kubectl get pods -A #检查主节点是否完成初始化并准备就绪
为避免网速过慢影响安装,提前从github下载kubeedge相关文件:
kubeedge-v1.10.0-linux-amd64.tar.gz
checksum_kubeedge-v1.10.0-linux-amd64.tar.gz.txt
keadm-v1.10.0-linux-amd64.tar.gz
解压并将文件放到指定文件夹
cd ~
cp /mnt/hgfs/share-master/keadm-v1.10.0-linux-amd64.tar.gz . #从共享文件夹复制
tar -zxvf keadm-v1.10.0-linux-amd64.tar.gz
sudo cp keadm-v1.10.0-linux-amd64/keadm/keadm /usr/sbin/
sudo cp /mnt/hgfs/share-master/kubeedge-v1.10.0-linux-amd64.tar.gz /etc/kubeedge/
sudo cp /mnt/hgfs/share-master/checksum_kubeedge-v1.10.0-linux-amd64.tar.gz.txt /etc/kubeedge/
sudo keadm init --advertise-address=10.64.17.99 --kubeedge-version=1.10.0 --kube-config=/home/master/.kube/config
ps -ef | grep cloudcore #如果查到2个cloudcore进程,表明启动成功
取出用于加入从节点的令牌
keadm gettoken
(见2.1)
(见2.2)
把docker驱动(/etc/docker/daemon.json)改为cgroupfs
{
"registry-mirrors": ["https://82m9ar63.mirror.aliyuncs.com"],
"exec-opts": ["native.cgroupdriver=cgroupfs"],
"log-driver": "json-file",
"log-opts": {
"max-size": "100m"
},
"storage-driver": "overlay2"
}
(见 2.4.1)
sudo keadm join --cloudcore-ipport=10.64.17.99:10000 --edgenode-name=node --kubeedge-version=1.10.0 --token=7b75d99871707b7d07e9be0e0a13a1a2402bf19bc1ecd27314005fe128e0cbf6.eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE2NjQ0MjE4MTl9.i7SUQN1oJdJlXunLSznT8DCpUHsDPmGYQxCnXfr1sEU
sudo systemctl status edgecore #检查edgecore服务是否正常启动
(在主节点master中,用kubectl get nodes查看)
master@master:~$ kubectl get nodes
NAME STATUS ROLES AGE VERSION
master Ready control-plane,master 27h v1.20.2
node Ready agent,edge 21h v1.22.6-kubeedge-v1.10.0
sudo timedatectl set-timezone Asia/Shanghai
sudo systemctl restart rsyslog
相关链接:
https://blog.csdn.net/u010549795/article/details/125609761.
https://blog.csdn.net/qq_42007073/article/details/124959523.
https://blog.csdn.net/qq_40955261/article/details/115250383