feat: add homelab deployment configs, documentation, and automation scripts
This commit is contained in:
45
scripts/apply_prom_grafana.py
Normal file
45
scripts/apply_prom_grafana.py
Normal file
@@ -0,0 +1,45 @@
|
||||
import paramiko
|
||||
import time
|
||||
|
||||
c = paramiko.SSHClient()
|
||||
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
||||
c.connect('140.44.4.11', username='root', key_filename=r'C:\Users\Snarf\.ssh\id_ed25519_snarfnet', timeout=10)
|
||||
|
||||
def run(cmd):
|
||||
_, o, e = c.exec_command(cmd)
|
||||
out = o.read().decode().strip()
|
||||
err = e.read().decode().strip()
|
||||
return out + ("\nERR: " + err if err else "")
|
||||
|
||||
with open("homelab-gitops-repo/manifests/aerodrome/prometheus/prometheus.yaml", "r") as f:
|
||||
prom_yaml = f.read()
|
||||
|
||||
stdin, stdout, stderr = c.exec_command("cat > /tmp/prometheus.yaml")
|
||||
stdin.write(prom_yaml)
|
||||
stdin.close()
|
||||
stdout.channel.recv_exit_status()
|
||||
|
||||
print("Applying Prometheus:")
|
||||
print(run("kubectl apply -f /tmp/prometheus.yaml"))
|
||||
|
||||
with open("homelab-gitops-repo/manifests/aerodrome/grafana/grafana.yaml", "r") as f:
|
||||
grafana_yaml = f.read()
|
||||
|
||||
stdin, stdout, stderr = c.exec_command("cat > /tmp/grafana_full.yaml")
|
||||
stdin.write(grafana_yaml)
|
||||
stdin.close()
|
||||
stdout.channel.recv_exit_status()
|
||||
|
||||
print("\nApplying Grafana configuration & dashboards:")
|
||||
print(run("kubectl apply -f /tmp/grafana_full.yaml"))
|
||||
|
||||
print("\nRestarting Grafana:")
|
||||
print(run("kubectl rollout restart deployment/grafana -n default"))
|
||||
print(run("kubectl rollout status deployment/grafana -n default --timeout=60s"))
|
||||
|
||||
print("\nChecking Prometheus pod:")
|
||||
time.sleep(5)
|
||||
print(run("kubectl get pods -l app.kubernetes.io/name=prometheus"))
|
||||
|
||||
c.close()
|
||||
|
||||
Reference in New Issue
Block a user