HiveBrain v1.2.0
Get Started
← Back to all entries
patternkubernetesMinor

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

Submitted by: @import:stackexchange-devops··
0
Viewed 0 times
thek3syoulocalhostrefuseddid8080washostport

Problem

When I run any kubectl commands, I'm getting

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

Solution

This problem is likely caused by a bad ~/.kube/config perhaps you have a file from a different kubernetes install (minikube) or an older k3s. If the server is local you can fix this by running these commands,

mkdir ~/.kube
sudo k3s kubectl config view --raw | tee ~/.kube/config
chmod 600 ~/.kube/config


The contents of ~/.kube/config need to have the same information as /etc/rancher/k3s/k3s.yaml when the server was started (the keys, ip, and ports).

Note in order to tell k3s to use this config file you'll want to configure KUBECONFIG.

export KUBECONFIG=~/.kube/config


You should persist this by having it set in ~/.profile or ~/.bashrc

Code Snippets

mkdir ~/.kube
sudo k3s kubectl config view --raw | tee ~/.kube/config
chmod 600 ~/.kube/config
export KUBECONFIG=~/.kube/config

Context

StackExchange DevOps Q#16013, answer score: 7

Revisions (0)

No revisions yet.