-
Notifications
You must be signed in to change notification settings - Fork 0
KubeEdge
Using KVM to run KubeEdge on your local machine
KubeEdge documentation:
- https://github.com/kubeedge/kubeedge/blob/master/docs/getting-started.md
- https://github.com/kubeedge/kubeedge/blob/master/docs/setup/keadm.md
- https://github.com/kubeedge/examples/blob/master/apache-beam-analysis/README.md
- Get the Ubuntu 20.04 server iso: https://releases.ubuntu.com/20.04/
- 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).
- 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.
- 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.
- 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/
- 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/ - Check if the host can see both VMs and the VMs can see each other and the host by using the 'ping' command.
Inspired by: https://www.linuxtechi.com/install-kubernetes-k8s-on-ubuntu-20-04/
Do the following steps on the cloud and edge VM:
- 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. - Enable ipv4 forwarding: Uncomment the line 'net.ipv4.ip_forward=1' in /etc/sysctl.conf
- Install docker:
sudo apt update
andsudo apt install -y docker.io
, then start dockersudo systemctl enable docker.service --now
and check if it is correctly startedsystemctl status docker
Do the following steps on the cloud VM only:
- Install kubernetes (version 1.21.0 at the time of writing):
sudo apt install -y apt-transport-https curl
andcurl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add
andsudo apt-add-repository "deb http://apt.kubernetes.io/ kubernetes-xenial main"
andsudo apt update
and finallysudo apt install -y kubelet kubeadm kubectl
- Initialize kubernetes:
sudo kubeadm init
(note: kubernetes now uses cgroup as the docker driver, not the recommended systemd) - Start using the cluster:
mkdir -p $HOME/.kube
andsudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
andsudo chown $(id -u):$(id -g) $HOME/.kube/config
Do the following step on the cloud and edge VM:
- 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
Do the following steps on the cloud VM only:
- Create a symbolic link so keadm can find kubernetes:
sudo ln -s ~/.kube /root
- Execute keadm:
cd keadm-v1.6.1-linux-amd64/keadm
and thensudo ./keadm init --advertise-address="cloud-ip-here"
- 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:
- Join the cloudcore and install mandatory software (such as mosquito):
cd keadm-v1.6.1-linux-amd64/keadm
andsudo ./keadm join --cloudcore-ipport=cloud_ip_here:10000 --token=token_from_previous_step
Do the following step on the cloud VM only:
- 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
TODO: see https://github.com/kubeedge/kubeedge/blob/master/docs/setup/keadm.md
Do the following step on both the cloud and edge VM:
-
sudo ./keadm reset
. To start KubeEdge next time, repeat step 3, 4 and 5 from the "Setting up KubeEdge" section.
Source: https://github.com/kubeedge/examples/blob/master/apache-beam-analysis/README.md Do the following step on both the cloud and endpoint VM:
- Clone the examples git:
git clone https://github.com/kubeedge/examples.git
Do the following step on the cloud VM only:
- 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
- Deploy the app:
kubectl apply -f examples/apache-beam-analysis/deployment.yaml
- Check if the app is running:
kubectl get pods
Do the following step on the endpoint VM only:
- Install go:
wget https://dl.google.com/go/go1.14.1.linux-amd64.tar.gz
, andsudo 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
- Get go app dependencies:
go get -u github.com/yosssi/gmq/mqtt
andgo get -u github.com/yosssi/gmq/mqtt/client
- Run the app:
cd examples/apache-beam-analysis/MQTT_Publisher/
, dovim testmachines.go
and change the ip address on line 88 to the ip of the edge vm, then dogo build testmachine.go
and./testmachine
TODO: This doesn't work yet
For the cloud VM only:
- Get deployment plans / pods:
kubectl get pods
- Get all kubernetes connected nodes:
kubectl get nodes
- Delete pod:
kubectl delete -f <path-to-config-yaml>
orkubectl delete pod <podname> --grace-period=0 --force
- 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