使用 Python SSH 实用程序执行 OpenShift 命令失败

问题描述 投票:0回答:1

我正在尝试使用 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 命令。

我感谢任何帮助,谢谢。

python python-3.x ssh openshift paramiko
1个回答
0
投票

需要添加kubeconfig路径:

client.exec_command('oc get nodes --kubeconfig <path to kubeconfig on host>')
© www.soinside.com 2019 - 2024. All rights reserved.