October 19, 2024

Annoying message when to execute kubectl…

Unable to connect to the server: tls: failed to verify certificate: x509: certificate has expired or is not yet valid: current time 2024-04-12T20:43:51+09:00 is after 2024-01-17T01:39:04Z

If you are aware that a certificate has expired, you can check it with

kevin@computer:~$ sudo microk8s.refresh-certs -c

The CA certificate will expire in 3198 days.
The server certificate will expire in -87 days.
The front proxy client certificate will expire in -87 days.

You can update each certificate by running the command

kevin@computer:~$ sudo microk8s.refresh-certs --cert=front-proxy-client.crt
Taking a backup of the current certificates under /var/snap/microk8s/6571/certs-backup/
Creating new certificates
Signature ok
subject=CN = front-proxy-client
Getting CA Private Key
Restarting service kubelite.

kohei@computer:~$ sudo microk8s.refresh-certs -c
The CA certificate will expire in 3198 days.
The server certificate will expire in -87 days.
The front proxy client certificate will expire in 364 days.

kevin@computer:~$ microk8s status
microk8s is running

Reference

https://www.ytyng.com/blog/update-certificates-in-microk8s-kubernbetes/