处理 k8s Rancher 证书过期
2024-11-21 06:42:25 # Technical # Operation
1
2
$ kubectl get ns
The connection to the server 10.253.209.33:8443 was refused - did you specify the right host or port?
  1. 先查看 docker 服务是否正常

    1
    $ systemctl status docker
  2. 如果 docker 服务正常的,k8s 可能是通过 rancher 启动的,查看 rancher 日志

    1
    $ docker logs -f --tail 100 <rancher>

    如果出现以下内容:

    1
    time="2021-03-29T00:28:18.603256144Z" level=fatal msg="starting tls server: Get  https://localhost:6444/apis/apiextensions.k8s.io/v1beta1/customresourcedefinitions: x509: certificate has expired or is not yet valid"

    说明是证书过期导致的

处理过程:

  1. 先禁用 ntp 时钟同步

    1
    $ timedatectl set-ntp false
  2. 调整事件到证书过期前

    1
    $ date -s '2021-01-01 00:00:00'
  3. 进入 rancher 容器,删除证书

    1
    2
    $ docker exec -it <rancher> bash
    $ mv /var/lib/rancher/k3s/server/tls*.crt /opt/
  4. 重启 rancher

    1
    $ docker restart <rancher>
  5. 如果 rancher 启动后报错:

    1
    certificate signed by unknown authority

    需要再重启一次

    1
    $ docker restart <rancher>
  6. 恢复 ntp 服务

    1
    2
    $ timedatectl set-ntp 0
    $ date -s '....'