前提

角色 IP 服务部署
云端 10.10.102.111 k8s 的 master,docker,cloudcore
边缘端 10.10.102.112 docker,edgecore

以上机器都要安装 docker ,由于云端是 k8s 的 master ,而我已经装好了,所以不需再去执行,只需边缘端执行以下操作就可以!如果你没有现成的 k8s 集群,就需要所有的机器都要执行,且云端需要部署一套 k8s 集群。

一、部署golang

  1. #配置 golang 环境
  2. wget https://golang.google.cn/dl/go1.17.3.linux-amd64.tar.gz
  3. tar -zxvf go1.17.3.linux-amd64.tar.gz -C /usr/local
  4. #配置 golang 环境变量
  5. vim /etc/profile
  6. #文件末尾追加
  7. # golang env
  8. export GOROOT=/usr/local/go
  9. export GOPATH=/data/gopath
  10. export PATH=$PATH:$GOROOT/bin:$GOPATH/bin
  11. # source /etc/profile
  12. # mkdir -p /data/gopath && cd /data/gopath
  13. # mkdir -p src pkg bin

二、部署云端

#配置 cloudcore
#下载 kubeEdge 源码
git clone https://github.com/kubeedge/kubeedge.git $GOPATH/src/github.com/kubeedge/kubeedge

#启动crds
cd $GOPATH/src/github.com/kubeedge/kubeedge/build/crds/devices
kubectl apply -f devices_v1alpha2_devicemodel.yaml
kubectl apply -f devices_v1alpha2_device.yaml
cd ..
cd reliablesyncs
kubectl apply -f cluster_objectsync_v1alpha1.yaml
kubectl apply -f objectsync_v1alpha1.yaml
cd ..
cd router
kubectl apply -f router_v1_ruleEndpoint.yaml
kubectl apply -f router_v1_rule.yaml

#下载 gcc
yum -y install gcc

#编译 cloudcore
cd $GOPATH/src/github.com/kubeedge/kubeedge
make all WHAT=cloudcore

#将编译好的二进制文件 copy 到/usr/local/bin 中
cp _output/local/bin/* /usr/local/bin/

#生成配置文件在 /etc/kubeedge/config
cd /etc
mkdir kubeedge
cd kubeedge
mkdir config
cd config
cloudcore --defaultconfig > cloudcore.yaml

#配置系统自启
cp $GOPATH/src/github.com/kubeedge/kubeedge/build/tools/cloudcore.service /etc/systemd/system/

#运行 cloudcore
systemctl start cloudcore

#获取 token,给 edgecore 配置时使用
kubectl get secret -nkubeedge tokensecret -o=jsonpath='{.data.tokendata}' | base64 -d

#生成证书
cd $GOPATH/src/github.com/kubeedge/kubeedge/build/tools
sh certgen.sh genCertAndKey edge

#边缘端创建完目录后,发送到边缘端
scp /etc/kubeedge/* root@10.10.102.111:/etc/kubeedge/

三、部署边缘端

#配置 edgecore
#下载 kubeEdge 源码
git clone https://github.com/kubeedge/kubeedge.git $GOPATH/src/github.com/kubeedge/kubeedge

#下载 gcc
yum -y install gcc

#编译 edgecore
cd $GOPATH/src/github.com/kubeedge/kubeedge
make all WHAT=edgecore

#将编译好的二进制文件 copy 到/usr/local/bin 中
cp _output/local/bin/* /usr/local/bin/

#生成配置文件在 /etc/kubeedge/config
cd /etc
mkdir kubeedge
cd kubeedge
mkdir config
cd config
edgecore --defaultconfig > edgecore.yaml

后面需要修改 edgecore.yaml 配置。要修改 edgeHub 中 httpServer 的地址,改为云端IP,还要修改websocket 中 server 的地址,同样改为云端IP。将云端获取的 token 放入到 edgeHub 中 token 里。将eventBus关闭(如果要使用MQTT则不需要关闭)

#配置 edgecore.yaml
vim edgecore.yaml

#修改 edgeHub
  edgeHub:
    enable: true
    heartbeat: 15
    httpServer: https://10.10.102.111:10002        #需要修改的部分,修改成云端的IP
    projectID: e632aba927ea4ac2b575ec1603d56f10
    quic:
      enable: false
      handshakeTimeout: 30
      readDeadline: 15
      server: 10.10.102.112:10001
      writeDeadline: 15
    rotateCertificates: true
    tlsCaFile: /etc/kubeedge/ca/rootCA.crt
    tlsCertFile: /etc/kubeedge/certs/server.crt
    tlsPrivateKeyFile: /etc/kubeedge/certs/server.key
    token: "81bb48accdc709daa3cb6f5c9689518d921dea0fdc4b3f0a70a407b085a8cfc8.eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE2MzY2ODM2MTZ9.eW2dct0RgdOjhNpzmJQwny7hEaX7RAnhn0gd1e-XO4g"        #需要修改的部分,修改成云端的token
    websocket:
      enable: true
      handshakeTimeout: 30
      readDeadline: 15
      server: 10.10.102.111:10000            #需要修改的部分,修改成云端的IP

…………

   eventBus:
    enable: false        #关闭 eventBus
    eventBusTLS:
      enable: false
#配置系统自启
cp $GOPATH/src/github.com/kubeedge/kubeedge/build/tools/edgecore.service /etc/systemd/system/

#运行 edgecore
systemctl start edgecore