Skip to content

KubeEdge

Matthijs Jansen edited this page Apr 30, 2021 · 47 revisions

How to run KubeEdge locally

Using KVM to run KubeEdge on your local machine

KubeEdge documentation:

Setting up the machines

  1. Get the Ubuntu 20.04 server iso: https://releases.ubuntu.com/20.04/
  2. Install KVM: https://linuxize.com/post/how-to-install-kvm-on-ubuntu-20-04/

To manage VMs, either use the virsh command, the qemu-system-x86_64 command , or use the Virtual Machine Manager application (GUI).

  1. Create a VM called 'template' using the Ubuntu 20.04 iso. Install the OpenSSH server (this is an option during the installation). Keep this VM as is, we will clone it to create VMs we will actually use. In this way if a VM gets corrupted in some way and you need a new one, you can simply clone this template without having to install Ubuntu from scratch.
  2. Clone the template VM three times, call the first VM 'cloud', the second VM 'edge1' and the third 'endpoint1'. These will represent a single KubeEdge cloudcore, edgecore and endpoint system.
  3. Change the IP of the VMs: https://bobcares.com/blog/virsh-set-ip-address/ and https://serverfault.com/questions/627238/kvm-libvirt-how-to-configure-static-guest-ip-addresses-on-the-virtualisation-ho

To login via SSH, start the VM and do ssh username@ip with the username being the one you chose during installation, and the ip you can find via: https://www.cyberciti.biz/faq/find-ip-address-of-linux-kvm-guest-virtual-machine/

  1. Change the hostname of the VMs to 'cloud', 'edge1' and 'endpoint1': Either use sudo hostnamectl set-hostname 'name' or https://www.cyberciti.biz/faq/ubuntu-change-hostname-command/
  2. Check if the host can see both VMs and the VMs can see each other and the host by using the 'ping' command.

Setting up Kubernetes

Inspired by: https://www.linuxtechi.com/install-kubernetes-k8s-on-ubuntu-20-04/
Do the following steps on the cloud and edge VM:

  1. Disable swap. First check if swap is enabled: swapon -s. If there is no output, swap is disabled. Otherwise, edit /etc/fstab by commenting out the line with 'swap' in it.
  2. Enable ipv4 forwarding: Uncomment the line 'net.ipv4.ip_forward=1' in /etc/sysctl.conf
  3. Install docker: sudo apt update and sudo apt install -y docker.io, then start docker sudo systemctl enable docker.service --now and check if it is correctly started systemctl status docker. If docker doesn't work for some reason, try to install version 19.03.

Do the following steps on the cloud VM only:

  1. Install kubernetes (version 1.19.0 for KubeEdge 1.6.1): sudo apt install -y apt-transport-https curl and curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add and sudo apt-add-repository "deb http://apt.kubernetes.io/ kubernetes-xenial main" and sudo apt update and finally sudo apt install -y kubelet=1.19.0-00 kubeadm=1.19.0-00 kubectl=1.19.0-00
  2. Initialize kubernetes: sudo kubeadm init (note: kubernetes now uses cgroup as the docker driver, not the recommended systemd)
  3. Start using the cluster: mkdir -p $HOME/.kube and sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config and sudo chown $(id -u):$(id -g) $HOME/.kube/config

Setting up KubeEdge

Do the following step on the cloud and edge VM:

  1. Get keadm: wget https://github.com/kubeedge/kubeedge/releases/download/v1.6.1/keadm-v1.6.1-linux-amd64.tar.gz. Extract it: tar -xvf keadm-v1.6.1-linux-amd64.tar.gz. Make it an executable: cd keadm-v1.6.1-linux-amd64/keadm && chmod +x keadm && sudo mv keadm /usr/local/bin

Do the following steps on the cloud VM only:

  1. Create a symbolic link so keadm can find kubernetes: sudo ln -s ~/.kube /root
  2. Start keadm: sudo keadm init --advertise-address="cloud-ip-here" --kubeedge-version=1.6.1
  3. Get the token which is used to join the edge VM: sudo keadm gettoken. Don't forget this token.

Do the following steps on the edge VM only:

  1. Join the cloudcore and install mandatory software (such as mosquito): sudo keadm join --cloudcore-ipport=cloud_ip_here:10000 --token=token_from_previous_step

Do the following step on the cloud VM only:

  1. Check if the setup has succeeded: kubectl get nodes. The cloud VM should have status 'NotReady', while the edge VM should have status 'Ready' and as version kubeedge. kubectl describe nodes edge1 should show the resources of the edge VM that are available to the cloudcore.

Enable the Metrics-server

TODO: see https://github.com/kubeedge/kubeedge/blob/master/docs/setup/keadm.md

Stop the cluster

Do the following step on both the cloud and edge VM:

  1. Stop KubeEdge: sudo keadm reset. To start KubeEdge next time, repeat step 3, 4 and 5 from the "Setting up KubeEdge" section.

Do the following step on the cloud VM only:

  1. (Optional) Stop Kubernetes: sudo kubeadm reset and rm -rf ~/.kube. To start Kubernetes next time, repeat step 5 and 6 from the "Setting up Kubernetes" section.

Run example application

Source: https://github.com/kubeedge/examples/blob/master/apache-beam-analysis/README.md Do the following step on both the cloud and endpoint VM:

  1. Clone the examples git: git clone https://github.com/kubeedge/examples.git

Do the following step on the cloud VM only:

  1. Get the container with the app: sudo docker pull containerise/ke_apache_beam:ke_apache_analysis_v1.1. Check if the image is correctly downloaded: docker images
  2. Deploy the app: kubectl apply -f ~/examples/apache-beam-analysis/deployment.yaml
  3. Check if the app is running: kubectl get pods

Do the following step on the endpoint VM only:

  1. Install go: wget https://dl.google.com/go/go1.14.1.linux-amd64.tar.gz, and sudo tar -xf go1.14.1.linux-amd64.tar.gz -C /usr/local, then add the following line to ~/.profile: export PATH=$PATH:/usr/local/go/bin and reload the environment: source ~/.profile. Finally test if it works: go version
  2. Get go app dependencies: go get -u github.com/yosssi/gmq/mqtt and go get -u github.com/yosssi/gmq/mqtt/client
  3. Run the app: cd examples/apache-beam-analysis/MQTT_Publisher/, do vim testmachines.go and change the ip address on line 88 to the ip of the edge vm, then do go build testmachine.go and ./testmachine

TODO: This doesn't work yet

Common Kubernetes / KubeEdge commands

For the cloud VM only:

  • Get deployment plans / pods: kubectl get pods
  • Get all kubernetes connected nodes: kubectl get nodes
  • Delete pod / deployment: kubectl delete -f <path-to-config-yaml>
  • Delete node: kubectl delete node <nodename>
  • Get pod details: kubectl describe pods <podname>
  • Get logs: less /var/log/kubeedge/cloudcore.log

For the edge VM only:

  • Get logs: journalctl -u edgecore.service -b
Clone this wiki locally