KubeEdge在树莓派上的安装
Howard Yin 2020-11-19 03:41:01 边缘计算容器化实操KubeEdge
# 开始之前
# 装系统
# 设置挂载cgroup
在/boot
分区中的/boot/cmdline.txt
文件开头加上cgroup_enable=memory cgroup_memory=1
。
# 关闭自动更新
apt autoremove --purge
dpkg-reconfigure -plow unattended-upgrades
reboot
1
2
3
2
3
# 设置WiFi
将/etc/netplan/50-cloud-init.yaml
修改为这样:
# This file is generated from information provided by the datasource. Changes
# to it will not persist across an instance reboot. To disable cloud-init's
# network configuration capabilities, write a file
# /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg with the following:
# network: {config: disabled}
network:
ethernets:
eth0:
dhcp4: true
optional: true
version: 2
wifis:
wlan0:
dhcp4: true
optional: true
access-points:
"HUAWEI-PKAWX9_HiLink":
password: "87654321"
"yin_Home":
password: "409987654321"
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# 本文所有操作均在su
账户下完成
# 安装Docker
以下内容摘自官方教程。
apt-get update
apt-get install -y \
apt-transport-https \
ca-certificates \
curl \
gnupg-agent \
software-properties-common
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
apt-key fingerprint 0EBFCD88
add-apt-repository \
"deb [arch=arm64] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) \
stable"
apt-get update
apt-get install -y docker-ce docker-ce-cli containerd.io
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# 编译keadm
# 安装Golang
wget https://golang.org/dl/go1.15.2.linux-arm64.tar.gz
tar -C /usr/local -xzf go1.15.2.linux-arm64.tar.gz
export PATH=$PATH:/usr/local/go/bin
export GOPATH="/root/go" #安装过程中Golang只用一次所以不加到profile中
go version
1
2
3
4
5
2
3
4
5
# 安装make
apt-get install -y make
1
# 下载编译KubeEdge源码
git clone https://github.com/kubeedge/kubeedge $GOPATH/src/github.com/kubeedge/kubeedge
cd $GOPATH/src/github.com/kubeedge/kubeedge
make all WHAT=keadm
1
2
3
2
3
# 加入集群
# 从云端获取token
在运行着cloudcore
的云端执行:
keadm gettoken
1
记录下输出的token字符串。
# 将树莓派加入集群
cd $GOPATH/src/github.com/kubeedge/kubeedge/_output/local/bin
./keadm join --cloudcore-ipport=<云端的IP>:<cloudcore端口号,默认为10000> --edgenode-name=<为这个边缘节点取名> --token=<从云端获取到的token>
1
2
2
# 量产边缘节点
树莓派安装KubeEdge的关键实际上只是一个keadm
程序,因此可以在keadm
编译完成后直接放到其他树莓派上使用而不再下载Golang编译源码。
# 构造原型系统
从编译安装的系统中取出keadm
程序和/etc/kubeedge
文件夹,在一个新SD卡中:
- 刷入经过基本设置的Ubuntu系统
- 按照前文所述的步骤安装Docker
- 将
keadm
上传到/bin
- 将
/etc/kubeedge
文件夹上传到/etc/kubeedge
# 生成镜像
# 用读卡器
在Linux系统上:
dd bs=4M if=/dev/<SD卡设备名> | gzip | cat > rasp.img.gz
1
在Windows系统上:用Win32DiskImager读取即可。
# 基于网络
选择一个硬盘容量足够的主机,记录下IP地址,在原型系统上执行:
dd bs=4M if=/dev/mmcblk0 | gzip | ssh <目标主机IP> "cat > rasp.img.gz"
1
# 使用镜像量产边缘节点
对于每个树莓派,将系统镜像刷入SD卡,开机后执行:
keadm join --kubeedge-version=1.4.0 --cloudcore-ipport=<云端的IP>:<cloudcore端口号,默认为10000> --edgenode-name=<为这个边缘节点取名> --token=<从云端获取到的token>
1
即可完成设置。