Monitoring Weather At The Edge With K3s and Raspberry Pi Devices
Speaker: Sergio Méndez
Summary
This talk looks at utilizing Kubernetes at the edge with K3s and Raspberry Pi devices for monitoring weather. Sergio Méndez, differentiates between IoT (Internet of Things) and Edge Computing, emphasizing that while they are often used interchangeably, they serve different purposes. IoT is more about devices connected over the internet, while Edge Computing focuses on processing data closer to the source. Sergio demonstrates a real-time weather monitoring system using Raspberry Pi, K3s, and various sensors. He showcases how temperature and humidity can be tracked and visualized in real time using Grafana dashboards.
Transcription
Hi, welcome. This is maybe a little bit different kind of conference. Well, it's something like, I am going to show you how to run Kubernetes at the edge using K3s. My talk is called "Monitoring Weather at the Edge with K3s and Raspberry Pi Devices". So, we are going to measure the weather in Tampa. Just let me...
IoT and Edge Computing, they are not the same things. IoT, well, people refer more to devices connected over the internet. But Edge Computing refers more to processing the data near to the edge. The differences might be where you are going to process the thing, what type of devices you are going to use. But in reality, IoT and Edge Computing are complementary. In Edge Computing, you might want to distribute the information across different devices and in the cloud. IoT refers more to getting that information with sensors, with just small devices.
IoT and Edge Computing are different. IoT is more about processing one task at a time. Edge Computing can process different tasks at the same time. You might need more power for processing. IoT uses microcontrollers, Edge Computing uses microprocessors. Let's say that in Edge Computing you are using microcomputers, and in IoT just devices with sensors. Something that's common right now is that in Edge Computing, a lot of people are using AR because AR doesn't consume a lot of resources in terms of energy and has a reasonable way to process the information.
As we mentioned, IoT and Edge Computing are complementary. But we can say that Edge Computing is like the next step of evolution of IoT. They are complementary, but as you can see, a lot of people are saying "Edge Computing at the edge" and similar terms. Talking about technology, some people refer to IoT and Edge as the same thing. It's not true, but they are complementary. If we say that Edge Computing refers to processing the data near the source, for example, I have a smartphone here. I am generating the information here. I am going to process the information on my device, on my smartphone. Maybe it's possible that I can send some portion of that to the cloud, some portion of the information locally. And I can complement that system with all that information. Maybe the information is on a lot of different edge or local devices. Maybe we can say local, and that information is processed locally. When the device finishes processing, maybe that information moves to the cloud. Maybe you can check that information later in another location, maybe in another country. Or maybe you want to create a dashboard with all the information about different edge devices in different locations around the world. That's the reality.
Some Edge Computing use cases could be smart farms, smart gardens. For example, you might want to play a little bit with ARM devices. A cool use case to try could be a smart garden, something to control your plants and flowers at home. Just to measure the weather. And if it's a little dry, I have to water my flowers. That could be an interesting use case. I am from Guatemala, I'm Sergio Méndez. In Guatemala, there are a lot of farmers. I think that my country needs Edge Computing to process information locally about their plants. Smart farms and smart gardens are a really nice idea to implement. You can use these systems for other systems, security cameras. Maybe you want to implement something that stops your dog when the door is open.
For Edge Computing, I remember someone here at Civo Navigate talking about factor learning. Different edge devices in different locations, maybe, for example, C Navigate, could be different edge devices in the theater, on the rooftop. Maybe you are sending information about how a talk is going, or getting information on how many people are there. And you want to get all the information together and show it in a Grafana dashboard in the main entrance. We can do that with Edge Computing without using Wi-Fi. Maybe we can use other protocols like LoRa that can send information across, let's say, from 1 to 10 kilometers using one battery. Instead of using Wi-Fi or an expensive Wi-Fi connection to send information, you can also use Edge Computing to collect location information like GPS coordinates. For example, your car is moving and is getting the information like the Waze application. But Waze uses the smartphone as the edge device. Let's say that Waze is an Edge Computing system, but a bigger one. You can implement a geolocation application, GPS applications. That is the same forecast that we are going to do. Not to predict, just getting the information. But you can get that information to create a machine learning model to predict the weather in some days. Maybe you want to buy a farm and monitor your farm remotely with that edge device. It's one of those use case applications.
If there's something new here, well, Kubernetes in that context is a powerful tool that can help you create a distributed system. A distributed system is a system created with a lot of machines, maybe more than 20 machines in different locations. But these machines in different locations are not all together in a data center. Kubernetes is going to give you the power of that. Some people who just know about edge or hardware tools like Arduino can take advantage of Kubernetes to create your distributed system to automate how to update those edge applications on your device. That's the benefit of Kubernetes. Pushing people to start learning best practices of DevOps to implement their systems. But it's more than that. K3s, as we know, SIO is made with K3s inside.
Kubernetes is a lightweight Kubernetes called K3s. SIO is an example of a cloud that is using K3s. I think it's maybe the only big cloud that is using K3s right now, the bigger and the stable one. Who knows if there's another cloud? I use K3s to run on my edge devices. In this example, I am going to use Raspberry Pis. You are going to see my Raspberry Pis now. K3s is really nice. It has all the features in one single binary that is about 100 megabytes. It's pretty small and includes Docker and all the things you need to run Kubernetes. K3s eliminates all the unnecessary things to run your cluster. It's designed to run on bare metal, on your hardware, on your small devices. It has some interesting tools like using MySQL instead of etcd. Maybe you can have that information in the cloud instead of the local etcd, maybe MySQL on the cloud hosted on GCP, Azure, or AWS, whatever you want.
K3s includes all the things you need. K3s is a CNCF Sandbox project right now. And as I mentioned, Kubernetes can give you the whole automation for your applications and the scaling power for your system, in this case for Edge Computing. ARM, on the other hand, is a microprocessor. It's not as powerful as Intel but consumes less energy. It's cheaper for edge devices to run just with a single battery. An ARM might last, let's say, 3 hours, and Intel only 30 minutes.
Just to give an example, it's not real information. But it's different. Intel has more power but consumes more energy. A Raspberry Pi, this is an example, a non-production example because a Raspberry Pi was created for learning purposes, for prototype purposes. But some people use Raspberry Pis for production. There are different cluster configurations, single clusters, and there are different challenges, as we mentioned, like energy consumption. We are going to show the temperature and humidity in real time, something you can apply to measure at your garden with your plants and flowers.
Let's create your system. I am using a Raspberry Pi, some micro SD cards for my operating system, a switch, and a Key Studio Raspberry Pi starter kit with a lot of electronic stuff. You install all the things, prepare your Raspberry Pi, install K3s with a single line command, and other software that you need to run things. Then you install MySQL and the Grafana dashboard and my edge client. But how does it look? Well, I have a picture here, maybe not to show with the camera, but it's the same picture. It's all the stuff that's running right here, the Raspberry Pi, the sensor that I am using. About how my system is designed, just to explain here, the DHT11 sensor is going to pick information using Python. And with this send Python script, it's going to send a request to a deployment that is deployed in my K3s cluster. And that information is going to be written on MySQL, and Grafana is going to read from that MySQL.
So, let's do it in real time. Right now, this is my cluster running the Grafana dashboard. And oh, let's run the client again. We are showing the temperature using Celsius and the humidity right here. Let me see...
Okay, here is the temperature in real time. Let me adjust the sensor a bit to update the information. You'll see a small change there. Right now, because I'm touching it, and let's say I'm a bit humid, it affects the sensor directly. Even the temperature is going to change in a few seconds. The red line represents the temperature, and the humidity is clearer. I'm touching the sensor, so you can do this in different locations, share data between the cloud and locally. It depends on your use case and what works better for you.
To give you an idea, everyone knows MySQL. I've created a small API to store the information read from the sensor. It's simple, not complicated. I believe that's the power of Edge Computing. If Edge Computing seems a bit weird or complicated, it's not. It's simpler than we think. It's about moving things locally, not just in the cloud. You can share information, and the challenges might be the sensors, but it's something we learned in university. For example, I wrote a book about this, and I started by buying a sensor and playing with it. It wasn't too complicated. The challenge is designing a system that's production-ready and can withstand bad weather conditions.
The concept is a distributed system. Currently, Kubernetes is most commonly used for distributed systems. How can I update my applications? Docker. If speed is necessary, maybe I have to program using assembler, but you can even use Docker and take advantage of such software.
This is the GitHub repository where you can check all the code samples, YAML files, Python code, slides, and additional resources. The last one is a full video that includes everything you need to deploy your own Kubernetes cluster. Let me show you a bit of this. The YAML files and Python code are straightforward. A few lines just calling an API. It's not complicated magic. It's straightforward. And because a lot of this content was extracted from my book, if you want to delve deeper or play with these technologies on weekends, you can refer to the book. It was interesting because I took portions of some chapters to create this demo. I was literally opening my book, thinking, "I'm going to play with this. I need these command lines, this example," and mixing things up.
If you want to contact me, that's my email and Twitter account. I constantly post about Edge Computing, small tips, how to use observability on Edge Computing, K3s, and more. In the future, I plan to create videos about these topics.
Do you have questions? For example, I used Ubuntu, which is more suitable for Raspberry Pi instead of Raspbian. To install K3s, did I use Kup, or did I go to the website and use the standard procedure? I believe Ubuntu is more suitable for production-ready environments. It's interesting that you mentioned people run Raspberry Pis in production. I've seen it used in meat processing factories with industrial-grade casings. They use it to connect machines with old protocols to translate serial interfaces to TCP, for example. There are many devices you can use, like Rock Pi or Orange Pi. The goal is to use an operating system that supports ARM, and you'll be fine.
Any other questions? It was a cool demo, very exciting. Do you have a list of components if I want to build this as an experiment? The DHT11 is a common sensor you can find anywhere. Follow Raspberry Pi tutorials to read the information from the port. All the code is in the GitHub repository. It's not complicated. No soldering is required. You can buy them on Amazon. For example, there's a converter to connect the sensor with just three cables. Install the libraries, run the Python code, and you're set. I think Raspberry Pis are a bit expensive right now. I want to try the Rock Pi or maybe the cheaper Orange Pi. Any other questions?
Okay, I got a question on the load balancer. I saw you were disabling the Traefik portion of it. Was it conflicting with MetalLB at that point?
Yes, I use MetalLB. So, for example, that's a big question when running things at the edge: how to manage the load balancer. MetalLB is one piece of software you can use. There's another one created by KubeSphere, which is like ELB or something like that. You can even use that. I think it runs pretty stable. But as you can see about the networking, I created that network there, but you reserve some portion of the network just for the load balancer IPs. The IP of the load balancer is higher, starting with 100, and the IP addresses that I am using for the nodes are lower, at the beginning. You can specify the portion of the network that you can use to assign IP addresses for the load balancer. It creates virtual IP addresses that you can ping inside the network. That's how MetalLB works.
Another challenge is my internet connection. I don't know why K3s asks for an internet connection. If there's no internet connection, maybe I'm missing some configuration, but the cluster doesn't get up. Maybe I'm missing something or I have to remove something, but you have to configure your network inside your devices to get the internet. If the internet is changing, because Kubernetes expects stable networking. Right now, I have a different network. I'm running things with my smartphone. My smartphone is providing all the internet information and the connection to install things. It's a bit tricky to configure your device for a stable internet connection, but it's possible. You're seeing this running. I'm not using the wireless here, just my internet from my smartphone.
There are solutions for that. I think that's one of the challenges of edge devices.
Your question?
I was going to ask if you tried running this on Raspberry Pi 2Ws or anything like that. But I looked up the prices, and those are around $65 average now. So, never mind, Rock Pi it is.
I think if you find something that uses ARM, you can try it. It's not a big deal. Maybe the only thing you have to do is recompile the container for a different architecture. It depends on what programming language you're using. With Python, it might be a bit complicated, but with Go, it's easier to change the architecture. So, in that way, you can decide which language is better for you. I said Python because it's easier to understand, but there are other languages. For instance, TinyGo is an optimized Go language just for edge devices. You can use TinyGo.
I think that's it. Thank you for attending my presentation. Thank you very much.
Stay up to date
Sign up to the Navigate mailing list and stay in the loop with all the latest updates and news about the event.