stackconf 2024 | Ignite: Is rust good for Kubernetes by Natalie Serebryakova .pdf

NETWAYS 52 views 19 slides Jul 25, 2024
Slide 1
Slide 1 of 19
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16
Slide 17
17
Slide 18
18
Slide 19
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...


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

Deploying the operator
1.kubectl apply -f local-pv.yaml
2.kubectl apply -f local-pvc.yaml

Running the operator

Summary
Developed Operator ensures data persistence in a Kubernetes cluster by managing
the underlying storage infrastructure .

THANK YOU