首页 > 其他分享 >Rancher Dashboard 无法访问 引申发现K8S报错Unable to connect to the server: x509: certificate has expired or is

Rancher Dashboard 无法访问 引申发现K8S报错Unable to connect to the server: x509: certificate has expired or is

时间:2024-03-27 10:03:15浏览次数:29  
标签:UTC Mar no 无法访问 2024 valid 报错 etcd ca

访问Rancher Dashboard,发现无法访问

由于笔者的rancher是用docker部署的,查看rancher log:

docker logs [container-name]

截取一部分报错如下:

.
.
2024-03-24 06:52:27.085313 I | embed: ready to serve client requests
2024-03-24 06:52:27.085567 I | etcdserver: published {Name:default ClientURLs:[http://localhost:2379]} to cluster cdf818194e3a8c32
2024-03-24 06:52:27.087033 N | embed: serving insecure client requests on 127.0.0.1:2379, this is strongly discouraged!
2024/03/24 06:52:27 [INFO] Waiting for server to become available: Get "https://127.0.0.1:6443/version?timeout=15m0s": dial tcp 127.0.0.1:6443: connect: connection refused
2024/03/24 06:52:29 [INFO] Waiting for server to become available: the server has asked for the client to provide credentials
#后续报错基本就都是 Waiting for server to become available: the server has asked for the client to provide credentials
.
.

初步判断可能是K8S集群的证书出了问题。
然后切到master node,尝试查看pod,发现证书过期,和rancher log中无法访问的报错时间匹配

[root@k8s-master-1 ~]# kubectl get pods
Unable to connect to the server: x509: certificate has expired or is not yet valid: current time 2024-03-26T17:06:36+08:00                                               is after 2024-03-23T11:19:33Z

查看证书过期时间
(1.2版本以上的命令应该为:kubeadm certs check-expiration)

[root@k8s-master-1 ~]# kubeadm alpha certs check-expiration
[check-expiration] Reading configuration from the cluster...
[check-expiration] FYI: You can look at this config file with 'kubectl -n kube-system get cm kubeadm-config -oyaml'
[check-expiration] Error reading configuration from the Cluster. Falling back to default configuration

W0326 17:32:32.371486 1768144 configset.go:348] WARNING: kubeadm cannot validate component configs for API groups [kubelet.config.k8s.io kubeproxy.config.k8s.io]
CERTIFICATE                EXPIRES                  RESIDUAL TIME   CERTIFICATE AUTHORITY   EXTERNALLY MANAGED
admin.conf                 Mar 23, 2024 11:19 UTC   <invalid>                               no
apiserver                  Mar 23, 2024 11:19 UTC   <invalid>       ca                      no
apiserver-etcd-client      Mar 23, 2024 11:19 UTC   <invalid>       etcd-ca                 no
apiserver-kubelet-client   Mar 23, 2024 11:19 UTC   <invalid>       ca                      no
controller-manager.conf    Mar 23, 2024 11:19 UTC   <invalid>                               no
etcd-healthcheck-client    Mar 23, 2024 11:19 UTC   <invalid>       etcd-ca                 no
etcd-peer                  Mar 23, 2024 11:19 UTC   <invalid>       etcd-ca                 no
etcd-server                Mar 23, 2024 11:19 UTC   <invalid>       etcd-ca                 no
front-proxy-client         Mar 23, 2024 11:19 UTC   <invalid>       front-proxy-ca          no
scheduler.conf             Mar 23, 2024 11:19 UTC   <invalid>                               no

renew all certificate

[root@k8s-master-1 ~]# kubeadm alpha certs renew all

再次查看会发现证书已经更新,但只是更新了一年

[root@k8s-master-1 ~]# kubeadm alpha certs check-expiration
[check-expiration] Reading configuration from the cluster...
[check-expiration] FYI: You can look at this config file with 'kubectl -n kube-system get cm kubeadm-config -oyaml'
[check-expiration] Error reading configuration from the Cluster. Falling back to default configuration

W0326 17:40:08.152879 1776164 configset.go:348] WARNING: kubeadm cannot validate component configs for API groups [kubelet.config.k8s.io kubeproxy.config.k8s.io]
CERTIFICATE                EXPIRES                  RESIDUAL TIME   CERTIFICATE AUTHORITY   EXTERNALLY MANAGED

admin.conf                 Mar 26, 2025 09:40 UTC   364d                                    no
apiserver                  Mar 26, 2025 09:40 UTC   364d            ca                      no
apiserver-etcd-client      Mar 26, 2025 09:40 UTC   364d            etcd-ca                 no
apiserver-kubelet-client   Mar 26, 2025 09:40 UTC   364d            ca                      no
controller-manager.conf    Mar 26, 2025 09:40 UTC   364d                                    no
etcd-healthcheck-client    Mar 26, 2025 09:40 UTC   364d            etcd-ca                 no
etcd-peer                  Mar 26, 2025 09:40 UTC   364d            etcd-ca                 no
etcd-server                Mar 26, 2025 09:40 UTC   364d            etcd-ca                 no
front-proxy-client         Mar 26, 2025 09:40 UTC   364d            front-proxy-ca          no
scheduler.conf             Mar 26, 2025 09:40 UTC   364d                                    no

以下为符合docker部署的更新证书的步骤:

#  1、备份证书(非常重要)
cp -r /etc/kubernetes  /etc/kubernetes_bak

