Update k3s Certificates
This happens every year around May 6th. The connection to the k3s service goes down and Kubectl command won't work. Here is how to fix it (do this within 90 days of certification expiry):
NOTE: Make sure that Openstack authentication environment is enabled. Otherwise, "openstack" commands will not work. This is only used if you want to remove dangling pods at the end of the procedure.
Check for CA expiration (controller). No CA renewal needed -> option A. CA renewal needed -> option B
Does any CA expire within 365 days? This check can be copied and pasted to the command line.
sudo bash -c 'cat << "EOF" | bash
echo " K3s CA-expiry check (warning window: 365 days)"
warn_days=365
rotate_ca_needed=0
for crt in /var/lib/rancher/k3s/server/tls/*-ca.crt; do
end=$(openssl x509 -enddate -noout -in "$crt" | cut -d= -f2)
left=$(( ( $(date -d "$end" +%s) - $(date +%s) ) / 86400 ))
printf " %-26s expires %-25s (%s days left)\n" "$(basename "$crt")" "$end" "$left"
[[ $left -lt $warn_days ]] && rotate_ca_needed=1
done
if [[ $rotate_ca_needed -eq 0 ]]; then
echo -e "\n CA > $warn_days d: use **Option A** (leaf-only restart)"
else
echo -e "\n CA < $warn_days d: use **Option B** (full CA rotation)"
fi
EOF'Option A: Leaf-only renewal (most years)
Check if the certificates are one year old, also check the status of k3s service if it contains logs like: "x509: certificate has expired or is not yet valid". Check correct function of k3s.
k3s restart (controller) K3s sees the certs < 90 days from expiry, issues new leaf certs at startup.
k3s agent restart (all worker nodes)
Verify (controller)
Copy fresh kubeconfig (controller) Check if k3s.yaml is different than kubeconfig.yml
If different, then copy k3s.yaml and do service restarts
if there are dangling zun containers left on the workers delete them (controller)
Copy and paste this on the command line.
Option B: Full CA rotation (rare)
Check if the certificates are one year old, also check the status of k3s service if it contains logs like: "x509: certificate has expired or is not yet valid". Check correct function of k3s.
Prepare new CA (controller)
k3s secret deletion (controller)
k3s restart (controller)
k3s agent restart (all worker nodes)
Verify (controller)
Copy fresh kubeconfig (controller)
if there are dangling zun containers left on the workers delete them (controller)
Copy and paste this on the command line.
Last updated