feat: Add Kubernetes examples and update dependencies
- Add Kubernetes examples demonstrating deployment of various applications (PostgreSQL, Redis, generic). This improves the documentation and provides practical usage examples. - Add `tokio` dependency for async examples. This enables the use of asynchronous operations in the examples. - Add `once_cell` dependency for improved resource management in Kubernetes module. This allows efficient management of singletons and other resources.
This commit is contained in:
		| @@ -11,12 +11,50 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> { | ||||
|     // Create Kubernetes manager for the database namespace | ||||
|     let km = KubernetesManager::new("database").await?; | ||||
|  | ||||
|     // Create the namespace if it doesn't exist | ||||
|     println!("Creating namespace 'database' if it doesn't exist..."); | ||||
|     match km.namespace_create("database").await { | ||||
|         Ok(_) => println!("✓ Namespace 'database' created"), | ||||
|         Err(e) => { | ||||
|             if e.to_string().contains("already exists") { | ||||
|                 println!("✓ Namespace 'database' already exists"); | ||||
|             } else { | ||||
|                 return Err(e.into()); | ||||
|             } | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     // Clean up any existing resources first | ||||
|     println!("Cleaning up any existing PostgreSQL resources..."); | ||||
|     match km.deployment_delete("postgres-cluster").await { | ||||
|         Ok(_) => println!("✓ Deleted existing deployment"), | ||||
|         Err(_) => println!("✓ No existing deployment to delete"), | ||||
|     } | ||||
|  | ||||
|     match km.service_delete("postgres-cluster").await { | ||||
|         Ok(_) => println!("✓ Deleted existing service"), | ||||
|         Err(_) => println!("✓ No existing service to delete"), | ||||
|     } | ||||
|  | ||||
|     // Configure PostgreSQL-specific labels | ||||
|     let mut labels = HashMap::new(); | ||||
|     labels.insert("app".to_string(), "postgres-cluster".to_string()); | ||||
|     labels.insert("type".to_string(), "database".to_string()); | ||||
|     labels.insert("engine".to_string(), "postgresql".to_string()); | ||||
|  | ||||
|     // Configure PostgreSQL environment variables | ||||
|     let mut env_vars = HashMap::new(); | ||||
|     env_vars.insert("POSTGRES_DB".to_string(), "myapp".to_string()); | ||||
|     env_vars.insert("POSTGRES_USER".to_string(), "postgres".to_string()); | ||||
|     env_vars.insert( | ||||
|         "POSTGRES_PASSWORD".to_string(), | ||||
|         "secretpassword".to_string(), | ||||
|     ); | ||||
|     env_vars.insert( | ||||
|         "PGDATA".to_string(), | ||||
|         "/var/lib/postgresql/data/pgdata".to_string(), | ||||
|     ); | ||||
|  | ||||
|     // Deploy the PostgreSQL cluster using the convenience method | ||||
|     println!("Deploying PostgreSQL cluster..."); | ||||
|     km.deploy_application( | ||||
| @@ -25,6 +63,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> { | ||||
|         2,                  // replicas (1 master + 1 replica) | ||||
|         5432,               // port | ||||
|         Some(labels),       // labels | ||||
|         Some(env_vars),     // environment variables | ||||
|     ) | ||||
|     .await?; | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user