feat: add scripts to inspect and check Rancher deployments via SSH

This commit is contained in:
2026-11-04 21:26:45 -05:00
parent 1b378b29f3
commit ba47f6a384
10 changed files with 210 additions and 15 deletions

View File

@@ -1,19 +1,13 @@
import paramiko
import sys
def check_catalog_versions(ip, cluster_name):
print(f"\n=======================================================")
print(f"=== {cluster_name} AVAILABLE CHART VERSIONS ===")
print(f"=======================================================")
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(ip, username='root', key_filename=r'C:\Users\Snarf\.ssh\id_ed25519_snarfnet', timeout=10)
# We can inspect the Rancher catalog charts
cmd = "kubectl get charts.catalog.cattle.io -A -o custom-columns=REPO:.metadata.namespace,CHART:.metadata.name | head -n 30"
_, out, _ = ssh.exec_command(cmd)
print(out.read().decode())
ssh.close()
sys.stdout.reconfigure(encoding='utf-8')
check_catalog_versions('140.44.4.11', 'AERODROME')
check_catalog_versions('140.44.4.41', 'SPACEPORT')
client = paramiko.SSHClient()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
key_path = r"C:\Users\Snarf\.ssh\id_ed25519_snarfnet"
client.connect("140.44.4.11", username="root", key_filename=key_path, timeout=15)
stdin, stdout, stderr = client.exec_command("KUBECONFIG=/etc/rancher/k3s/k3s.yaml helm search repo rancher-stable/rancher --versions > /tmp/rancher_versions.txt && head -n 30 /tmp/rancher_versions.txt")
print(stdout.read().decode('utf-8'))
client.close()

View File

@@ -0,0 +1,20 @@
import paramiko
import sys
sys.stdout.reconfigure(encoding='utf-8')
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect('140.44.4.11', username='root', key_filename=r'C:\Users\Snarf\.ssh\id_ed25519_snarfnet', timeout=10)
def run(cmd):
print(f"=== {cmd} ===")
_, out, err = ssh.exec_command(cmd)
res = out.read().decode('utf-8', errors='replace').strip()
if res:
print(res)
run("KUBECONFIG=/etc/rancher/k3s/k3s.yaml helm repo update rancher-stable")
run("KUBECONFIG=/etc/rancher/k3s/k3s.yaml helm search repo rancher-stable/rancher --versions | head -n 35")
ssh.close()

View File

@@ -0,0 +1,14 @@
import paramiko
import sys
sys.stdout.reconfigure(encoding='utf-8')
client = paramiko.SSHClient()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
key_path = r"C:\Users\Snarf\.ssh\id_ed25519_snarfnet"
client.connect("140.44.4.11", username="root", key_filename=key_path, timeout=15)
stdin, stdout, stderr = client.exec_command("KUBECONFIG=/etc/rancher/k3s/k3s.yaml helm search repo rancher-stable/rancher --versions | head -n 35")
print(stdout.read().decode('utf-8'))
client.close()

View File

@@ -0,0 +1,15 @@
import paramiko
import sys
sys.stdout.reconfigure(encoding='utf-8')
client = paramiko.SSHClient()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
key_path = r"C:\Users\Snarf\.ssh\id_ed25519_snarfnet"
client.connect("140.44.4.11", username="root", key_filename=key_path, timeout=15)
stdin, stdout, stderr = client.exec_command("KUBECONFIG=/etc/rancher/k3s/k3s.yaml kubectl -n cattle-system get secret tls-rancher-ingress")
print(stdout.read().decode('utf-8'))
print(stderr.read().decode('utf-8'))
client.close()

View File

@@ -0,0 +1,27 @@
import urllib.request
import json
import re
releases = {}
for page in range(1, 20):
url = f"https://api.github.com/repos/rancher/rancher/tags?per_page=100&page={page}"
req = urllib.request.Request(url, headers={'User-Agent': 'Mozilla/5.0'})
try:
data = json.loads(urllib.request.urlopen(req).read().decode())
except:
break
if not data:
break
for item in data:
name = item['name']
m = re.match(r"^v(2\.\d+)\.(\d+)$", name)
if m:
series = m.group(1)
patch = int(m.group(2))
if series not in releases or patch > releases[series]:
releases[series] = patch
for s in sorted(releases.keys(), key=lambda x: [int(p) for p in x.split('.')]):
print(f"Series v{s}: latest patch is v{s}.{releases[s]}")

View File

