rancher: Rancher cluster can't schedule deployments anymore, k8s events show "FailedCreate" and "x509: certificate has expired or is not yet valid"

Rancher Server Setup

  • Rancher version: v2.5.5

  • k3s version: v1.18.8+k3s1

  • Installation option Docker install

Information about the Cluster

  • Kubernetes version: Client Version: version.Info{Major:“1”, Minor:“18”, GitVersion:“v1.18.8+k3s1”, GitCommit:“6b595318666804506c19cfc3d3d228423d38fab1”, GitTreeState:“clean”, BuildDate:“2020-08-14T20:42:29Z”, GoVersion:“go1.13.15”, Compiler:“gc”, Platform:“linux/amd64”} Server Version: version.Info{Major:“1”, Minor:“18”, GitVersion:“v1.18.8+k3s1”, GitCommit:“6b595318666804506c19cfc3d3d228423d38fab1”, GitTreeState:“clean”, BuildDate:“2020-08-14T20:42:29Z”, GoVersion:“go1.13.15”, Compiler:“gc”, Platform:“linux/amd64”}

  • Cluster Type (Local)

Describe the bug

We noticed problems with some PODs running in our cluster, namely some PODs were evicted, others had health problems and weren’t ready. Quick solution was to try and restart those PODs. But none of the killed PODs got started afterwards, deployments complained about inability to start PODs.

K8s events show messages like

Reason: FailedCreate
Message: (combined from similar events): Error creating: pods "my-deployment-6655f8b747-" is forbidden: Get "https://[::1]:6443/api/v1/namespaces/my-namespace/limitranges": x509: certificate has expired or is not yet valid: current time 2023-06-08T13:21:22Z is after 2022-02-27T

I tried to run the following script on the host that runs the rancher server docker container to check if a known cert has expired:

#!/bin/sh
CONFIG_DIR=/opt/rancher
for i in `ls ${CONFIG_DIR}/k3s/server/tls/*.crt`; do
	echo $i
	openssl x509 -enddate -noout -in $i
done

echo serving-cert
docker exec rancher-server k3s kubectl get secret -n cattle-system serving-cert -o jsonpath='{.data.tls\.crt}' | base64 -d | openssl x509 -noout -text | grep Not
echo k3s-serving
docker exec rancher-server k3s kubectl get secret -n kube-system k3s-serving -o jsonpath='{.data.tls\.crt}' | base64 -d | openssl x509 -noout -text | grep Not

which produced the following output ( which looks like they are ok )

# ./show-rancher-certs.sh
/opt/rancher/k3s/server/tls/client-admin.crt
notAfter=Apr 22 22:00:33 2024 GMT
/opt/rancher/k3s/server/tls/client-auth-proxy.crt
notAfter=Apr 22 22:00:33 2024 GMT
/opt/rancher/k3s/server/tls/client-ca.crt
notAfter=Oct 27 16:55:05 2030 GMT
/opt/rancher/k3s/server/tls/client-cloud-controller.crt
notAfter=Dec 16 01:53:24 2023 GMT
/opt/rancher/k3s/server/tls/client-controller.crt
notAfter=Apr 22 22:00:33 2024 GMT
/opt/rancher/k3s/server/tls/client-k3s-controller.crt
notAfter=Dec 16 01:53:24 2023 GMT
/opt/rancher/k3s/server/tls/client-kube-apiserver.crt
notAfter=Apr 22 22:00:33 2024 GMT
/opt/rancher/k3s/server/tls/client-kube-proxy.crt
notAfter=Apr 22 22:00:33 2024 GMT
/opt/rancher/k3s/server/tls/client-scheduler.crt
notAfter=Apr 22 22:00:33 2024 GMT
/opt/rancher/k3s/server/tls/request-header-ca.crt
notAfter=Oct 27 16:55:05 2030 GMT
/opt/rancher/k3s/server/tls/server-ca.crt
notAfter=Oct 27 16:55:05 2030 GMT
/opt/rancher/k3s/server/tls/serving-kube-apiserver.crt
notAfter=Apr 22 22:00:33 2024 GMT
serving-cert
            Not Before: Oct  1 10:54:25 2019 GMT
            Not After : Feb  1 07:56:09 2024 GMT
k3s-serving
            Not Before: Oct 29 16:55:05 2020 GMT
            Not After : Jun  7 14:00:59 2024 GMT

To Reproduce

???

Result

Cluster is stuck in limbo, can not start any new PODs for deployments.

Expected Result

Killing a POD automatically brings up a new one.

Any help appreciated !

About this issue

Most upvoted comments

@Martin-Weiss Thank you very much for helping me thru this issue - you saved my day !!!

After I have restarted those kube-apiserver containers within my rancher agent nodes the cluster got in a stable state again !

@manuel-koch - yes - I guess restarting them makes sense. P.S. you should really upgrade ASAP and on a regular basis! Kubernetes 1.19 is out of general support since a very long time… even 1.23 just got deprecated upstream… see https://endoflife.date/kubernetes