KubeEdge+Wasmedge环境配置

几点说明

  1. 可以参考这个华为云的课程直接使用华为云进行搭建。

  2. 下面是裸机搭建的方式,其中大部分过程都需要各个节点可以进行科学上网,官方文档很多地方目前已经不可取。

  3. 遇到问题可以先查看日志,分析日志去解决。如cloudcore, crio, edgecore的日志,或者查看pod日志kubectl logs

  4. 本文参考了这几篇文章,在安装过程中遇到一些问题可以在这里面找:

Cloud节点配置

1. 安装Go

选择节点的架构对应的安装包,建议安装最新版本

wget https://golang.org/dl/go1.18.1.linux-arm64.tar.gz
tar xzvf go1.18.1.linux-arm64.tar.gz

export PATH=/home/${user}/go/bin:$PATH
go version

2. 安装CRI-O

分段在命令行中执行下面的指令

根据crio的安装说明,找到自己的系统名称,修改下面的OSVERSION

# Create the .conf file to load the modules at bootup

cat <<EOF | sudo tee /etc/modules-load.d/crio.conf
overlay
br_netfilter
EOF

sudo modprobe overlay
sudo modprobe br_netfilter

# Set up required sysctl params; these persist across reboots.

cat <<EOF | sudo tee /etc/sysctl.d/99-kubernetes-cri.conf
net.bridge.bridge-nf-call-iptables  = 1
net.ipv4.ip_forward                 = 1
net.bridge.bridge-nf-call-ip6tables = 1
EOF

# 这个地方如果下载很慢,或者不能下载,就在浏览器中打开opensuse的网址进行下载
sudo sysctl --system
export OS="xUbuntu_22.04"
export VERSION="1.24"
cat <<EOF | sudo tee /etc/apt/sources.list.d/devel:kubic:libcontainers:stable.list
deb https://download.opensuse.org/repositories/devel:/kubic:/libcontainers:/stable/$OS/ /
EOF
cat <<EOF | sudo tee /etc/apt/sources.list.d/devel:kubic:libcontainers:stable:cri-o:$VERSION.list
deb http://download.opensuse.org/repositories/devel:/kubic:/libcontainers:/stable:/cri-o:/$VERSION/$OS/ /
EOF

curl -L https://download.opensuse.org/repositories/devel:/kubic:/libcontainers:/stable/$OS/Release.key | sudo apt-key --keyring /etc/apt/trusted.gpg.d/libcontainers.gpg add -
curl -L https://download.opensuse.org/repositories/devel:kubic:libcontainers:stable:cri-o:$VERSION/$OS/Release.key | sudo apt-key --keyring /etc/apt/trusted.gpg.d/libcontainers-cri-o.gpg add -

sudo apt-get update
sudo apt-get install cri-o cri-o-runc

sudo systemctl daemon-reload
sudo systemctl enable crio --now
sudo systemctl status cri-o # 查看cri-o的状态

3. 使用kubeadm创建k8s集群

3.1. 安装K8s

sudo apt-get update
sudo apt-get install -y apt-transport-https curl
echo "deb [signed-by=/usr/share/keyrings/kubernetes-archive-keyring.gpg] https://apt.kubernetes.io/ kubernetes-xenial main" | sudo tee /etc/apt/sources.list.d/kubernetes.list

sudo apt update
K_VER="1.28.0-00" #这个地方强烈建议安装最新版本的!!!
sudo apt install -y kubelet=${K_VER} kubectl=${K_VER} kubeadm=${K_VER}
sudo apt-mark hold kubelet kubeadm kubectl

3.2. 创建K8s集群

# 关闭交换空间
sudo nano /etc/fstab

在这里插入图片描述

注释掉上图中的/swapfile这一行

# 执行这条指令
cat /etc/cni/net.d/100-crio-bridge.conf
# 得到类似下面的结果
{
    "cniVersion": "0.3.1",
    "name": "crio",
    "type": "bridge",
    "bridge": "cni0",
    "isGateway": true,
    "ipMasq": true,
    "hairpinMode": true,
    "ipam": {
        "type": "host-local",
        "routes": [
            { "dst": "0.0.0.0/0" },
            { "dst": "1100:200::1/24" }
        ],
        "ranges": [
            [{ "subnet": "10.85.0.0/16" }], # 设置这个值为环境变量CIDR
            [{ "subnet": "1100:200::/24" }]
        ]
    }
}

export CIDR=10.85.0.0/16
# --apiserver-advertise-address改成云节点的IP地址
sudo kubeadm init --apiserver-advertise-address=192.168.43.216 --pod-network-cidr=$CIDR --cri-socket=unix:///var/run/crio/crio.sock --image-repository registry.aliyuncs.com/google_containers

mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config

如果遇到问题需要重置集群,使用下面的指令:

sudo kubeadm reset --cri-socket=unix:///var/run/crio/crio.sock
sudo rm -rf $HOME/.kube

4. 用Keadm初始化云节点

sudo ./keadm deprecated init --advertise-address=192.168.43.216 --kube-config=/home/${user}/.kube/config --kubeedge-version=1.14.2

