Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Servers, nginx and Docker

kubectl cannot reach the Kubernetes API server on port 6443

ErrorUnable to connect to the server

Short 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.

  • Applies to Kubernetes 1.31 to 1.34 with kubeadm and containerd, Ubuntu 24.04
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 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/version
  2. 2Match what you see, then jump to its fix

    1. 1The server address in the error is not your control plane's address.kubectl uses the wrong or missing kubeconfigFix
    2. 2From another machine curl is refused or hangs, while on the control plane node itself it answers.A firewall blocks port 6443Fix
    3. 3The refusal also happens on the control plane node itself, and kubelet logs show the API server container restarting.kube-apiserver is not runningFix

What does the error look like?

  • Unable to connect to the server
  • dial 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-contexts

2Fix

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 version

Confirmed by kubernetes.io

Did this fix it?

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 numbered

2Fix

Allow the port. If the node sits behind a cloud firewall or security group, open it there too.

sudo ufw allow 6443/tcp

3Verify

From the other machine the API server answers.

curl -vk https://<control-plane-ip>:6443/version

Confirmed by kubernetes.io

Did this fix it?

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 kubelet

3Verify

A kube-apiserver container is Running and the version call answers.

sudo crictl ps | grep kube-apiserver
kubectl get nodes

Confirmed by kubernetes.io

Did this fix it?

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

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 fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.