metrics-apiserver stays Ready indefinitely when it cannot establish its gRPC connection to keda-operator
Report
In KEDA 2.20.2, keda-operator-metrics-apiserver pods intermittently starts up (or reconnect) and then fail to establish their gRPC connection to keda-operator:9666 for minutes to hours. During that time the pod stays Ready, is never restarted, and keeps receiving HPA external-metric requests from the APIService, all of which fail.
This is the same symptom as #7251. The keepalive/state-wait changes in #7463 and the backoff fix in #7857 reduced how often we see it (compared with 2.19.0), but didn't eliminate it.
I'm seeing this across multiple clusters.
Expected Behavior
If the adapter can't establish (or re-establish) its gRPC connection to the operator within a bounded time, it should surface that, so Kubernetes can recover it. For example:
- a readiness check that reflects the gRPC connection state, so the APIService stops routing requests to that replica, and/or
- a liveness check (or process exit) after the connection has been unavailable for N minutes, so the pod gets restarted.
Actual Behavior
The adapter's liveness/readiness probes (/healthz, /readyz) are the generic apiserver checks. In cmd/adapter/main.go (v2.20.2)I couldn't find a check tied to the metrics-service gRPC client state. The pod stays Ready and keeps serving failed metric requests until something external restarts it.
An example of this behaviour
- 16:14: Operator leader changes (pods were rescheduled by node consolidation). The existing adapter replica (A) logs a short burst of
connect: connection refused(dials landing on the non-leader operator pod), reconnects in ~10s, and serves metrics with zero gRPC timeouts for the rest of the window. - 16:14: a new adapter replica (B) starts on a different node. Every dial attempt for the next 2 hours fails with
i/o timeout. The provider cyclesIDLE→CONNECTING→TRANSIENT_FAILURE, and "successfully established" is never logged. Throughout, B stays Ready and logs ~800timeout while waiting to establish gRPC connectionerrors against incoming HPA requests. - 18:13: B is evicted by node consolidation. It never connected.
Both replicas dialed the same Service ClusterIP (sessionAffinity: None, kube-proxy iptables mode) while the operator was up and reachable. So the dropped packets are specific to B's network path, not the operator.
Steps to Reproduce the Problem
I can't reproduce the underlying connection failure on demand. It shows up regularly when KEDA pods are rescheduled often
Logs from KEDA operator
The operator shows nothing unusual during these windows. The other adapter replica is served normally at the same time.
Logs from the affected metrics-apiserver replica (B):
INFO keda_metrics_adapter.provider Waiting for establishing a gRPC connection to KEDA Metrics Server {"currentState": "TRANSIENT_FAILURE"}
W [core] [Channel #1 SubChannel #2] grpc: addrConn.createTransport failed to connect to {Addr: "<keda-operator ClusterIP>:9666", ServerName: "keda-operator.keda.svc.cluster.local:9666", }. Err: connection error: desc = "transport: Error while dialing: dial tcp <keda-operator ClusterIP>:9666: i/o timeout"
E provider.go:#] "msg"="timeout" "error"="timeout while waiting to establish gRPC connection to KEDA Metrics Service server" "logger"="keda_metrics_adapter.provider" "server"="keda-operator.keda.svc.cluster.local:9666"
E status.go:#] "Unhandled Error" err="apiserver received an error that is not an metav1.Status: &errors.errorString{s:\"timeout while waiting to establish gRPC connection to KEDA Metrics Service server\"}"
E writers.go:#] "Unhandled Error" err="apiserver was unable to write a JSON response: http: Handler timeout"
KEDA Version
2.20.2
Kubernetes Version
1.36
Platform
Amazon Web Services
Scaler Details
Several, but this example was prometheus
Would you be open to contributing a fix?
None
Anything else?
Related:
- #7251 — same symptom; closed via #7463
- #7874 — adapter fails to reconnect after the operator pod moves; closed as stale, not fixed. It asked for the same kind of recovery (retry, exit, or liveness check)
- #7879 —
too_many_pingsGoAway on 2.20.x. We also see this occasionally, but it isn't what's happening in the example above (no GoAway preceded it)
Source: kedacore/keda