Slide 1

Slide 1 text

@deepu105 @oktaDev Why did I build a Kubernetes Dashboard in Rust? Deepu K Sasidharan @deepu105 | deepu.tech

Slide 2

Slide 2 text

@deepu105 @oktaDev Hi, I’m Deepu K Sasidharan ➔ JHipster co-lead developer ➔ Java Champion ➔ Creator of KDash, JDL Studio ➔ Developer Advocate @ Auth0 by Okta ➔ Polyglot dev, OSS aficionado, author, speaker @deepu105 deepu.tech deepu105 deepu05

Slide 3

Slide 3 text

@deepu105 @oktaDev What is KDash?

Slide 4

Slide 4 text

@deepu105 @oktaDev KDash ● A simple terminal dashboard for Kubernetes ● Provides resource views, Node metrics, logs and common view features ● Resources utilizations for nodes, pods and namespaces based on metrics server. ● Context switching ● Easy full keyboard navigation and themes ● Open Source, MIT license https://github.com/kdash-rs/kdash

Slide 5

Slide 5 text

@deepu105 @oktaDev KDash - Context overview

Slide 6

Slide 6 text

@deepu105 @oktaDev KDash - Utilization metrics

Slide 7

Slide 7 text

@deepu105 @oktaDev Why did I build another Kubernetes dashboard?

Slide 8

Slide 8 text

@deepu105 @oktaDev Why another dashboard Kdash is obviously inspired by k9s, so why build another dashboard? ● User experience: I wanted the stuff that is most used easily available and a workflow suitable for daily use ● Better navigation: I wanted a better overview and keyboard shortcuts for everything ● Better metrics: I wanted to see better resource metrics for the cluster ● PoC for Rust tooling: I wanted to build something useful in Rust for the k8s space ● Speed: While Go based tooling can be almost as fast, I wanted to build something faster and efficient with Rust. Why not? ○ KDash uses way less memory/cpu than k9s and even Kubectl watch

Slide 9

Slide 9 text

@deepu105 @oktaDev Why Rust? Why not GoLang?

Slide 10

Slide 10 text

@deepu105 @oktaDev Rust = High level general purpose language ● Multi-paradigm, ideal for functional, imperative and even OOP ● Modern tooling ● Ideal for systems programming, embedded, web servers and more ● Memory safe ● Concurrent ● No garbage collection ● Performance focused ● Awesome community ● Most loved language in Stack Overflow survey for 6 years in a row

Slide 11

Slide 11 text

@deepu105 @oktaDev What is so special about Rust? https://deepu.tech/my-second-impression-of-rust/

Slide 12

Slide 12 text

@deepu105 @oktaDev “Rust throws around some buzz words in its docs, but they are not just marketing buzz, they actually mean it with full sincerity and they actually matter a lot”

Slide 13

Slide 13 text

@deepu105 @oktaDev Ownership and borrowing ● No garbage collection or any runtime memory management ● Memory is managed using lifetimes of variables using a borrow checker at compile time ● No pause times, no runtime overhead ● Efficient and very low memory usage ● Reference counting available when needed

Slide 14

Slide 14 text

@deepu105 @oktaDev Safety guarantee ● Memory safe ● Null safe ● Type safe ● Thread safe Rust is safe by default and you can write unsafe code only within unsafe code blocks

Slide 15

Slide 15 text

@deepu105 @oktaDev Memory safety “About 70% of all CVEs at Microsoft are memory safety issues. Two-thirds of Linux kernel vulnerabilities come from memory safety issues” ● No free after use errors ● No invalid pointer access ● No double free errors ● No undefined behaviours ● Memory safety is ensured by ownership mechanism ● Unsafe mode for manual memory management and memory unsafe code https://deepu.tech/memory-management-in-programming/

Slide 16

Slide 16 text

@deepu105 @oktaDev Null safety “NULL is the most dreaded feature and the worst invention in programming” ● No concept of NULL ● Optional monad is used for presence and absence of data

Slide 17

Slide 17 text

@deepu105 @oktaDev Thread safety “Fearless concurrency” ● Threads, coroutines and asynchronous concurrency ● Mutex and ARC for shared data concurrency ● Channels for message passing concurrency ● Data race is not possible in Rust ● No need for thread synchronization ● Memory and Type safety ensures thread safety

Slide 18

Slide 18 text

@deepu105 @oktaDev Zero cost abstractions “What you don’t use, you don’t pay for. And further: What you do use, you couldn’t hand code any better.” – Bjarne Stroustrup ● Your programming style or paradigm does not affect performance ● Number of abstractions does not affect performance as the compiler always translates your code to the best possible machine code ● You could not get more performance from hand written optimizations ● In-built abstractions are often more performant than hand written code ● Compiler produces identical assembly code for almost all variations

