When I try to run kubectl command through sshpass,it failed with Unable to connect to the server

9/20/2017

I used such command:

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

I got:

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

How to fix this issue?

All kubectl commands work well on target system. Command:

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

also work well:

 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
...
-- Lior
kubectl
kubernetes
ssh
sshpass

1 Answer

9/22/2017

can you try run something like this?

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

in your case like this:

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