---
# System prepended metadata

title: KubeEdge Setup

---

# How To Setup KubeEdge By Keadm

## What we need:
- Minimum 2 VM with 2 CPU and 2GB RAM. Set static IP to both VM
- 1 VM will act as K8s Master node, 1 VM will act as Edge Node
- 192.x.x.x/X network range with static IPs for master and worker nodes. i will be using the 10.x.x.x series as the pod network range that will be used by the Calico network plugin. Make sure the Node IP range and pod IP range don’t overlap. If your IP in 10.x.x.x range, use 192.168.0.0/16 as the POD CIDR.
- Make sure both kubernetes and kubeedge version compatible. (refer to https://github.com/kubeedge/kubeedge#kubernetes-compatibility)

## In this doc, we will:
1. Setting up a Kubernetes cluster (only master node)
2. Setup Cloud side (CloudCore) for the master node
3. Setup edge side (EdgeCore) for the edge node

---
## Setting Static IP (skip for openstack)
```sudo nano /etc/netplan/01-network-manager-all.yaml```
```
network:
  version: 2
  renderer: NetworkManager
  ethernets:
    enp0s3:
      dhcp4: no
      addresses:
        [Your IP/24]
      routes:
      - to: default
        via: 192.168.1.1
      nameservers:
          addresses: [8.8.8.8, 1.1.1.1] 
```
```sudo netplan apply ```


## **Do the following in Master node:**

**Disable swap**
```
sudo swapoff -a
(crontab -l 2>/dev/null; echo "@reboot /sbin/swapoff -a") | crontab - || true
```

**Disable firewall**
```
sudo ufw disable
```

## Install Go
- Choose whichever version
```
wget https://golang.org/dl/go1.17.3.linux-amd64.tar.gz
tar xzvf go1.17.3.linux-amd64.tar.gz

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

#output
go version go1.17.3 linux/amd64 
```
![image](https://hackmd.io/_uploads/SJaHi3Qip.png)

---
</br>


## Install CRI (i'm using CRI-O)
``` 
#Create the .conf file to load the modules at bootup
cat <<EOF | sudo tee /etc/modules-load.d/k8s.conf
overlay
br_netfilter
EOF

sudo modprobe overlay
sudo modprobe br_netfilter

# sysctl params required by setup, params persist across reboots
cat <<EOF | sudo tee /etc/sysctl.d/k8s.conf
net.bridge.bridge-nf-call-iptables  = 1
net.bridge.bridge-nf-call-ip6tables = 1
net.ipv4.ip_forward                 = 1
EOF

sudo sysctl --system

# Adjust to version you are using
OS="xUbuntu_22.04"

VERSION="1.28"

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 -y

```
- CNI  plugin configuration (refer to https://github.com/cri-o/cri-o/blob/main/contrib/cni/README.md)
```
#CNI plugin installation 
git clone https://github.com/containernetworking/plugins
cd plugins
git checkout v1.1.1
./build_linux.sh

#Install the CNI Plugin
sudo mkdir -p /opt/cni/bin
sudo cp bin/* /opt/cni/bin/

#Reload the updated config
sudo systemctl daemon-reload
sudo systemctl enable crio --now
sudo systemctl status cri-o
```
---
## Install Kubernetes
**Install dependencies**
```
sudo apt-get update
sudo apt-get install -y apt-transport-https ca-certificates curl
```
</br>

**Download the GPG key for the Kubernetes APT repository.**
```
sudo curl -fsSLo /usr/share/keyrings/kubernetes-archive-keyring.gpg https://dl.k8s.io/apt/doc/apt-key.gpg

```

</br>**Add the Kubernetes APT repository to your system.**
```
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-get update -y
```

</br>**Install kubelet, kubectl and kubeadm by compatible version for kubeedge**
I use K8s v1.26.7 and KubeEdge v1.15.2

```sudo apt-get install -y kubelet=1.xx.x-00 kubectl=1.xx.x-00 kubeadm=1.xx.x-00```


</br>**(Optional) Prevent upgrade**
```sudo apt-mark hold kubelet kubeadm kubectl```



</br>**Initialize kubeadm**

```sudo kubeadm init --apiserver-advertise-address=<ip_VM> --pod-network-cidr=10.85.0.0/16  --ignore-preflight-errors=all --kubernetes-version=vx.xx.x --v=5 ```
![image](https://hackmd.io/_uploads/HJ_21Tmj6.png)



</br>**Deploy Calico network plugin**
```
kubectl create -f https://raw.githubusercontent.com/projectcalico/calico/v3.26.1/manifests/tigera-operator.yaml

curl https://raw.githubusercontent.com/projectcalico/calico/v3.26.1/manifests/custom-resources.yaml -O

kubectl create -f custom-resources.yaml 
```
---
## **Setup CloudCore  in Master Node:**
```
wget https://github.com/kubeedge/kubeedge/releases/download/v1.15.2/keadm-v1.15.2-linux-amd64.tar.gz
tar -zxvf keadm-v1.15.2-linux-amd64.tar.gz
sudo cp keadm-v1.15.2-linux-amd64/keadm/keadm /usr/local/bin/keadm 
```
- Keadm Init
```
sudo keadm init --advertise-address=<IP master node> --kube-config=/home/${user}/.kube/config --kubeedge-version=v1.15.2
```
Output:
![image](https://hackmd.io/_uploads/HJiMhCbsp.png)
Note: Read https://kubeedge.io/docs/faq/setup/#timed-out-waiting-for-the-condition if error timeout 

![image](https://hackmd.io/_uploads/rynQn0-oa.png)

---

## **Setup EdgeCore  in Edge Node (Other VM):**
- Do from https://hackmd.io/ijx8I0GpRg-U7q_DI6RxDQ?both#Setting-Static-IP-skip-for-openstack to https://hackmd.io/ijx8I0GpRg-U7q_DI6RxDQ#Install-CRI-im-using-CRI-O

### **Get Token From Cloud Side**
Run keadm gettoken on the cloud side will return the token, which will be used when joining edge nodes.

```sudo keadm gettoken --kube-config=/home/${user}/.kube/config```

### **Download KubeEdge and join edge nodes**
```
wget https://github.com/kubeedge/kubeedge/releases/download/v1.15.2/keadm-v1.15.2-linux-amd64.tar.gz
tar -zxvf keadm-v1.15.2-linux-amd64.tar.gz
sudo cp keadm-v1.15.2-linux-amd64/keadm/keadm /usr/local/bin/keadm 

sudo keadm join \
--cloudcore-ipport=<IP Cloud Side>:10000 \
--edgenode-name=edge \
--token=b4550d45b773c0480446277eed1358dcd8a02a0c214646a8082d775f9c447d81.eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE2Mzg4ODUzNzd9.A9WOYJFrgL2swVGnydpb4gMojyvyoNPCXaA4rXGowqU \
--remote-runtime-endpoint=unix:///var/run/crio/crio.sock \
--runtimetype=remote \
--cgroupdriver=systemd \
--kubeedge-version=v1.15.2

```
![image](https://hackmd.io/_uploads/BJwsvTXoa.png)

![image](https://hackmd.io/_uploads/ByOoixGj6.png)

Written and tested by #INU