#  2、查看证书的有效期 (注意:和老版本的命令不一样)
kubeadm certs check-expiration

#  3、升级证书(谨慎操作)
kubeadm certs renew all

#  4、重启etcd kube-apiserver kube-controller kube-scheduler 4个容器(注意etcd是否有多个,是否和其他重复,例如kuboard)
for i in k8s_etcd kube-apiserver kube-controller-manager kube-scheduler;do
echo ….restart container $i….
docker ps |grep $i | grep -v pause | cut -d " " -f1 | xargs docker restart
done
#或者手动一个一个重启
docker ps | grep k8s_etcd
docker ps | grep k8s_kube-apiserver
docker ps | grep k8s_kube-controller-manager
docker ps | grep k8s_kube-scheduler

docker restart container_id

#  5、再次查看已经升级成功
kubeadm certs check-expiration

# 以上需要在master各个节点操作

#  6、更新证书 (需要在有引用证书的master节点操作)
cp -f /etc/kubernetes/admin.conf  ~/.kube/config

做完以上步骤后,重启rancher. 然后可以正常访问了

然后建议在创建集群初始化的时候,可以设置证书10年过期,方法可参考下面的;
https://blog.csdn.net/xiaoyaoyun518/article/details/134161291

标签:UTC,Mar,no,无法访问,2024,valid,报错,etcd,ca
From: https://www.cnblogs.com/rinya09/p/18098240

相关文章

  • std::sort 错误"Expression : invalid operator <"
    解决:std::sort的比较函数,切记仅使用小于或大于,不要使用小于等于或大于等于。即所谓的“strictweakordering”,也就是说,如果a==b,则返回的应该是false,如果返回的是true,则会出上面的错这个问题是标准库sort实现导致的参考https://blog.csdn.net/qq_35097289/article/details/1046......
  • (离线RAG、chatGLM3-6B)安装了fastchat:0.2.36,仍报错ModuleNotFoundError: No module nam
           在离线知识库服务(Langchain-Chatchat)本地搭建时,虽然在虚拟环境中安装了fastchat:0.2.36,但在运行时,仍报错ModuleNotFoundError:Nomodulenamed'fastchat.protocol'。              经过在网上查询,发现部署成功的案例采用的0.2.34版本的fast......
  • Selenium报错ElementNotInteractableException元素不可交互,该如何解决?
    简介在使用Selenium进行Web自动化测试时,我们可能会遇到各种异常情况。其中之一就是ElementNotInteractableException异常,这通常意味着在尝试与页面元素交互时出现了问题。本文将详细介绍这个异常的原因、可能的解决方法,并提供示例代码来帮助你更好地理解和处理这种情况。......
  • java用es报错ElasticsearchStatusException[Elasticsearch exception [type=x_content
    java报错ElasticsearchStatusException[Elasticsearchexception[type=x_content_parse_exception,reason=[1:55][bool]failedtoparsefield[must]]];nested:ElasticsearchException[Elasticsearchexception[type=parsing_exception,reason=[match]unknowntoke......
  • 报错“由于目标机器积极拒绝,无法连接”怎么解决?
    原文链接:https://www.php.cn/faq/192504.html在我们有时连接sqlserver数据库时,通过本地端的数据库去连接别的机器的数据库,或者是服务器上的数据库,一般会出现“由于目标计算机积极拒绝,无法连接”的字样,那到底是什么原因呢?怎么解决?1、如果出现这样的情况,首先我们要排查对方的机器i......
  • 安装图形化界面时候报错 Transaction check error: file /boot/efi/EFI/centos from
    报错Transactioncheckerror:file/boot/efi/EFI/centosfrominstalloffwupdate-efi-12-5.el7.centos.x86_64conflictswithfilefrompackagegrub2-common-1:2.02-0.65.el7.centos.2.noarch如果在安装过程出现类似这种错误:Transactioncheckerror:file/boot/efi/EFI......
  • Android证书校验出现java.io.IOException: Invalid keystore format错误的解决方案
    使用下面命令keytool-list-v-keystore签名.keystore出现错误java.io.IOException:Invalidkeystoreformat一般出现这种错误的情况有2种可能1.密码错误2.JDK版本问题1.如果是JDK8生成的keystore,然后用JDK11(+)执行是没问题的,当前情况不需要解决,因为是成功......
  • 使用 Validation
    使用Validation要使用验证,请使用class-validator。示例如何在TypeORM中使用class-validator:import{Entity,PrimaryGeneratedColumn,Column}from"typeorm";import{Contains,IsInt,Length,IsEmail,IsFQDN,IsDate,Min,Max}from"class-validator";......
  • typestack/class-validator
    typestack/class-validatorPublicNotificationsFork 756 Star 10.4k CodeIssues217Pullrequests29DiscussionsActionsSecurityInsights typestack/class-validator   develop4 Branches25 Tags  Code......
  • requests.exceptions.MissingSchema: Invalid URLrequests.exceptions.ConnectionErro
    代码如下,运行时出现 requests.exceptions.ConnectionError:HTTPSConnectionPool(host='www.dropbox.com',port=443):Maxretriesexceededwithurl:/s/dm3m1o0tsv9terq/pytorch_model.bin?dl=1(CausedbyNewConnectionError('<urllib3.connection.HTTPSConne......