rancher: [RFE] Improve CAPR error messaging -- vague certificate errors encountered do not provide enough context to effectively debug CAPR

This issue will serve to track an improvement in error messaging when CAPR/K3s/RKE2 are not functioning properly. The most noisy error message encountered in the logs of the rancher-system-agent will generally state that there are certificates missing for kube-scheduler and kube-controller-manager; however, this is expected as CAPR relies on the corresponding Kubernetes component to generate a self-signed certificate.

These certificates are used by CAPR to determine the health of the corresponding components. Without the certificates, we cannot reliably connect to the healthz endpoint of the component.

Because of how bootstrapping of K8s components happens within RKE2, if there is a problem starting the container runtime or the components are unable to start, the user is left with their rancher-system-agent continuously reporting that the certificates were not generated.

In this case, the correct course of action is to

  1. Verify RKE2 is properly installed
  2. Verify RKE2 has started and the components have started

Misconfiguration of RKE2, bad networking configurations, overly restrictive systems (read-only file systems, selinux policies, etc.) can all lead to RKE2 being unable to bootstrap the components into place, thus leading to the certificates never being generated.

As such, I think the correct thing to do here would be add additional logic to CAPR + system-agent to check the status of RKE2 and report the problems as such. There realistically is no reason to run the probes against the components until RKE2 has started/is running.

For users that are encountering this issue, if you believe your issue to be unique, please collect as much data as possible from your machines. A logs collector dump is likely the most helpful: https://github.com/rancherlabs/support-tools/tree/master/collection/rancher/v2.x/logs-collector

Original Title: Certs and directory /var/lib/rancher/rke2/server/tls/kube-scheduler and /var/lib/rancher/rke2/server/tls/kube-controller-manager missing

Original Issue Contents Below:

Rancher Server Setup

  • Rancher version: 2.7.3
  • Installation option (Docker install/Helm Chart): HELM
    • K3S v1.25.9+k3s1

Information about the Cluster

  • Kubernetes version: v1.25.9+rke2r1
  • Cluster Type (Downstream):
    • If downstream, what type of cluster? (Custom/Imported or specify provider for Hosted/Infrastructure Provider):
    • Custom
    • Node VM OS Ubuntu 22.04

User Information

  • What is the role of the user logged in? Admin

Describe the bug When creating a new custom cluster via Rancher’s UI, the nodes that I try to add are stuck in “reconcilling” sate.

To Reproduce

  1. Create a new cluster on Rancher UI following documentation: https://ranchermanager.docs.rancher.com/reference-guides/cluster-configuration/rancher-server-configuration/rke2-cluster-configuration All parameters to default except: Kubernetes Version: v1.25.9+rke2r1 Container Network: Calico NGINX Ingress: Selected or not I had the same problem

  2. Register a node Keep all roles selected in step 1 Select “Insecure” in step 2 Copy and paste the cmd to the first node

Result The node stay in “reconcilling” state with this message: “Waiting for probes: kube-apiserver, kube-controller-manager, kube-scheduler”

Command to obtain logs on the node: sudo journalctl -u rancher-system-agent.service -f

Logs obtained: May 24 13:26:56 s001kubed01 rancher-system-agent[16705]: time="2023-05-24T13:26:56Z" level=error msg="error loading CA cert for probe (kube-scheduler) /var/lib/rancher/rke2/server/tls/kube-scheduler/kube-scheduler.crt: open /var/lib/rancher/rke2/server/tls/kube-scheduler/kube-scheduler.crt: no such file or directory" May 24 13:26:56 s001kubed01 rancher-system-agent[16705]: time="2023-05-24T13:26:56Z" level=error msg="error while appending ca cert to pool for probe kube-scheduler" May 24 13:26:57 s001kubed01 rancher-system-agent[16705]: time="2023-05-24T13:26:57Z" level=error msg="error encountered during parsing of last run time: parsing time \"\" as \"Mon Jan _2 15:04:05 MST 2006\": cannot parse \"\" as \"Mon\"" May 24 13:26:57 s001kubed01 rancher-system-agent[16705]: time="2023-05-24T13:26:57Z" level=error msg="error loading CA cert for probe (kube-controller-manager) /var/lib/rancher/rke2/server/tls/kube-controller-manager/kube-controller-manager.crt: open /var/lib/rancher/rke2/server/tls/kube-controller-manager/kube-controller-manager.crt: no such file or directory" May 24 13:26:57 s001kubed01 rancher-system-agent[16705]: time="2023-05-24T13:26:57Z" level=error msg="error while appending ca cert to pool for probe kube-controller-manager" May 24 13:26:57 s001kubed01 rancher-system-agent[16705]: time="2023-05-24T13:26:57Z" level=error msg="error loading CA cert for probe (kube-scheduler) /var/lib/rancher/rke2/server/tls/kube-scheduler/kube-scheduler.crt: open /var/lib/rancher/rke2/server/tls/kube-scheduler/kube-scheduler.crt: no such file or directory" May 24 13:26:57 s001kubed01 rancher-system-agent[16705]: time="2023-05-24T13:26:57Z" level=error msg="error while appending ca cert to pool for probe kube-scheduler" May 24 13:27:01 s001kubed01 rancher-system-agent[16705]: time="2023-05-24T13:27:01Z" level=error msg="error encountered during parsing of last run time: parsing time \"\" as \"Mon Jan _2 15:04:05 MST 2006\": cannot parse \"\" as \"Mon\""

