Unable to connect to the server: x509: certificate signed by unknown authority

时间:2023-03-09 03:19:50
Unable to connect to the server: x509: certificate signed by unknown authority

0x00 Problem

在使用二进制搭建 k8s 集群的过程中,使用 kubectl get 等操作时始终显示 x509: certificate signed by unknown authority :

[root@k8sm90 ~]# kubectl get cs,nodes
Unable to connect to the server: x509: certificate signed by unknown authority

以至于后面的一些操作也无法继续。

0x01 Solution

可能出现这个问题的情况都不同,但是吾这里排查到的是由于之前使用 kubuadm 的方式在本机创建过 k8s ,发现 ~/.kube/config 文件还存在,删除了此文件之后,便没有报错了

[root@k8sm90 ~]# rm -rf /root/.kube/config
[root@k8sm90 ~]# kubectl get cs,nodes
NAME AGE
componentstatus/scheduler <unknown>
componentstatus/controller-manager <unknown>
componentstatus/etcd-0 <unknown>
componentstatus/etcd-1 <unknown>
componentstatus/etcd-2 <unknown> NAME STATUS ROLES AGE VERSION
192.168.1.90 Ready master 5h43m v1.16.2
192.168.1.91 Ready node 5h30m v1.16.2
192.168.1.92 Ready node 5h29m v1.16.2