73 lines
2.4 KiB
Rust
73 lines
2.4 KiB
Rust
//! Redis Cluster Deployment Example
|
|
//!
|
|
//! This example shows how to deploy a Redis cluster using the
|
|
//! KubernetesManager convenience methods.
|
|
|
|
use sal_kubernetes::KubernetesManager;
|
|
use std::collections::HashMap;
|
|
|
|
#[tokio::main]
|
|
async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|
// Create Kubernetes manager for the cache namespace
|
|
let km = KubernetesManager::new("cache").await?;
|
|
|
|
// Configure Redis-specific labels
|
|
let mut labels = HashMap::new();
|
|
labels.insert("app".to_string(), "redis-cluster".to_string());
|
|
labels.insert("type".to_string(), "cache".to_string());
|
|
labels.insert("engine".to_string(), "redis".to_string());
|
|
|
|
// Deploy the Redis cluster using the convenience method
|
|
println!("Deploying Redis cluster...");
|
|
km.deploy_application(
|
|
"redis-cluster", // name
|
|
"redis:7-alpine", // image
|
|
3, // replicas (Redis cluster nodes)
|
|
6379, // port
|
|
Some(labels), // labels
|
|
)
|
|
.await?;
|
|
|
|
println!("✅ Redis cluster deployed successfully!");
|
|
|
|
// Check deployment status
|
|
let deployments = km.deployments_list().await?;
|
|
let redis_deployment = deployments
|
|
.iter()
|
|
.find(|d| d.metadata.name.as_ref() == Some(&"redis-cluster".to_string()));
|
|
|
|
if let Some(deployment) = redis_deployment {
|
|
let total_replicas = deployment
|
|
.spec
|
|
.as_ref()
|
|
.and_then(|s| s.replicas)
|
|
.unwrap_or(0);
|
|
let ready_replicas = deployment
|
|
.status
|
|
.as_ref()
|
|
.and_then(|s| s.ready_replicas)
|
|
.unwrap_or(0);
|
|
|
|
println!(
|
|
"Deployment status: {}/{} replicas ready",
|
|
ready_replicas, total_replicas
|
|
);
|
|
}
|
|
|
|
println!("\n📋 Connection Information:");
|
|
println!(" Host: redis-cluster.cache.svc.cluster.local");
|
|
println!(" Port: 6379");
|
|
println!(" Password: Configure REDIS_PASSWORD environment variable");
|
|
|
|
println!("\n🔧 To connect from another pod:");
|
|
println!(" redis-cli -h redis-cluster.cache.svc.cluster.local");
|
|
|
|
println!("\n💡 Next steps:");
|
|
println!(" • Configure Redis authentication with environment variables");
|
|
println!(" • Set up Redis clustering configuration");
|
|
println!(" • Add persistent volume claims for data persistence");
|
|
println!(" • Configure memory limits and eviction policies");
|
|
|
|
Ok(())
|
|
}
|