这里KubeEdge可能会下载很慢,可以先到https://github.com/kubeedge/kubeedge/releases下载对应版本放到/etc/kubeedge中,例如下载kubeedge-v1.14.2-linux-amd64.tar.gz/checksum_kubeedge-v1.14.2-linux-amd64.tar.gz.txt

如果遇到问题需要重置,使用下面的指令:

sudo ./keadm reset --kube-config=/home/${user}/.kube/config
systemctl stop cloudcore
sudo rm -rf /etc/systemd/system/cloudcore.service

Edge节点配置

1. 安装Wasmedge

下载https://raw.githubusercontent.com/WasmEdge/WasmEdge/master/utils/install.sh,然后运行此脚本

2. 安装CRI-O和crun

需要先安装wasmedge,否则接下来会报错configure: error: *** Missing wasmedge headers

https://raw.githubusercontent.com/second-state/wasmedge-containers-examples/main/crio/install.sh

先下载上面的内容,如下所示,然后根据crio的安装说明,找到自己的系统名称,修改下面的OS,之后运行脚本就可以。运行过程中有些指令可能报错permission denied,添加sudo重新运行。

OS如果Raspbian有问题,就换成Debian.

#!/bin/bash

export WASMEDGE_VERSION=""
export CRUN_VERSION=""

for opt in "$@"; do
  case $opt in
    -w=*|--wasmedge=*)
      export WASMEDGE_VERSION="${opt#*=}"
      shift
      ;;
    -c=*|--crun=*)
      export CRUN_VERSION="${opt#*=}"
      shift
      ;;
    *)
      ;;
  esac
done

echo -e "Starting installation ..."
sudo apt update
export OS="Raspbian_10" #修改这里
export VERSION="1.24"   #修改这里
echo -e "OS: $OS"
echo -e "Version: $VERSION"
echo -e "Installing libseccomp2 ..."
sudo apt install -y libseccomp2

# Set download URL that we are adding to sources.list.d

export ADD1="deb https://download.opensuse.org/repositories/devel:/kubic:/libcontainers:/stable/$OS/ /"
export DEST1="/etc/apt/sources.list.d/devel:kubic:libcontainers:stable.list"
echo -e "Adding \n$ADD1 \nto \n$DEST1"
export ADD2="deb https://download.opensuse.org/repositories/devel:/kubic:/libcontainers:/stable:/cri-o:/$VERSION/$OS/ /"
export DEST2="/etc/apt/sources.list.d/devel:kubic:libcontainers:stable:cri-o:$VERSION.list"
echo -e "Adding \n$ADD2 \nto \n$DEST2"
sudo rm -rf "$DEST1"
sudo rm -rf "$DEST2"
sudo touch "$DEST1"
sudo touch "$DEST2"
if [ -f "$DEST1" ]
then
    echo "$ADD1" | sudo tee -i "$DEST1"
    echo "Success writing to $DEST1"
else
    echo "Error writing to $DEST1"
    exit 2
fi

if [ -f "$DEST2" ]
then
    echo "$ADD2" | sudo tee -i "$DEST2"
    echo "Success writing to $DEST2"
else
    echo "Error writing to $DEST2"
    exit 2
fi
echo -e "Installing wget"
sudo apt install -y wget
if [ -f Release.key ]
then
    rm -rf Release.key
fi
echo -e "Fetching Release.key"
wget "https://download.opensuse.org/repositories/devel:kubic:libcontainers:stable:cri-o:$VERSION/$OS/Release.key"
echo -e "Adding Release.key"
sudo apt-key add Release.key
echo -e "Deleting Release.key"
rm -rf Release.key
echo -e "Fetching Release.key"
wget "https://download.opensuse.org/repositories/devel:/kubic:/libcontainers:/stable/$OS/Release.key"
echo -e "Adding Release.key"
sudo apt-key add Release.key
echo -e "Removing Release.key"
rm -rf Release.key
sudo apt update
sudo apt install -y criu
sudo apt install -y libyajl2
sudo apt install -y cri-o
sudo apt install -y cri-o-runc
sudo apt install -y cri-tools
sudo apt install -y containernetworking-plugins
echo -e "Installing WasmEdge"
if [ -f install.sh ]
then
    rm -rf install.sh
fi
wget -q https://raw.githubusercontent.com/WasmEdge/WasmEdge/master/utils/install.sh
sudo chmod a+x install.sh

if [[ "$WASMEDGE_VERSION" = "" ]]; then
    echo -e "Use latest WasmEdge release"
    sudo ./install.sh --path="/usr/local"
else
    echo -e "Use WasmEdge: $WASMEDGE_VERSION"
    sudo ./install.sh --path="/usr/local" --version="$WASMEDGE_VERSION"
fi

rm -rf install.sh
echo -e "Building and installing crun"
sudo apt install -y make git gcc build-essential pkgconf libtool libsystemd-dev libprotobuf-c-dev libcap-dev libseccomp-dev libyajl-dev go-md2man libtool autoconf python3 automake

if [[ "$CRUN_VERSION" = "" ]]; then
    echo -e "Use latest master of Crun"
    git clone https://github.com/containers/crun
