stackconf 2024 | Ignite: Is rust good for Kubernetes by Natalie Serebryakova .pdf
NETWAYS
52 views
19 slides
Jul 25, 2024
Slide 1 of 19
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
About This Presentation
Rust is a powerful and safe systems programming language that has been gaining popularity among developers due to its emphasis on safety, speed, and concurrency. Kubernetes, on the other hand, is an open-source container orchestration platform that automates deploying, scaling, and managing containe...
Rust is a powerful and safe systems programming language that has been gaining popularity among developers due to its emphasis on safety, speed, and concurrency. Kubernetes, on the other hand, is an open-source container orchestration platform that automates deploying, scaling, and managing containerized applications written in Go.
This talk will cover how easy it is to develop Rust-based Operators in Kubernetes using an example of an operator for Managing the PVC Lifecycle.
Size: 2.86 MB
Language: en
Added: Jul 25, 2024
Slides: 19 pages
Slide Content
Is Rust good for Kubernetes?
Natalie Serebryakova
Whoami
●My name is Natalie
●I'm a Staff Cloud Engineer
●LinkedIn: https://www.linkedin.com/in/login-id/
●AWS Community Builder
●AWS User Group co-organizer
Agenda
●Kubernetes Operator
●Using Rust to develop Kubernetes Operator (PVC, PV)
●Demo using PVC Operator example
●Summary
Kubernetes Operators (Custom controllers)
Operators let you use custom app-specific object types to automate the
underlying Kubernetes configuration.
How Kubernetes Operators used?
●Kubernetes Operators are processes that connect to the Kubernetes API and
watch for events (typically on a limited number of resource types).
●When a relevant event occurs, the operator reacts and performs a specific
action
Why to use Rust for Kubernetes ecosystem?
Feature Go Rust
Performance✅ Good enough
✅ low-level control over memory management
✅ compiler optimizations
✅ and concurrency features
Concurrency
✅ Goroutines and channels
for concurrency
Async/await syntax :
✅ require finer control over concurrency
✅ error handling
✅ have performance-critical asynchronous tasks
Safety
✅ Strong typing, but lacks
memory safety checks
✅ Strong typing with rigorous (guaranteed)
memory safety checks
Majority K8s ecosystem (as of today) is build in Go. Is there benefit of using Rust?
Building Kubernetes Operators PVC with Rust
•Kubernetes Operator can automate the management of PVCs and PVs, handling
lifecycle events like creation, deletion, scaling, and backup/restoration
To build Kubernetes Operators using Rust in Kubernetes clusters we will need to Extend
Kubernetes API with Custom Resource Definitions (CRDs) to support
•PersistentVolumeClaims (PVCs): PVCs request specific size and access modes (e.g.,
read/write) for storage from Persistent Volumes (PVs).
•PersistentVolumes (PVs): PVs are the storage resources in the cluster. Each PV
corresponds to a PVC's request.
Building and deploying K8s Operator with Rust
●Rust Environment: Ensure Rust and Cargo are installed.
●Kubernetes Cluster: A Minikube or any Kubernetes cluster.
●Docker: For building and pushing the operator's container image.
●kubectl: For interacting with the Kubernetes cluster.
●kube-rs, kuberntes-openapi, tokio, serde, log Crates: Required Rust crates.
Rust crates to use
kube-rs and kubernetes-openapi are Rust crates specifically designed to support
the development of Kubernetes operators.
-kube-rs:
●Provides useful abstractions over Kubernetes API
●Simplifies handling of Custom Resource Definitions (CRDs)
-kubernetes-openapi:
●Used by kube-rs for Kubernetes API interaction
●Enhancing operator development capabilities.
Best practices for writing Kubernetes Operators
1. Define clear Custom Resources (CRDs) and associated control loops
2. Follow K8s API conventions, client libraries
3. Handle state properly
4. Incorporate error handling
5. Secure your Operator
6. Document your Operator
Kubernetes Client configuration
●Initialize the Kubernetes client for interacting with the cluster, leveraging the default
Controller Components
●Struct holds configuration that affects the controller's behavior, such as default
values for storage classes or thresholds for certain operations.
Creating Custom Controller
Creating Custom Controller
Packaging the operator
“Package” into the container by creating a Dockerfile:
Run :
docker build -t yourusername/k8s_pvc_operator:v1 .
docker push yourusername/ k8s_pvc_operator:v1