lmrc-kubernetes
Part of the LMRC Stack - Infrastructure-as-Code toolkit for building production-ready Rust applications
A comprehensive Rust library for managing Kubernetes resources with a focus on deployments, services, secrets, and cluster operations.
Features
Core Resources
- Deployments: Full lifecycle management with health probes, init containers, rolling updates, rollbacks, and scaling
- Services: ClusterIP, NodePort, and LoadBalancer support
- Secrets: Docker registry and generic secrets management
- Namespaces: Namespace creation and management
- ConfigMaps: Configuration data management with volume mounting
- Ingress: HTTP/HTTPS routing with TLS support and path-based routing
- Gateway API: Next-generation traffic management with Gateway and HTTPRoute resources
- NetworkPolicy: Network security and micro-segmentation with ingress/egress rules
- Jobs: Batch processing with parallelism, retries, and TTL
- CronJobs: Scheduled recurring tasks with cron syntax
- PersistentVolumeClaims: Persistent storage management with multiple access modes
- HorizontalPodAutoscaler: Auto-scaling based on CPU, memory, and custom metrics
Advanced Features
- Health probes (liveness, readiness, startup) with HTTP, TCP, and Exec support
- Init containers for initialization tasks
- Resource limits and requests (CPU and memory)
- Volume mounts (ConfigMap, Secret, EmptyDir, HostPath, PersistentVolumeClaim)
- Image pull secrets for private registries
- Service accounts for RBAC integration
- Command and args override for containers
- Pre-deployment validation
- Deployment strategies (RollingUpdate, Recreate)
- Multi-namespace support
- Label-based resource querying
Developer Experience
- Type-safe builder patterns throughout
- Comprehensive error types with detailed context
- Ergonomic API design
- Full async/await support with tokio
- 66 unit tests covering all functionality
Installation
Add this to your Cargo.toml:
[]
= "0.1"
= { = "1", = ["full"] }
Requirements
- Rust 1.70 or later
- Kubernetes cluster access (kubeconfig or in-cluster)
- Dependencies:
kube2.0+ for Kubernetes clientk8s-openapi0.26+ with v1_31 API supporttokiofor async runtime
Quick Start
use ;
use ;
use DeploymentOptions;
async
Usage Examples
Deployment with Resource Limits
use ;
let resources = new
.cpu_request
.cpu_limit
.memory_request
.memory_limit;
let container = new
.with_port
.with_resources;
let deployment = new
.with_replicas
.with_container;
Health Probes
use ;
let liveness = http
.initial_delay_seconds
.period_seconds;
let readiness = http
.initial_delay_seconds
.timeout_seconds;
let container = new
.with_liveness_probe
.with_readiness_probe;
ConfigMaps and Volume Mounts
use ConfigMapSpec;
use ;
// Create ConfigMap
let configmap = new
.with_data;
client.configmaps.apply.await?;
// Mount in deployment
let volume = from_configmap;
let container = new
.with_volume_mount;
Docker Registry Secrets
// Create a Docker registry secret
client.secrets
.apply_docker_registry_secret
.await?;
// Use in deployment
let deployment = new
.with_image_pull_secret
.with_container;
Service Creation
use ;
let service = new
.with_selector
.with_port
.with_type;
client.services.apply.await?;
Ingress with TLS
use ;
let rule = new
.with_path
.with_path;
let tls = new
.with_host
.with_secret_name;
let ingress = new
.with_rule
.with_tls;
client.ingress.apply.await?;
NetworkPolicy
use ;
let policy = new
.with_pod_selector
.with_ingress_rule
.with_policy_type;
client.network_policies.apply.await?;
Jobs
use JobSpec;
let job = new
.with_container
.with_parallelism
.with_completions
.with_backoff_limit;
client.jobs.apply.await?;
CronJobs
use CronJobSpec;
let cronjob = new
.with_container
.with_restart_policy;
client.cronjobs.apply.await?;
PersistentVolumeClaims
use ;
let pvc = new
.with_access_mode
.with_storage_class;
client.pvcs.apply.await?;
HorizontalPodAutoscaler
use ;
let hpa = new
.with_replicas
.with_metric;
client.hpas.apply.await?;
Rollback Deployment
use RollbackOptions;
let rollback_opts = new
.revision // Optional: specify revision
.timeout_secs;
client.deployments
.rollback
.await?;
Scale Deployment
// Scale to 10 replicas
client.deployments.scale.await?;
Multi-Namespace Operations
// Create clients for different namespaces
let prod_client = client.with_namespace;
let staging_client = client.with_namespace;
// Deploy to production
prod_client.deployments.apply.await?;
// Deploy to staging
staging_client.deployments.apply.await?;
Error Handling
The library provides comprehensive error types with detailed context:
use Error;
match client.deployments.apply.await
Architecture
The library is organized into focused modules:
client: Main client for accessing Kubernetes APIdeployment: Deployment specifications and managementservice: Service specifications and managementsecret: Secret managementnamespace: Namespace operationsconfigmap: ConfigMap managementingress: Ingress managementgateway: Gateway API managementnetworkpolicy: NetworkPolicy managementjob: Job managementcronjob: CronJob managementpvc: PersistentVolumeClaim managementhpa: HorizontalPodAutoscaler managementconfig: Configuration types and optionserror: Comprehensive error types
Testing
Run the test suite:
# Run unit tests
# Run with output
# Run specific test
# Check code quality
Contributing
Contributions are welcome! Please see CONTRIBUTING.md for guidelines.
License
Part of the LMRC Stack project. Licensed under either of:
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
Links
Changelog
See CHANGELOG.md for version history and release notes.