rancher控制台的https证书有效期一年,到期后需要手动更新证书。
当rancher证书过期后,会导致rancher控制台无法访问的问题。
解决办法如下:
1.在安装rancher的工具服务器中,运行docker ps命令,查看正在运行的docker容器,找到rancher容器的id。并记录rancher版本号。
2.如果是rancher2.2.8版本,本地电脑新建脚本文件cer.sh, 文件中 rancher_server_id替换成上一步rancher容器id
rancher_server_id=1f7986afab8a
docker exec -ti ${rancher_server_id} mv /var/lib/rancher/management-state/tls/localhost.crt /var/lib/rancher/management-state/tls/localhost.crt-bak
docker exec -ti ${rancher_server_id} mv /var/lib/rancher/management-state/tls/localhost.key /var/lib/rancher/management-state/tls/localhost.key-bak
docker restart ${rancher_server_id}
如果是rancher2.5以上版本,本地电脑新建脚本文件cer.sh,文件中rancher_server_id替换成上一步rancher容器id,rancher_server_url替换成安装rancher电脑ip
rancher_server_id=1f7986afab8a
rancher_server_url=安装rancher电脑ip
docker exec -ti ${rancher_server_id} kubectl --insecure-skip-tls-verify -n kube-system delete secrets k3s-serving
docker exec -ti ${rancher_server_id} kubectl --insecure-skip-tls-verify delete secret serving-cert -n cattle-system
docker exec -ti ${rancher_server_id} rm -f /var/lib/rancher/k3s/server/tls/dynamic-cert.json
docker exec -ti ${rancher_server_id} curl --insecure -sfL https://${rancher_server_url}/v3
docker restart ${rancher_server_id}
- 切换到rancher路径下,例如:cd /home/docker-compose/rancher/ 执行上传命令rz,将cer.sh脚本上传。
- 执行命令chmod 777 cer.sh 对脚本进行授权。
- 执行命令sh cer.sh