我正在尝试使用 Python Paramiko SSH 客户端在 openshift 节点上执行类似
oc get nodes
的 Open Shift 命令。
当我直接在节点上运行此命令时,它会执行并返回输出。但是,如果我尝试使用 ssh 会话执行它,它会抛出以下错误。
['error: Missing or incomplete configuration info. Please login or point to an existing, complete config file:', '',
'1. Via the command-line flag --config',
'2. Via the KUBECONFIG environment variable',
'3. In your home directory as ~/.kube/config', '',
"To view or setup config directly use the 'config' command."]
我写的代码如下:
client = paramiko.SSHClient()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
client.connect(hostname=ip_address,
username=username,
password=password)
client.exec_command('oc get nodes')
即使尝试使用
ssh -i oc get nodes
运行命令,也会抛出 Bash: oc 命令不存在。
使用的Python版本:Python3.7
我是 Python 新手,请告诉我是否有任何库可以用来执行 oc 命令。
我感谢任何帮助,谢谢。
需要添加kubeconfig路径:
client.exec_command('oc get nodes --kubeconfig <path to kubeconfig on host>')