0

I installed K3S on Ubuntu 18.04 as below:

curl -LO "https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl"
chmod +x ./kubectl
sudo mv ./kubectl /usr/local/bin/kubectl
kubectl version --client
curl -sfL https://get.k3s.io | sh -
sudo kubectl get nodes

However, when I do sudo kubectl get nodes, I get error below

ubuntu@ip-10-0-0-62:~$ sudo kubectl get nodes
The connection to the server localhost:8080 was refused - did you specify the right host or port?

I checked the running processes for three important ports

ubuntu@ip-10-0-0-62:~$ sudo lsof -i:6443
COMMAND    PID USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
k3s-serve 2295 root   15u  IPv6  28164      0t0  TCP *:6443 (LISTEN)
k3s-serve 2295 root  166u  IPv6  31995      0t0  TCP ip-10-0-0-62.ap-southeast-2.compute.internal:6443->ip-10-42-0-2.ap-southeast-2.compute.internal:45338 (ESTABLISHED)
k3s-serve 2295 root  168u  IPv4  30182      0t0  TCP localhost:59284->localhost:6443 (ESTABLISHED)
k3s-serve 2295 root  173u  IPv4  27307      0t0  TCP localhost:59176->localhost:6443 (ESTABLISHED)
k3s-serve 2295 root  177u  IPv6  28302      0t0  TCP localhost:6443->localhost:59176 (ESTABLISHED)
k3s-serve 2295 root  182u  IPv6  27361      0t0  TCP localhost:6443->localhost:59226 (ESTABLISHED)
k3s-serve 2295 root  184u  IPv4  28411      0t0  TCP localhost:59226->localhost:6443 (ESTABLISHED)
k3s-serve 2295 root  185u  IPv4  27363      0t0  TCP ip-10-0-0-62.ap-southeast-2.compute.internal:47226->ip-10-0-0-62.ap-southeast-2.compute.internal:6443 (ESTABLISHED)
k3s-serve 2295 root  186u  IPv6  27364      0t0  TCP ip-10-0-0-62.ap-southeast-2.compute.internal:6443->ip-10-0-0-62.ap-southeast-2.compute.internal:47226 (ESTABLISHED)
k3s-serve 2295 root  188u  IPv4  27368      0t0  TCP localhost:59230->localhost:6443 (ESTABLISHED)
k3s-serve 2295 root  190u  IPv6  28414      0t0  TCP localhost:6443->localhost:59230 (ESTABLISHED)
k3s-serve 2295 root  194u  IPv4  28418      0t0  TCP localhost:59232->localhost:6443 (ESTABLISHED)
k3s-serve 2295 root  195u  IPv4  28419      0t0  TCP localhost:59234->localhost:6443 (ESTABLISHED)
k3s-serve 2295 root  196u  IPv4  28420      0t0  TCP localhost:59236->localhost:6443 (ESTABLISHED)
k3s-serve 2295 root  197u  IPv6  27405      0t0  TCP localhost:6443->localhost:59232 (ESTABLISHED)
k3s-serve 2295 root  198u  IPv6  27406      0t0  TCP localhost:6443->localhost:59234 (ESTABLISHED)
k3s-serve 2295 root  199u  IPv6  27407      0t0  TCP localhost:6443->localhost:59236 (ESTABLISHED)
k3s-serve 2295 root  204u  IPv4  27411      0t0  TCP localhost:59238->localhost:6443 (ESTABLISHED)
k3s-serve 2295 root  205u  IPv6  32305      0t0  TCP ip-10-0-0-62.ap-southeast-2.compute.internal:6443->ip-10-42-0-4.ap-southeast-2.compute.internal:49256 (ESTABLISHED)
k3s-serve 2295 root  209u  IPv4  28426      0t0  TCP localhost:59240->localhost:6443 (ESTABLISHED)
k3s-serve 2295 root  210u  IPv4  27420      0t0  TCP localhost:59242->localhost:6443 (ESTABLISHED)
k3s-serve 2295 root  211u  IPv6  34769      0t0  TCP ip-10-0-0-62.ap-southeast-2.compute.internal:6443->ip-10-42-0-6.ap-southeast-2.compute.internal:56858 (ESTABLISHED)
k3s-serve 2295 root  212u  IPv4  28428      0t0  TCP localhost:59246->localhost:6443 (ESTABLISHED)
k3s-serve 2295 root  213u  IPv6  28429      0t0  TCP localhost:6443->localhost:59238 (ESTABLISHED)
k3s-serve 2295 root  214u  IPv6  28430      0t0  TCP localhost:6443->localhost:59240 (ESTABLISHED)
k3s-serve 2295 root  215u  IPv6  28431      0t0  TCP localhost:6443->localhost:59242 (ESTABLISHED)
k3s-serve 2295 root  216u  IPv6  34771      0t0  TCP ip-10-0-0-62.ap-southeast-2.compute.internal:6443->ip-10-42-0-6.ap-southeast-2.compute.internal:56860 (ESTABLISHED)
k3s-serve 2295 root  217u  IPv6  28433      0t0  TCP localhost:6443->localhost:59246 (ESTABLISHED)
k3s-serve 2295 root  218u  IPv4  27438      0t0  TCP localhost:59248->localhost:6443 (ESTABLISHED)
k3s-serve 2295 root  220u  IPv6  28449      0t0  TCP localhost:6443->localhost:59248 (ESTABLISHED)
k3s-serve 2295 root  221u  IPv6  28450      0t0  TCP localhost:6443->localhost:59250 (ESTABLISHED)
k3s-serve 2295 root  225u  IPv4  28442      0t0  TCP localhost:59250->localhost:6443 (ESTABLISHED)
k3s-serve 2295 root  240u  IPv4  28731      0t0  TCP localhost:59254->localhost:6443 (ESTABLISHED)
k3s-serve 2295 root  241u  IPv4  28732      0t0  TCP localhost:59256->localhost:6443 (ESTABLISHED)
k3s-serve 2295 root  242u  IPv6  28733      0t0  TCP localhost:6443->localhost:59254 (ESTABLISHED)
k3s-serve 2295 root  243u  IPv6  28734      0t0  TCP localhost:6443->localhost:59256 (ESTABLISHED)
k3s-serve 2295 root  250u  IPv4  29978      0t0  TCP localhost:59264->localhost:6443 (ESTABLISHED)
k3s-serve 2295 root  252u  IPv6  29980      0t0  TCP localhost:6443->localhost:59264 (ESTABLISHED)
k3s-serve 2295 root  253u  IPv4  29232      0t0  TCP localhost:59266->localhost:6443 (ESTABLISHED)
k3s-serve 2295 root  254u  IPv4  29233      0t0  TCP localhost:59268->localhost:6443 (ESTABLISHED)
k3s-serve 2295 root  255u  IPv6  29234      0t0  TCP localhost:6443->localhost:59266 (ESTABLISHED)
k3s-serve 2295 root  256u  IPv6  29982      0t0  TCP localhost:6443->localhost:59268 (ESTABLISHED)
k3s-serve 2295 root  257u  IPv4  29286      0t0  TCP localhost:59270->localhost:6443 (ESTABLISHED)
k3s-serve 2295 root  258u  IPv6  29287      0t0  TCP localhost:6443->localhost:59270 (ESTABLISHED)
k3s-serve 2295 root  259u  IPv6  34773      0t0  TCP ip-10-0-0-62.ap-southeast-2.compute.internal:6443->ip-10-42-0-6.ap-southeast-2.compute.internal:56862 (ESTABLISHED)
k3s-serve 2295 root  260u  IPv6  30184      0t0  TCP localhost:6443->localhost:59284 (ESTABLISHED)
k3s-serve 2295 root  261u  IPv6  36154      0t0  TCP ip-10-0-0-62.ap-southeast-2.compute.internal:6443->ip-10-42-0-6.ap-southeast-2.compute.internal:56864 (ESTABLISHED)
k3s-serve 2295 root  262u  IPv6  31996      0t0  TCP ip-10-0-0-62.ap-southeast-2.compute.internal:6443->ip-10-42-0-2.ap-southeast-2.compute.internal:45340 (ESTABLISHED)
k3s-serve 2295 root  263u  IPv6  31998      0t0  TCP ip-10-0-0-62.ap-southeast-2.compute.internal:6443->ip-10-42-0-2.ap-southeast-2.compute.internal:45342 (ESTABLISHED)
k3s-serve 2295 root  264u  IPv6  32076      0t0  TCP ip-10-0-0-62.ap-southeast-2.compute.internal:6443->ip-10-42-0-3.ap-southeast-2.compute.internal:35926 (ESTABLISHED)
k3s-serve 2295 root  265u  IPv6  31674      0t0  TCP ip-10-0-0-62.ap-southeast-2.compute.internal:6443->ip-10-42-0-3.ap-southeast-2.compute.internal:35928 (ESTABLISHED)
k3s-serve 2295 root  266u  IPv6  32122      0t0  TCP ip-10-0-0-62.ap-southeast-2.compute.internal:6443->ip-10-42-0-3.ap-southeast-2.compute.internal:35936 (ESTABLISHED)
k3s-serve 2295 root  267u  IPv6  31675      0t0  TCP ip-10-0-0-62.ap-southeast-2.compute.internal:6443->ip-10-42-0-3.ap-southeast-2.compute.internal:35930 (ESTABLISHED)
k3s-serve 2295 root  268u  IPv6  31676      0t0  TCP ip-10-0-0-62.ap-southeast-2.compute.internal:6443->ip-10-42-0-3.ap-southeast-2.compute.internal:35932 (ESTABLISHED)
k3s-serve 2295 root  269u  IPv6  31677      0t0  TCP ip-10-0-0-62.ap-southeast-2.compute.internal:6443->ip-10-42-0-3.ap-southeast-2.compute.internal:35934 (ESTABLISHED)
k3s-serve 2295 root  270u  IPv6  31705      0t0  TCP ip-10-0-0-62.ap-southeast-2.compute.internal:6443->ip-10-42-0-3.ap-southeast-2.compute.internal:35938 (ESTABLISHED)
k3s-serve 2295 root  271u  IPv6  33226      0t0  TCP ip-10-0-0-62.ap-southeast-2.compute.internal:6443->ip-10-42-0-4.ap-southeast-2.compute.internal:49258 (ESTABLISHED)
k3s-serve 2295 root  272u  IPv6  33229      0t0  TCP ip-10-0-0-62.ap-southeast-2.compute.internal:6443->ip-10-42-0-4.ap-southeast-2.compute.internal:49260 (ESTABLISHED)
k3s-serve 2295 root  273u  IPv4  32308      0t0  TCP localhost:59490->localhost:6443 (ESTABLISHED)
k3s-serve 2295 root  274u  IPv6  32309      0t0  TCP localhost:6443->localhost:59490 (ESTABLISHED)
k3s-serve 2295 root  275u  IPv4  33234      0t0  TCP localhost:59492->localhost:6443 (ESTABLISHED)
k3s-serve 2295 root  276u  IPv6  32311      0t0  TCP localhost:6443->localhost:59492 (ESTABLISHED)
k3s-serve 2295 root  277u  IPv4  33645      0t0  TCP localhost:59586->localhost:6443 (ESTABLISHED)
k3s-serve 2295 root  279u  IPv6  33646      0t0  TCP localhost:6443->localhost:59586 (ESTABLISHED)
k3s-serve 2295 root  283u  IPv4  33650      0t0  TCP localhost:59592->localhost:6443 (ESTABLISHED)
k3s-serve 2295 root  286u  IPv6  32741      0t0  TCP localhost:6443->localhost:59592 (ESTABLISHED)
ubuntu@ip-10-0-0-62:~$ sudo lsof -i:8472
ubuntu@ip-10-0-0-62:~$ sudo lsof -i:10250
COMMAND    PID USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
k3s-serve 2295 root  224u  IPv6  28440      0t0  TCP *:10250 (LISTEN)
k3s-serve 2295 root  226u  IPv6  37502      0t0  TCP ip-10-0-0-62.ap-southeast-2.compute.internal:10250->ip-10-42-0-4.ap-southeast-2.compute.internal:47148 (ESTABLISHED)

Not sure what is the issue and how to resolve it.

learner
  • 101
  • 3

1 Answers1

0

You may need to check your .kube/config. Your error message indicates kubectl tries to connect to localhost:8080 but your lsof call indicates you expect communication to happen on port 6443. Check in particular the clusters section in your kubectl configuration. It may be the wrong active context or wrong server URL.