I am trying to write a shellscript to run on a linux server which will interact with a remote kubernetes cluster and get info about the certificates on the cluster. The linux server has connectivity to kubernetes nodes. I am able to SSH to the kubernetes node from the server and run the kubectl commands and get the proper output via terminal.
But, when I try the same via shellscript (ssh to kubernetes node and run kubectl get certs), the kubectl command gives an error "The connection to the server localhost:8080 was refused - did you specify the right host or port?"
Trying SSH from linux server terminal (working)
ssh user@server
sudo -i
kubectl get certs -o json
Trying the same in a shellscript(not working)
#!/bin/bash
ssh user@server <<"EOF"
sudo -i
Kubectl get certs -o json
EOF
The result of running the above shellscript is "The connection to the server localhost:8080 was refused - did you specify the right host or port? "