当我尝试通过sshpass运行kubectl命令时,它无法连接到服务器失败

时间:2017-09-20 07:25:50

标签: ssh kubernetes kubectl sshpass

我使用了这样的命令:

sshpass -p password ssh root@x.x.x.x 'date;kubectl get pod;date' 

我得到了:

Wed Sep 20 14:39:19 CST 2017
Unable to connect to the server: EOF
Wed Sep 20 14:39:20 CST 2017

如何解决此问题?

所有kubectl命令在目标系统上运行良好。 命令:

sshpass -p password ssh root@x.x.x.x 'kubectl'

也很好用:

 mynode /etc » sshpass -p password ssh -o StrictHostKeyChecking=no root@x.x.x.x "kubectl"                                                        
kubectl controls the Kubernetes cluster manager. 

Find more information at https://github.com/kubernetes/kubernetes.

Basic Commands (Beginner):
  create         Create a resource by filename or stdin
  expose         Take a replication controller, service, deployment or pod and expose it as a new Kubernetes Service
  run            Run a particular image on the cluster
  set            Set specific features on objects

Basic Commands (Intermediate):
  get            Display one or many resources
  explain        Documentation of resources
  edit           Edit a resource on the server
  delete         Delete resources by filenames, stdin, resources and names, or by resources and label selector
...

1 个答案:

答案 0 :(得分:0)

你能试试这样的事吗?

ssh master-01 -x 'kubectl --kubeconfig=/root/.kube/config get nodes'

在你的情况下是这样的:

 sshpass -p password  ssh master-01 -x 'kubectl --kubeconfig=/root/.kube/config get nodes'