kubectl cannot reach the Kubernetes API server on port 6443
Unable to connect to the serverShort answer
Port 6443 is the Kubernetes API server. A refusal means nothing answered there: kubectl is pointed at the wrong server or kubeconfig, a firewall such as ufw blocks the port, or kube-apiserver itself is not running on the control plane node.
Fix it fast
1Find out which cause you have
See which server kubectl is using, then test that exact address with curl. A refusal here, from the machine you work on, points to the firewall or a stopped API server; a different address than you expect points to the kubeconfig.
kubectl config view --minify | grep server curl -vk https://<control-plane-ip>:6443/version2Match what you see, then jump to its fix
- 1
The server address in the error is not your control plane's address.kubectl uses the wrong or missing kubeconfigFix - 2
From another machine curl is refused or hangs, while on the control plane node itself it answers.A firewall blocks port 6443Fix - 3
The refusal also happens on the control plane node itself, and kubelet logs show the API server container restarting.kube-apiserver is not runningFix
- 1
What does the error look like?
Unable to connect to the serverdial tcp <ip>:6443: connect: connection refused
Cause 1 of 3
kubectl uses the wrong or missing kubeconfig
1Check
kubectl reads ~/.kube/config unless the KUBECONFIG variable or --kubeconfig says otherwise. A copy of the admin file is on the control plane node.
echo "$KUBECONFIG"
kubectl config get-contexts2Fix
Point kubectl at the right file or context. On a kubeadm control plane node, copy the admin file to your home folder.
mkdir -p ~/.kube
sudo cp /etc/kubernetes/admin.conf ~/.kube/config
sudo chown "$(id -u):$(id -g)" ~/.kube/config
kubectl config use-context <context-name>3Verify
kubectl reports the server version.
kubectl versionConfirmed by kubernetes.io
Cause 2 of 3
A firewall blocks port 6443
1Check
Port 6443 must be open inbound on the control plane node, since every client and worker node talks to the API server there. Look at the ufw rules.
sudo ufw status numbered2Fix
Allow the port. If the node sits behind a cloud firewall or security group, open it there too.
sudo ufw allow 6443/tcp3Verify
From the other machine the API server answers.
curl -vk https://<control-plane-ip>:6443/versionConfirmed by kubernetes.io
Cause 3 of 3
kube-apiserver is not running
1Check
In a kubeadm cluster the API server is a container started by kubelet. List all containers with crictl, including exited ones, and read the log of the kube-apiserver one.
sudo systemctl status kubelet
sudo crictl ps -a | grep kube-apiserver
sudo crictl logs --tail=50 <container-id>2Fix
Fix the error in that log (for example a bad flag or an unreachable etcd, whose ports are 2379-2380), then let kubelet restart the container. If crictl cannot find a runtime, set the endpoint in /etc/crictl.yaml.
# /etc/crictl.yaml (containerd)
runtime-endpoint: unix:///var/run/containerd/containerd.sock
image-endpoint: unix:///var/run/containerd/containerd.sock
sudo systemctl restart kubelet3Verify
A kube-apiserver container is Running and the version call answers.
sudo crictl ps | grep kube-apiserver
kubectl get nodesConfirmed by kubernetes.io
How do I stop it coming back?
- Open 6443 on the control plane in both ufw and any cloud firewall before you run kubeadm join.
- Keep a copy of admin.conf in a safe place and use named contexts.
- Put a load balancer address in front of several control plane nodes instead of one node's IP.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
Related fixes
Servers
Kubernetes cannot pull an image from a plain HTTP or self-signed registry
docker pull works on a laptop, the same image fails in the cluster
Kubernetes nodes pull images through their container runtime, usually containerd, not through your Docker daemon.
4 causes, each with a fixServers
dnf cannot install MySQL on Amazon Linux 2023
dnf cannot find a mysql-server package on Amazon Linux 2023
Amazon Linux 2023 documents MariaDB, not MySQL, as its database server, with packages named mariadb105 and mariadb105-server.
3 causes, each with a fixServers
Ansible hangs, then times out waiting for the sudo prompt
a playbook using become seems to hang
Ansible ran sudo on the target and never saw the answer it expected.
3 causes, each with a fixServers
Apache on Ubuntu returns 404 Not Found for my site
The requested URL was not found on this server.
On Ubuntu a 404 from Apache usually means the request maps to a path that has no file.
3 causes, each with a fixServers
Apache returns 504 Gateway Timeout when PHP takes too long
Quick requests work, slow ones end in a 504 after a fixed wait
A 504 from Apache means the backend did not answer within the proxy timeout.
2 causes, each with a fixServers
Apache logs SIGWINCH and exits on its own
the httpd container stops although nothing crashed
SIGWINCH is Apache's graceful-stop signal.
2 causes, each with a fix