@@ -0,0 +1,15 @@
import paramiko
import sys
sys.stdout.reconfigure(encoding='utf-8')
client = paramiko.SSHClient()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
key_path = r"C:\Users\Snarf\.ssh\id_ed25519_snarfnet"
client.connect("140.44.4.11", username="root", key_filename=key_path, timeout=15)
stdin, stdout, stderr = client.exec_command("KUBECONFIG=/etc/rancher/k3s/k3s.yaml helm get values rancher -n cattle-system")
print("=== CURRENT RANCHER VALUES ===")
print(stdout.read().decode('utf-8'))
client.close()

View File

@@ -0,0 +1,21 @@
import paramiko
import base64
import gzip
import json
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect('140.44.4.11', username='root', key_filename=r'C:\Users\Snarf\.ssh\id_ed25519_snarfnet', timeout=10)
_, out, _ = ssh.exec_command('kubectl get secret -n cattle-system sh.helm.release.v1.rancher.v1 -o jsonpath="{.data.release}"')
raw = out.read().decode().strip()
if raw:
data = base64.b64decode(raw)
data = base64.b64decode(data) # helm encodes twice
decomp = gzip.decompress(data)
rel = json.loads(decomp)
print("Chart:", rel.get('chart', {}).get('metadata', {}).get('version'))
print("Values:", json.dumps(rel.get('config', {}), indent=2))
ssh.close()

View File

@@ -0,0 +1,26 @@
import paramiko
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect('140.44.4.11', username='root', key_filename=r'C:\Users\Snarf\.ssh\id_ed25519_snarfnet', timeout=10)
def run(cmd):
print(f"\n=== {cmd} ===")
_, out, err = ssh.exec_command(cmd)
res = out.read().decode('utf-8', errors='replace').strip()
if res:
print(res)
e = err.read().decode('utf-8', errors='replace').strip()
if e:
print("ERR:", e)
run("kubectl get deploy,sts,ds -n cattle-system -o wide")
run("kubectl get pods -n cattle-system -o wide")
run("kubectl get deploy -n cattle-system rancher -o yaml | grep -E 'image:'")
run("kubectl get secrets -n cattle-system | grep -i helm")
run("kubectl get helmcharts,helmchartconfigs -A | grep -i rancher")
run("kubectl get ns | grep -E 'cert-manager|cattle'")
run("kubectl get pods -n cert-manager 2>/dev/null || true")
ssh.close()

34
scripts/rancher_status.py Normal file
View File

@@ -0,0 +1,34 @@
import paramiko
import sys
sys.stdout.reconfigure(encoding='utf-8')
client = paramiko.SSHClient()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
key_path = r"C:\Users\Snarf\.ssh\id_ed25519_snarfnet"
try:
client.connect("140.44.4.11", username="root", key_filename=key_path, timeout=10)
print("=== Connected to Aerodrome (140.44.4.11) ===")
cmds = [
"kubectl -n cattle-system get pods -o wide",
"helm list -n cattle-system",
"helm repo list",
"k3s etcd-snapshot list"
]
for cmd in cmds:
print(f"\n--- Running: {cmd} ---")
stdin, stdout, stderr = client.exec_command(f"KUBECONFIG=/etc/rancher/k3s/k3s.yaml {cmd}")
out = stdout.read().decode('utf-8')
err = stderr.read().decode('utf-8')
if out:
print(out.strip())
if err:
print(f"ERR: {err.strip()}")
client.close()
except Exception as e:
print(f"Error: {e}")

29
scripts/test_etcd_helm.py Normal file
View File

@@ -0,0 +1,29 @@
import paramiko
import sys
sys.stdout.reconfigure(encoding='utf-8')
client = paramiko.SSHClient()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
key_path = r"C:\Users\Snarf\.ssh\id_ed25519_snarfnet"
def run_remote(cmd):
client.connect("140.44.4.11", username="root", key_filename=key_path, timeout=15)
stdin, stdout, stderr = client.exec_command(cmd)
out = stdout.read().decode('utf-8')
err = stderr.read().decode('utf-8')
client.close()
return out, err
out, err = run_remote("k3s etcd-snapshot list")
print("=== ETCD SNAPSHOTS ===")
print(out)
if err:
print("ERR:", err)
out, err = run_remote("KUBECONFIG=/etc/rancher/k3s/k3s.yaml helm repo list")
print("=== HELM REPOS ===")
print(out)
if err:
print("ERR:", err)