feat: Add K3s installer with complete lifecycle management

Implemented a production-ready K3s Kubernetes installer with full lifecycle
support including installation, startup management, and cleanup.

Key features:
- Install first master (cluster init), join additional masters (HA), and workers
- Systemd service management via StartupManager abstraction
- IPv6 support with Mycelium interface auto-detection
- Robust destroy/cleanup with proper ordering to prevent hanging
- Complete removal of services, processes, network interfaces, and data
This commit is contained in:
peternashaat
2025-11-27 14:01:22 +01:00
parent 449213681e
commit dc2f8c2976
4 changed files with 154 additions and 3 deletions

View File

@@ -24,7 +24,7 @@
k3s_version:'v1.33.1'
data_dir:'~/hero/var/k3s'
node_name:'master-1'
mycelium_interface:'mycelium0'
// mycelium_interface:'mycelium0' // Optional: auto-detected if not specified
// Install as first master (will generate token and use --cluster-init)
!!kubernetes_installer.install_master name:'k3s_master_1'
@@ -50,7 +50,7 @@
k3s_version:'v1.33.1'
data_dir:'~/hero/var/k3s'
node_name:'master-2'
mycelium_interface:'mycelium0'
// mycelium_interface:'mycelium0' // Optional: auto-detected if not specified
token:'<TOKEN_FROM_FIRST_MASTER>'
master_url:'https://[<MASTER_IPV6>]:6443'
@@ -73,7 +73,7 @@
k3s_version:'v1.33.1'
data_dir:'~/hero/var/k3s'
node_name:'worker-1'
mycelium_interface:'mycelium0'
// mycelium_interface:'mycelium0' // Optional: auto-detected if not specified
token:'<TOKEN_FROM_FIRST_MASTER>'
master_url:'https://[<MASTER_IPV6>]:6443'

View File

@@ -0,0 +1,54 @@
#!/usr/bin/env -S v -n -w -cg -gc none -cc tcc -d use_openssl -enable-globals run
import incubaid.herolib.core.playcmds
import incubaid.herolib.ui.console
// ============================================================================
// K3s Join Additional Master (HA Setup)
// ============================================================================
// This script shows how to join an additional master node to an existing
// K3s cluster for high availability.
//
// Prerequisites:
// 1. First master must be running
// 2. You need the token from the first master
// 3. You need the master URL (IPv6 address and port)
// ============================================================================
console.print_header('='.repeat(80))
console.print_header('K3s Join Additional Master Node')
console.print_header('='.repeat(80))
// IMPORTANT: Replace these values with your actual cluster information
// You can get these from the first master's join script or by running:
// !!kubernetes_installer.generate_join_script name:"k3s_master_1"
master_token := 'YOUR_CLUSTER_TOKEN_HERE' // Get from first master
master_url := 'https://[YOUR_MASTER_IPV6]:6443' // First master's IPv6 address
join_master_script := '
!!kubernetes_installer.configure
name:"k3s_master_2"
k3s_version:"v1.33.1"
data_dir:"~/hero/var/k3s"
node_name:"master-2"
mycelium_interface:"mycelium"
token:"${master_token}"
master_url:"${master_url}"
!!kubernetes_installer.join_master name:"k3s_master_2"
!!kubernetes_installer.start name:"k3s_master_2"
'
console.print_header('⚠️ Before running, make sure to:')
console.print_header(' 1. Update master_token with your cluster token')
console.print_header(' 2. Update master_url with your first master IPv6')
console.print_header(' 3. Ensure first master is running')
console.print_header('')
// Uncomment the line below to actually run the join
// playcmds.run(heroscript: join_master_script)!
console.print_header('✅ Script ready. Uncomment playcmds.run() to execute.')
console.print_header('='.repeat(80))

View File

@@ -0,0 +1,53 @@
#!/usr/bin/env -S v -n -w -cg -gc none -cc tcc -d use_openssl -enable-globals run
import incubaid.herolib.core.playcmds
import incubaid.herolib.ui.console
// ============================================================================
// K3s Join Worker Node
// ============================================================================
// This script shows how to join a worker node to an existing K3s cluster.
//
// Prerequisites:
// 1. At least one master must be running
// 2. You need the token from the master
// 3. You need the master URL (IPv6 address and port)
// ============================================================================
console.print_header('='.repeat(80))
console.print_header('K3s Join Worker Node')
console.print_header('='.repeat(80))
// IMPORTANT: Replace these values with your actual cluster information
// You can get these from the master's join script or by running:
// !!kubernetes_installer.generate_join_script name:"k3s_master_1"
master_token := 'YOUR_CLUSTER_TOKEN_HERE' // Get from master
master_url := 'https://[YOUR_MASTER_IPV6]:6443' // Master's IPv6 address
join_worker_script := '
!!kubernetes_installer.configure
name:"k3s_worker_1"
k3s_version:"v1.33.1"
data_dir:"~/hero/var/k3s"
node_name:"worker-1"
mycelium_interface:"mycelium"
token:"${master_token}"
master_url:"${master_url}"
!!kubernetes_installer.install_worker name:"k3s_worker_1"
!!kubernetes_installer.start name:"k3s_worker_1"
'
console.print_header('⚠️ Before running, make sure to:')
console.print_header(' 1. Update master_token with your cluster token')
console.print_header(' 2. Update master_url with your master IPv6')
console.print_header(' 3. Ensure master is running')
console.print_header('')
// Uncomment the line below to actually run the join
// playcmds.run(heroscript: join_worker_script)!
console.print_header('✅ Script ready. Uncomment playcmds.run() to execute.')
console.print_header('='.repeat(80))

View File

@@ -0,0 +1,44 @@
#!/usr/bin/env -S v -n -w -cg -gc none -cc tcc -d use_openssl -enable-globals run
import incubaid.herolib.core.playcmds
import incubaid.herolib.ui.console
console.print_header('='*.repeat(80))
console.print_header('K3s Install/Uninstall Lifecycle Test')
console.print_header('='*.repeat(80))
// ============================================================================
// PHASE 1: Install Master
// ============================================================================
console.print_header('\n📦 PHASE 1: Installing K3s Master')
install_script := '
!!kubernetes_installer.configure
name:"k3s_test"
node_name:"test-master"
!!kubernetes_installer.install_master name:"k3s_test"
!!kubernetes_installer.start name:"k3s_test"
'
playcmds.run(heroscript: install_script)!
console.print_header('✅ Installation completed!')
// ============================================================================
// PHASE 2: Uninstall
// ============================================================================
console.print_header('\n🧹 PHASE 2: Uninstalling K3s')
uninstall_script := '
!!kubernetes_installer.configure
name:"k3s_test"
!!kubernetes_installer.destroy name:"k3s_test"
'
playcmds.run(heroscript: uninstall_script)!
console.print_header('✅ Uninstallation completed!')
console.print_header('\n' + '='.repeat(80))
console.print_header('✅ FULL LIFECYCLE TEST COMPLETED!')
console.print_header('='.repeat(80))