# -*- coding: utf-8 -*- import paramiko c = paramiko.SSHClient() c.set_missing_host_key_policy(paramiko.AutoAddPolicy()) c.connect("192.168.110.207", username="root", password="123456", timeout=20) cmds = [ "which -a kubectl; ls -la $(which kubectl) /usr/bin/kubectl /usr/local/bin/kubectl 2>/dev/null; type kubectl", "kubectl version --client 2>&1 | head -5", "echo KUBECONFIG=$KUBECONFIG; ls -la ~/.kube/config /etc/rancher/k3s/k3s.yaml 2>&1", "head -20 ~/.kube/config 2>/dev/null || echo no_home_kube", "head -15 /etc/rancher/k3s/k3s.yaml 2>/dev/null", "k3s kubectl get nodes 2>&1", "systemctl is-active k3s; k3s --version | head -1", ] for cmd in cmds: print("===", cmd[:70]) _, o, e = c.exec_command(cmd, timeout=30) print(o.read().decode(errors="replace")) err = e.read().decode(errors="replace") if err.strip(): print("ERR:", err[:500]) c.close()