Skip to content

connection to the server :6443 was refused: API server won't start

Kubernetestested on RKE2 v1.37.2

If port 6443 refuses, the API server isn't running. kubectl can't help then – but crictl, journalctl and the files under /var/log/pods on the control plane node work without Kubernetes.

Symptom

kubectl get nodes
systemctl is-active rke2-server
The connection to the server 127.0.0.1:6443 was refused - did you specify the right
  host or port?
activating

rke2-server hangs in activating: it waits for an API server that never becomes ready. Running pods keep working, but controllers, scheduler and kubectl stand still.

Diagnosis

crictl asks containerd directly. Container log, the same line as a file under /var/log/pods and the rendered static pod manifest.

sudo -i crictl ps -a --name kube-apiserver | tr -s ' ' | cut -c1-88
sudo -i crictl logs $(sudo -i crictl ps -a --name kube-apiserver -q | head -1) 2>&1 \
  | tail -1 | cut -c1-88
sudo grep feature-gates /var/lib/rancher/rke2/agent/pod-manifests/kube-apiserver.yaml
CONTAINER IMAGE CREATED STATE NAME ATTEMPT POD ID POD NAMESPACE
4f2b11200f3d4 6d31c161dcb90 10 seconds ago Exited kube-apiserver 3 a1664c15bb8a3 kube-ap
E1120 14:40:25.164233       1 run.go:72] "command failed" err="unrecognized feature gate
    - --feature-gates=DebugBuchGate=true

Causes

Unknown flagkube-apiserver exits while parsing its flags

In the course it's a feature gate that doesn't exist – like one an upgrade has removed: unrecognized feature gate: DebugBuchGate. The kubelet keeps restarting the static pod, ATTEMPT goes up.

Log survivesThe container is already gone

The file under /var/log/pods survives even when the container is deleted. The journal of rke2-server shows it waiting for the API server.

sudo sh -c 'tail -qn1 /var/log/pods/kube-system_kube-apiserver-*/kube-apiserver/*.log' \
  | sed 's/^[^ ]* [^ ]* F //' | cut -c1-88
sudo journalctl -u rke2-server -b --no-pager | grep -o 'Polling for API server.*' \
  | tail -1 | cut -c1-88
E1120 14:40:25.164233       1 run.go:72] "command failed" err="unrecognized feature gate
Polling for API server readiness: GET /readyz failed: Get \"https://127.0.0.1:6443/ready

Fix

RKE2 rewrites the static pod manifest on every start, so correcting the configuration and restarting rke2-server is enough. In the lab that takes just under a minute.
sudo rm /etc/rancher/rke2/config.yaml.d/90-kaputt.yaml
sudo rmdir /etc/rancher/rke2/config.yaml.d
sudo systemctl restart rke2-server
kubectl get --raw /readyz; echo
sudo -i crictl ps --name kube-apiserver | tr -s ' ' | cut -c1-88
ok
CONTAINER IMAGE CREATED STATE NAME ATTEMPT POD ID POD NAMESPACE
86397b7cb87e9 6d31c161dcb90 36 seconds ago Running kube-apiserver 0 85353367e72ff kube-a

Don't: Editing the manifest under pod-manifests by hand. RKE2 rewrites it on the next start.

▶
Break it yourself and find it – free
Debugging Kubernetes, day 15: API server, etcd, static pods and expired certificates – with an etcd snapshot before every change and a drill to reproduce each one.
Go to day 15 →

FAQ

What should I do before touching the control plane?

Take an etcd snapshot. The course does that before every change.

How do I know the API server is healthy again?

kubectl get --raw /readyz answers ok. /readyz?verbose lists every single check; a failed one is marked with [-].

Related error patterns

More