Directories “/var/lib/rancher/rke2/server/tls/kube-controller-manager” and “/var/lib/rancher/rke2/server/tls/kube-scheduler” are indeed missing. So are the CRTs (not even misplaced)

Expected Result The node get registered automatically

Thanks for your help 😄

About this issue

  • Original URL
  • State: open
  • Created 3 years ago
  • Reactions: 24
  • Comments: 54 (2 by maintainers)

Most upvoted comments

same issue on Rancher 2.7.9, Calico, 1.26.8+rke2r1

This is still an issue with k8s 1.28.8-rke2r1 and Rancher 2.8.3

This still fixes it for me.

timeout 1 openssl s_client -connect 127.0.0.1:10259 -showcerts 2>&1 | grep -A 19 -m 1 'BEGIN CERTIFICATE' | sudo tee /var/lib/rancher/rke2/server/tls/kube-scheduler/kube-scheduler.crt
timeout 1 openssl s_client -connect 127.0.0.1:10257 -showcerts 2>&1 | grep -A 19 -m 1 'BEGIN CERTIFICATE' | sudo tee /var/lib/rancher/rke2/server/tls/kube-controller-manager/kube-controller-manager.crt

It’s interesting that this problem occurs (at least in my case) only when I’m using RockyLinux 9.2… I tried the exact same stack but this time Ubuntu 20.04.6LTS and everything went as it should.

With Ubuntu 22.04 it doesn’t work for me.

Hi, good news, we have find the root cause,

We had the options “noexec” on /var mountpoint in /etc/fstab, so some execution scripts could’nt be executed.

/dev/mapper/rootvg-var /var ext4 defaults,noexec,nosuid,nodev 1 2

This is because we are using already hardened RHEL iso version.

I fixed the issue with disabling IPv6 IP-addresses on master nodes. When the first node was bootstrapped it tried to connect with two other node with IPv6 and failed. After disabling all works fine.

Had the same issue with ubuntu 22.04. If you started rancher server with docker run, please note the version compatibility of rancher and docker, see here: https://www.suse.com/suse-rancher/support-matrix/all-supported-versions/rancher-v2-8-5/, For example, rancher 2.8.5, when I use docker 27.1.1, it’s not OK, but when I switch to docker 24.0.9 , it’s OK.

We are also facing this same issue.

Racher Version: v2.8.4

  • Hosted via Docker on Ubuntu Server 24.04 LTS

Cluster Config:

  • Tested Kubernetes Version: v1.28.9+rke2r1 and v1.26.15+rke2r1
  • Tested Container Network: Calico and Cilium

All Nodes and the rancher server are hosted on Hyper-V using Ubuntu Server LTS 24.04 within the same V Switch.

For us, we had to manually created the etcd user and additionally make sure to set the kernel parameters https://docs.k3s.io/security/hardening-guide#set-kernel-parameters

Kubernetes 1.24.17 - cis 1.6

The Problem still occurs and it is not a fstab error. Pretty urgend issue if so many have that problem