else
    echo -e "Use Crun: $CRUN_VERSION"
    echo -e "Downloading crun-${CRUN_VERSION}.tar.gz"
    wget https://github.com/containers/crun/releases/download/"${CRUN_VERSION}"/crun-"${CRUN_VERSION}".tar.gz
    tar --no-overwrite-dir -xzf crun-"${CRUN_VERSION}".tar.gz
    mv crun-"${CRUN_VERSION}" crun
fi

cd crun || exit
./autogen.sh
./configure --with-wasmedge
make
sudo make install

# Write config

echo -e "[crio.runtime]\ndefault_runtime = \"crun\"\n" | sudo tee -i /etc/crio/crio.conf
echo -e "\n# Add crun runtime here\n[crio.runtime.runtimes.crun]\nruntime_path = \"/usr/local/bin/crun\"\nruntime_type = \"oci\"\nruntime_root = \"/run/crun\"\n" | sudo tee -i -a /etc/crio/crio.conf.d/01-crio-runc.conf

sudo systemctl restart crio
echo -e "Finished"

安装好之后,需要修改crio的配置文件/etc/crio/crio.conf,增加下面的内容,然后重启crio。

[crio.image]
pause_image="registry.cn-hangzhou.aliyuncs.com/google_containers/pause:latest"

否则会默认拉取k8s.io仓库。

设置开机启动crio

systemctl enable crio
systemctl restart crio

3. 安装Go

wget https://golang.org/dl/go1.18.1.linux-arm64.tar.gz
tar xzvf go1.18.1.linux-arm64.tar.gz

export PATH=/home/${user}/go/bin:$PATH
go version

4. 下载KubeEdge并加入集群

在云节点运行sudo ./keadm gettoken --kube-config=/home/${user}/.kube/config

user@master:~/keadm-v1.14.2-linux-amd64/keadm$ sudo ./keadm gettoken --kube-config=/home/user/.kube/config
4217edbdc987d150745e03a8395d02d0bde2136e46d455b84cf2f485e0a84e2d.eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE2OTcxNjM0NjZ9.6022i6pFVDzR01hPFGarK_lLgPhT51RVmvdI7nuuQuY

接下来下载KubeEdge然后利用token加入集群

wget https://github.com/kubeedge/kubeedge/releases/download/v1.14.2/keadm-v1.14.2-linux-arm64.tar.gz
tar xzvf keadm-v1.14.2-linux-arm64.tar.gz
cd keadm-v1.14.2-linux-arm64/keadm/

#cloudcore-ipport修改成云节点的IP地址
sudo ./keadm deprecated join \
--cloudcore-ipport=192.168.43.216:10000 \
--edgenode-name=knode1 \
--token=2fe0b882d210299d28123766587ee228285326ce2505624089eecad46b89bdd3.eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE2OTcyNDg3ODF9.kyod2BlJfr3JLxG-eTSWJOwIJIylRA1Yjzhn_q3aHEs \
--remote-runtime-endpoint=unix:///var/run/crio/crio.sock \
--runtimetype=remote \
--cgroupdriver=systemd \
--kubeedge-version=1.14.2

这里会先安装Mosquitto,可能会提示Unsupported Proxy Configuration,可以先把代理关掉,然后下载Mosquitto。

如果遇到问题需要重置,使用下面的指令:

sudo ./keadm reset --kube-config=/home/${user}/.kube/config
systemctl stop edgecore
sudo rm -rf /etc/systemd/system/edgecore.service

5. 启用kubectl logs功能

这个过程参考官方文档就可以。kubectl logs一定要启用,否则不能正常使用。可以不使用metrics server

6. 运行简单的WebAssembly应用

kubectl run -it --restart=Never wasi-demo --image=wasmedge/example-wasi:latest --annotations="module.wasm.image/variant=compat-smart" /wasi_example_main.wasm 50000000

在中心节点运行这条指令,如果可以得到类似下面的输出:

Random number: -1694733782
Random bytes: [6, 226, 176, 126, 136, 114, 90, 2, 216, 17, 241, 217, 143, 189, 123, 197, 17, 60, 49, 37, 71, 69, 67, 108, 66, 39, 105, 9, 6, 72, 232, 238, 102, 5, 148, 243, 249, 183, 52, 228, 54, 176, 63, 249, 216, 217, 46, 74, 88, 204, 130, 191, 182, 19, 118, 193, 77, 35, 189, 6, 139, 68, 163, 214, 231, 100, 138, 246, 185, 47, 37, 49, 3, 7, 176, 97, 68, 124, 20, 235, 145, 166, 142, 159, 114, 163, 186, 46, 161, 144, 191, 211, 69, 19, 179, 241, 8, 207, 8, 112, 80, 170, 33, 51, 251, 33, 105, 0, 178, 175, 129, 225, 112, 126, 102, 219, 106, 77, 242, 104, 198, 238, 193, 247, 23, 47, 22, 29]
Printed from wasi: This is from a main function
This is from a main function
The env vars are as follows.
The args are as follows.
/wasi_example_main.wasm
50000000
File content is This is in a file

那么就配置成功了。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值