官方文档:https://docs.kubeedge.io/en/latest/
参考视频:https://www.bilibili.com/video/BV1LJ411D7t1?p=3
参考文章:https://blog.csdn.net/subfate/article/details/106463852
我这共两台机器,192.168.1.10部署Master和cloudcore,192.168.1.11部署edgecore
2.1. 修改主机名
根据IP地址修改,如hostnamectl set-hostname 192-168-1-10
2.2. 开启路由转发
sed -i 's/net.ipv4.ip_forward=.*/net.ipv4.ip_forward=1/' /etc/sysctl.conf
sysctl -p
2.3.安装Docker(所有节点)
2.4.部署K8S集群(单机版,云端节点)
kubeadm部署K8s集群V1.19.0
注意:只需要部署Master相关组件
2.5.安装Mosquitto(只在边缘节点安装)
mosquitto镜像制作参考文章:https://anqixiang.blog.csdn.net/article/details/110451206
docker run -itd --restart always --name mosquitto -p 1883:1883 mosquitto:v1.0
3.1.配置Golang 环境(版本1.14.7)
tar xvf go1.14.7.linux-amd64.tar.gz -C /usr/local/bin/
vi /etc/profile #添加如下几行
#GO
export GO_HOME=/usr/local/bin/go
export PATH=$GO_HOME/bin:$PATH
source /etc/profile
go version
3.2. 源码编译
git config --global http.sslVerify false #跳过SSL验证
cd /opt
git clone https://github.com/kubeedge/kubeedge.git
yum install gcc make -y
cd /opt/kubeedge
make all WHAT=cloudcore
make all WHAT=edgecore
生成的二进制位于_output/local/bin/目录下,把生成的二进制文件拷贝到/usr/local/bin/下
3.3.创建设备模型和设备CRD
cd /opt/kubeedge/build/crds/devices
kubectl create -f devices_v1alpha2_devicemodel.yaml
kubectl create -f devices_v1alpha2_device.yaml
cd /opt/kubeedge/build/crds/reliablesyncs
kubectl create -f cluster_objectsync_v1alpha1.yaml
kubectl create -f objectsync_v1alpha1.yaml
3.4.配置云端节点
mkdir -p /etc/kubeedge/config/
cloudcore --minconfig > /etc/kubeedge/config/cloudcore.yaml
cp /data/kubeedge/build/tools/cloudcore.service /etc/systemd/system/cloudcore.service
vi /etc/systemd/system/cloudcore.service
修改启动命令为/usr/local/bin/cloudcore
systemctl daemon-reload
systemctl enable cloudcore
systemctl start cloudcore
journalctl -u cloudcore -f #查看日志
nohup ./cloudcore > cloudcore.log 2>&1 & #启动cloudcore
3.5.配置边缘端节点
scp /usr/local/bin/edgecore 192.168.1.11:/usr/local/bin/
scp /data/images/pause.tar 192.168.1.11:/data/
docker load -i /data/pause.tar
docker tag swr.cn-south-1.myhuaweicloud.com/anqixiang_k8s/pause:3.1 kubeedge/pause:3.1
mkdir -p /etc/kubeedge/{ca,certs,config}
edgecore --minconfig > /etc/kubeedge/config/edgecore.yaml
sed -i 's|podSandboxImage: .*|podSandboxImage: kubeedge/pause:3.1|' /etc/kubeedge/config/edgecore.yaml
#修改token
token=$(kubectl get secret -nkubeedge tokensecret -o=jsonpath='{.data.tokendata}' | base64 -d)
sed -i "s|token: .*|token: ${token}|g" /etc/kubeedge/config/edgecore.yaml
ssh 192.168.1.11 -t -t "mkdir -p /etc/kubeedge/{ca,certs,config}"
scp /etc/kubeedge/config/edgecore.yaml 192.168.1.11:/etc/kubeedge/config/
vi /etc/kubeedge/config/edgecore.yaml
hostnameOverride为当前节点的主机名
nodeIP为当前节点的物理IP地址
在云端节点操作
vi /data/kubeedge/build/tools/edgecore.service
for ip in ${NODEIP}; do scp /data/kubeedge/build/tools/edgecore.service $ip:/etc/systemd/system/; done
for ip in ${NODEIP}; do ssh $ip -t -t "systemctl daemon-reload && systemctl enable edgecore && systemctl start edgecore"; done
nohup edgecore > /var/log/edgecore.log 2>&1 & #启动edgecore
3.6.验证
kubectl get node
kubectl apply -f /opt/kubeedge/build/deployment.yaml
kubectl get pod