Slide 19

Slide 19 text

@deepu105 @oktaDev Zero cost abstractions

Slide 20

Slide 20 text

@deepu105 @oktaDev Immutable by default ● Variable are immutable by default, including references ● Mutations needs to explicitly declared at all stages using the mut keyword, like var declaration and method signatures ● Variables can be passed by value or reference, mutable or immutable

Slide 21

Slide 21 text

@deepu105 @oktaDev Pattern matching ● First class support ● Can be used for control flow in if, switch, while, for statements ● Can be used for error handling, optionals and so on ● Can be used for value assignments and for code blocks

Slide 22

Slide 22 text

@deepu105 @oktaDev Advanced generics, traits and types ● Advanced generics ○ Generics in types, structs, enums and functions ○ No performance impact due to zero cost abstractions ○ Generics with lifetime annotations ● Traits for shared behaviour ○ Default implementation for traits ○ Placeholders for traits, operator overloading ○ Trait bounds for Generics ○ Multiple and compound trait bounds ● Type aliasing and great type inference

Slide 23

Slide 23 text

@deepu105 @oktaDev Macros ● Meta programming ● Great for non generic reusable code ● Custom behaviours ● Declarative macros and Procedural macros

Slide 24

Slide 24 text

@deepu105 @oktaDev Tooling and community ● Hands down, one of the best compilers out there and great backward compatibility ● One of the best tooling you can find in terms of features and developer experience. Cargo is one stop shop for Rust tooling, build, compilation, formatting, linting, and so on ● One of the best documentation, which is shipped with the tooling ● A very diverse and vibrant community ○ Community formed from other languages hence bringing in best of many ○ Very welcoming and helpful ○ Rapidly maturing ecosystem with growing number of libraries and use cases ○ Has a forum which is used more than stack overflow for Rust ● Big names like Google, Apple, Microsoft, Amazon and Facebook are already behind rust and investing it. ● It’s on path to become the second supported language in Linux development. ● Use case has already extended to embedded, web assembly, kubernetes, web development, game development and even client side ● It’s only a matter of time until you can do any use case in Rust

Slide 25

Slide 25 text

@deepu105 @oktaDev Does that mean there is no downsides?

Slide 26

Slide 26 text

@deepu105 @oktaDev The downsides ● Complexity ● Steep learning curve ● Young and maturing ● Many ways to do the same thing (kind of like JS)

Slide 27

Slide 27 text

@deepu105 @oktaDev “Rust, not Firefox, is Mozilla’s greatest industry contribution” – TechRepublic

Slide 28

Slide 28 text

@deepu105 @oktaDev High level language compromise ● Safety ● Speed ● Abstractions Pick two

Slide 29

Slide 29 text

@deepu105 @oktaDev High level language compromise ● Safety ● Speed ● Abstractions With Rust we can get all three. Hence Rust is a high level language with performance and memory efficiency closest to a low level language. The only tradeoff you will make with Rust is the learning curve.

Slide 30

Slide 30 text

@deepu105 @oktaDev KDash architecture

Slide 31

Slide 31 text

@deepu105 @oktaDev Major Libraries used ● tui-rs: Library to build rich terminal user interfaces and dashboards ● Crossterm: Terminal manipulation library ● Tokio: An event-driven, non-blocking async I/O platform ● kube-rs (k8s-openapi, Openssl): Kubernetes client for Rust ● kubectl-view-allocations: Library to fetch resource allocations for k8s ● clap: Command line argument parser ● rust-clipboard: cross-platform library for OS-level clipboard management ● duct.rs: Library for running child processes ● Serde: Serialization and deserialization library

Slide 32

Slide 32 text

@deepu105 @oktaDev Data architecture ● Event driven ○ Async I/O using dedicated channels ● Multi threaded ○ Single data-store using ARC + Mutex ○ Separate threads for UI, streams, network and CMD ● Non-blocking UI ○ Only bottleneck is network I/O with kube-api-server

Slide 33

Slide 33 text

@deepu105 @oktaDev Challenges

Slide 34

Slide 34 text

@deepu105 @oktaDev Challenges ● Log streaming was blocking due to how the kube-rs lib works ○ Solution: Seperate thread for log streaming with tokio-streams ○ Some quirks exists and needs to be investigated and fixed ● UI was blocking and not very smooth ○ Solution: Seperate thread for network calls and event driven I/O ● Kube-rs version updates are coupled to another library used ○ No proper solution yet

Slide 35

Slide 35 text

@deepu105 @oktaDev Thank You Deepu K Sasidharan @deepu105 | deepu.tech https://deepu.tech/tags#rust https://developer.auth0.com

Slide 36

Slide 36 text

@deepu105 @oktaDev https://github.com/deepu105/battleship-rs