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

ubuntu@ip-172-31-35-118:~$ kubectl version
WARNING: This version information is deprecated and will be replaced with the output from kubectl version --short. Use --output=yaml|json to get the full version.
Client Version: version.Info{Major:“1”, Minor:“25”, GitVersion:“v1.25.3”, GitCommit:“434bfd82814af038ad94d62ebe59b133fcb50506”, GitTreeState:“clean”, BuildDate:“2022-10-12T10:57:26Z”, GoVersion:“go1.19.2”, Compiler:“gc”, Platform:“linux/amd64”}
Kustomize Version: v4.5.7
The connection to the server 172.31.35.118:6443 was refused - did you specify the right host or port?

Since even then i swapoff -a and followed below steps:

sudo -i
swapoff -a
exit
strace -eopenat kubectl versionit