-1

I am trying to run kubectl commands on a remote server from local, but seems it is trying to run on localhost when all other commands(ls, date) I am able to run on remote.

command = 'kubectl get pod -n namespace'
stdin,stdout,stderr=ssh.exec_command(command)

Error:

The connection to the server localhost:8080 was refused - did you specify the right host or port?

Any idea how to run kubectl on remote to connect to a pod and run some command there inside the pod?

P....
  • 17,421
  • 2
  • 32
  • 52
Param
  • 1

1 Answers1

0

Check if you are ssh connection is non-root user, this error comes when you try to execute the kubectl commands as non-root user.

Solutions:

  1. Add sudo as prefix to the commands. This will solve the issue with current user itself.
  2. Make the ssh connection with root user.