@startuml K3s Infrastructure Sequence Diagram skinparam sequenceMessageAlign center skinparam responseMessageBelowArrow true title K3s Kubernetes Cluster Deployment - Sequence Diagram actor "DevOps Engineer" as client participant "Terraform CLI" as terraform participant "K3s Install Module" as module participant "SSH Connection" as ssh participant "Server Node" as server participant "Worker Node 1" as worker1 participant "Worker Node 2" as worker2 == Infrastructure Initialization == client -> terraform: terraform init terraform -> client: Providers initialized == Deployment Planning == client -> terraform: terraform plan terraform -> module: Parse variables module -> terraform: Show planned resources terraform -> client: Display execution plan == Infrastructure Deployment == client -> terraform: terraform apply terraform -> module: Execute installation == SSH Configuration == module -> module: Create temporary SSH config note right: Creates secure SSH configuration for all nodes == Server Provisioning == module -> ssh: Establish connection to server ssh -> server: Connect module -> server: Install K3s server component note right Uses curl to download K3s installer Configures K3s as server node end note server --> module: Installation complete == Kubeconfig Retrieval == module -> server: Request kubeconfig server -> server: Copy k3s.yaml to /tmp server --> module: Kubeconfig available module -> module: Download kubeconfig module -> module: Update server URL in config note right: Replaces 127.0.0.1 with actual server address == Node Token Handling == module -> server: Request node token server -> server: Extract node token server --> module: Node token available module -> module: Download node token == Worker Node Provisioning == group Worker Node Installation [Parallel execution] module -> ssh: Connect to Worker Node 1 ssh -> worker1: Connect module -> worker1: Transfer node token module -> worker1: Install K3s agent note right Installs K3s in agent mode Uses token to join the cluster end note worker1 --> module: Installation complete module -> ssh: Connect to Worker Node 2 ssh -> worker2: Connect module -> worker2: Transfer node token module -> worker2: Install K3s agent worker2 --> module: Installation complete end == Completion == module --> terraform: All resources provisioned terraform --> client: Infrastructure deployment complete == Cluster Usage == client -> server: Access Kubernetes via kubeconfig note right: Uses kubectl with the generated configuration == Destruction (Optional) == client -> terraform: terraform destroy terraform -> module: Initiate cleanup module -> worker1: Run agent uninstall script worker1 --> module: Agent uninstalled module -> worker2: Run agent uninstall script worker2 --> module: Agent uninstalled module -> server: Run server uninstall script server --> module: Server uninstalled module --> terraform: All resources cleaned up terraform --> client: Infrastructure destroyed footer K3s Infrastructure Sequence Diagram - Version 1.0 @enduml