open /var/lib/rancher/rke2/server/tls/kube-controller-manager/kube-controller-manager.crt: no such file or directory
open /var/lib/rancher/rke2/server/tls/kube-scheduler/kube-scheduler.crt: no such file or directory
error while appending ca cert to pool for probe kube-scheduler
root@master-1:/var/lib/rancher/rke2/server/tls# ll
total 148
drwx------ 4 root root 4096 Sep 26 22:03 ./
drwxr-xr-x 7 root root 4096 Sep 26 22:03 ../
-rw-r--r-- 1 root root 1177 Sep 26 22:03 client-admin.crt
-rw------- 1 root root  227 Sep 26 22:03 client-admin.key
-rw-r--r-- 1 root root 1186 Sep 26 22:03 client-auth-proxy.crt
-rw------- 1 root root  227 Sep 26 22:03 client-auth-proxy.key
-rw-r--r-- 1 root root  570 Sep 26 22:03 client-ca.crt
-rw------- 1 root root  227 Sep 26 22:03 client-ca.key
-rw-r--r-- 1 root root  570 Sep 26 22:33 client-ca.nochain.crt
-rw-r--r-- 1 root root 1165 Sep 26 22:03 client-controller.crt
-rw------- 1 root root  227 Sep 26 22:03 client-controller.key
-rw-r--r-- 1 root root 1181 Sep 26 22:03 client-kube-apiserver.crt
-rw------- 1 root root  227 Sep 26 22:03 client-kube-apiserver.key
-rw-r--r-- 1 root root 1149 Sep 26 22:03 client-kube-proxy.crt
-rw------- 1 root root  227 Sep 26 22:03 client-kube-proxy.key
-rw------- 1 root root  227 Sep 26 22:03 client-kubelet.key
-rw-r--r-- 1 root root 1165 Sep 26 22:03 client-rke2-cloud-controller.crt
-rw------- 1 root root  227 Sep 26 22:03 client-rke2-cloud-controller.key
-rw-r--r-- 1 root root 1153 Sep 26 22:03 client-rke2-controller.crt
-rw------- 1 root root  227 Sep 26 22:03 client-rke2-controller.key
-rw-r--r-- 1 root root 1153 Sep 26 22:03 client-scheduler.crt
-rw------- 1 root root  227 Sep 26 22:03 client-scheduler.key
-rw-r--r-- 1 root root 1189 Sep 26 22:03 client-supervisor.crt
-rw------- 1 root root  227 Sep 26 22:03 client-supervisor.key
-rw-r--r-- 1 root root 3019 Sep 26 22:03 dynamic-cert.json
drwxr-xr-x 2 root root 4096 Sep 26 22:03 etcd/
-rw-r--r-- 1 root root  595 Sep 26 22:03 request-header-ca.crt
-rw------- 1 root root  227 Sep 26 22:03 request-header-ca.key
-rw-r--r-- 1 root root  574 Sep 26 22:03 server-ca.crt
-rw------- 1 root root  227 Sep 26 22:03 server-ca.key
-rw-r--r-- 1 root root  574 Sep 26 22:33 server-ca.nochain.crt
-rw------- 1 root root 1679 Sep 26 22:33 service.current.key
-rw------- 1 root root 1679 Sep 26 22:03 service.key
-rw-r--r-- 1 root root 1400 Sep 26 22:03 serving-kube-apiserver.crt
-rw------- 1 root root  227 Sep 26 22:03 serving-kube-apiserver.key
-rw------- 1 root root  227 Sep 26 22:03 serving-kubelet.key
drwx------ 2 root root 4096 Sep 26 22:03 temporary-certs/

Rancher RKE2 Cluster Config: KubeVersion: v1.24.17+rke2r1 CNI: cilium Default Pod Security Policy: RKE2 Default Worker CIS Profile: cis-1.6

System Services: {CoreDNS, Metrics Server} Members: {…} ETCD: auto snapshots enabled (default)

Cluster CIDR: 10.42.0.0/16 Service CIDR: 10.43.0.0/16

Advanced.“Raise error if kernel parameters are different than the expected kubelet defaults”: true

I fixed the issue with disabling IPv6 IP-addresses on master nodes. When the first node was bootstrapped it tried to connect with two other node with IPv6 and failed. After disabling all works fine.

In my env, I need the dual-stack ip addresses.

You can check my repo where I’ve fixed the issue (WORKING DUAL STACK !!), if you intend to use this code as is, you have to change the rancher agent version to v2.7-head on line 40 (var VERSION) of the file cmd/agent/main.go