首页 > 解决方案 > 使用 Python SSH 实用程序执行 OpenShift 命令失败

问题描述

我正在尝试oc get nodes使用 Python Paramiko SSH 客户端在 openshift 节点上执行 Open Shift 命令。

当我直接在节点上运行此命令时,它会执行并返回输出。但是,如果我尝试使用 ssh session 执行它,它会抛出以下错误。

['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 命令,请告诉我。

我感谢任何帮助,谢谢。

标签: pythonpython-3.xsshopenshiftparamiko

解决方案


推荐阅读