Home United States USA — software A Rust Controller for Kubernetes

A Rust Controller for Kubernetes

417
0
SHARE

To teach myself Kubernetes in general and controllers in particular, I previously developed one in Java. I decided to do the same in Rust by following the …
Join the DZone community and get the full member experience. To teach myself Kubernetes in general and controllers in particular, I previously developed one in Java. This week, I decided to do the same in Rust by following the same steps I did. The guiding principle is creating a Kubernetes controller that watches pods’ lifecycle and injects a sidecar into them. When Kubernetes schedules the pod, the controller schedules the sidecar; when it deletes the former, it deletes the latter as well. I understand this would be better handled by the out-of-the-box admission controller, but it’s a good learning exercise. Because of that, I approached the development through several steps: The original Java project used quite more steps, but they are not relevant for this post. This project is the first one on my Rust path in which I had to set up a project from scratch. All my previous work either used an existing project or copied a provided template. With cargo, it’s pretty straightforward: The initial structure is the following: With the following content: At this point, you can: 1. Build the package: 2. And run it: As expected, it outputs: We will start by replacing the out-of-the-box logging macro with a library with logging levels (debug, info, etc.). After some research, I found the log4rs crate: log4rs is a highly configurable logging framework modeled after Java’s Logback and log4j libraries. Given that I’ve don’t have enough perspective on the Rust library ecosystem, I chose log4rs because its design is similar to Log4J.

Continue reading...