kubernetes: Kubelet serving CSR never created
What happened?
We are seeing an issue occasionally where the kubelet never gets the server certificate (serverTLSBootstrap: true).
We have an auto-approver for the server certificates and detect this issue because we are waiting for the certificate to appear in /var/lib/kubelet/pki/kubelet-server-current.pem. When we hit it, not even the CSR is created.
It started happening after upgrading to v1.32 so we believe it could be from a change that was introduced in v1.32.
Restarting the kubelet does not help. It happily continues without the server certificate, even though it is configured to bootstrap it.
In healthy clusters, we see this:
$ kubectl get csr
NAME AGE SIGNERNAME REQUESTOR REQUESTEDDURATION CONDITION
csr-8dql4 29s kubernetes.io/kubelet-serving system:node:lennart-kubelet-debug <none> Pending
csr-r8ztr 17s kubernetes.io/kubelet-serving system:node:lennart-kubelet-debug <none> Pending
csr-xtwpf 30s kubernetes.io/kube-apiserver-client-kubelet system:node:lennart-kubelet-debug <none> Approved,Issued
In faulty clusters, there is just the client CSR.
We are not sure why two CSRs are created for the server either, but it works when we approve the newer of them.
Edit: The two server CSRs happen because kubeadm restarts the kubelet as part of initializing. This is how it picks up the client certificate. After the restart, the kubelet does not “remember” its old server CSR so it creates a new. This is not an issue.
Here is the kubelet config from an affected node: kubelet-config.txt
What did you expect to happen?
When configured, the kubelet should always create the server CSR.
How can we reproduce it (as minimally and precisely as possible)?
Unfortunately we do not have any guaranteed reproduction steps. In general, this is what is needed to trigger the issue:
- Kubelet is configured to rotate certificates (default) and to use server certificate.
- Node status is stable, i.e. there are no changes of any kind that would cause the kubelet to update the status.
- Kubelet is restarted and the server certificate does not exist (e.g. because it was removed or it wasn’t issued yet).
In this specific case you should be able to see that the CSR is not created:
$ kubectl get csr
NAME AGE SIGNERNAME REQUESTOR REQUESTEDDURATION CONDITION
csr-2mq8h 22s kubernetes.io/kube-apiserver-client-kubelet system:node:lennart-kubelet-debug <none> Approved,Issued
$ kubectl get nodes
NAME STATUS ROLES AGE VERSION
lennart-kubelet-debug Ready control-plane 28s v1.32.1
Anything else we need to know?
I believe the culprit is https://github.com/kubernetes/kubernetes/pull/128640. Not the randomization of the interval, but the change in how the zero case for the lastStatusReportTime is handled.
It used to be treated as expired and trigger an update. After the PR it is treated the opposite.
This means that patchNodeStatus is never called and consequently neither is setLastObservedNodeAddresses.
The latter is initializing the kubelets internal node address state (not node status).
This internal state is what the server certificate manager is relying on to create the CSR. As long as it is nil, i.e. as long as the node status hasn’t been patched, it cannot progress.
Kubernetes version
$ kubectl version
Client Version: v1.32.1
Kustomize Version: v5.5.0
Server Version: v1.32.1
Cloud provider
OS version
# On Linux:
$ cat /etc/os-release
# paste output here
$ uname -a
# paste output here
Install tools
Container runtime (CRI) and version (if applicable)
Related plugins (CNI, CSI, …) and versions (if applicable)
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 27 (25 by maintainers)
yep, I think you are right, that looks wrong, it should start reporting periodically
I see, and
kl.clock.Since(kl.lastStatusReportTime)wasnow - zero, that is why it got triggered@lentzi90 before we didn’t update the node if it didn’t change
https://github.com/kubernetes/kubernetes/blame/3184eb3d1b2b07b3b68eff5240eb8a8e20bb0d07/pkg/kubelet/kubelet_node_status.go#L484-L488
so that logic looks correct, if there was no update and the node didn’t change, we don’t update.
I think we need to understand what is the heuristic to detect the node change
EDIT
ups, wrong, place , there are two loops that update the node
fastNodeStatusUpdateandtryUpdateNodeStatus, you are changing the later, taking a look now 👀kubeadm has no recent changes related to the kubelet-finalize phase (minus this). that phase requires the kubelet restart to truly enable kubelet client cert rotation.
kubeadm does the following on join:
on init:
if the kubelet knows about the requirement for server cert rotation (from config) but it never creates the csr due to restarts, that seems like a kubelet bug.
This is reproducible maybe 5-10% of the cluster creations, so I don’t think it is about wrong configuration or feature gates.
Minimal test environments seem never produce this same issue, the only reproductions we’ve found are when something goes wrong 100% of the time (like using the link-local ipv6 address. That breaking the node’s addresses shouldn’t happen either IMO, but maybe let’s discuss that in another issue.)
Checking the changelog, most of the Kubelet and CSR related changes were done in 1.31 already, where no issues have been seen. That’d further exclude #126441 and #125813 IMO, but thanks @lentzi90 for verifying that with a test too.
Kubelet is not logging basically anything on any log level related to server certs is also making it hard to debug. The whole DynamicCertificateManager code is silent, and kubelet itself is also very silent on the very few lines it has related to certs. For client certs it at least says something, but server cert path is so silent.
One further finding related to CSRs are that in k8s 1.32, the second server CSR request comes 15 seconds later than the first. In 1.31 and older, they were only few seconds apart. This also happens on minimal kubeadm init based test env. I’ve also not found a reason why this is happening and if its somehow related or not.
It would also be interesting to understand why there is always 2 server CSRs and why the first one never means anything. The contents are basically the same, same requestor, same CSR input, …