feat: add housekeeping and cleanup scripts for cluster maintenance
This commit is contained in:
35
scripts/cleanup_spaceport.py
Normal file
35
scripts/cleanup_spaceport.py
Normal file
@@ -0,0 +1,35 @@
|
||||
import paramiko
|
||||
import sys
|
||||
import time
|
||||
|
||||
sys.stdout.reconfigure(encoding='utf-8')
|
||||
|
||||
key_path = r"C:\Users\Snarf\.ssh\id_ed25519_snarfnet"
|
||||
client = paramiko.SSHClient()
|
||||
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
||||
|
||||
master_ip = "140.44.4.41"
|
||||
print(f"Connecting to Spaceport Master: {master_ip}...")
|
||||
client.connect(master_ip, username="root", key_filename=key_path, timeout=15)
|
||||
|
||||
# A. Clean up completed pods across namespaces on Spaceport
|
||||
print("\n>>> Pruning completed pods on Spaceport...")
|
||||
stdin, stdout, stderr = client.exec_command("KUBECONFIG=/etc/rancher/k3s/k3s.yaml kubectl delete pod -A --field-selector=status.phase=Succeeded")
|
||||
print(stdout.read().decode('utf-8'))
|
||||
print(stderr.read().decode('utf-8'))
|
||||
|
||||
# B. Save final etcd snapshot on Spaceport
|
||||
snap_space = f"final-post-upgrade-spaceport-{int(time.time())}"
|
||||
print(f"\n>>> Saving final etcd snapshot: {snap_space}...")
|
||||
stdin, stdout, stderr = client.exec_command(f"k3s etcd-snapshot save --name {snap_space}")
|
||||
print(stdout.read().decode('utf-8'))
|
||||
print(stderr.read().decode('utf-8'))
|
||||
|
||||
# C. List snapshots
|
||||
print("\n>>> Recent etcd snapshots on Spaceport:")
|
||||
stdin, stdout, stderr = client.exec_command("k3s etcd-snapshot list | tail -n 5")
|
||||
print(stdout.read().decode('utf-8'))
|
||||
|
||||
client.close()
|
||||
print("\nSpaceport cleanup and snapshot completed successfully!")
|
||||
|
||||
Reference in New Issue
Block a user