kubernetes - 证书续订后,错误 : "You must be logged in to the server (Unauthorized)"

标签 kubernetes kubectl kubeadm

我的证书已过期:

root@ubuntu:~# kubectl get pods
Unable to connect to the server: x509: certificate has expired or is not yet valid                                                                                                                                                           
我通过运行验证了它:
root@ubuntu:~# 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

W0330 09:18:49.875780   12562 configset.go:202] WARNING: kubeadm cannot validate component configs for API groups [kubelet.config.k8s.io kubepro                                                                                             xy.config.k8s.io]
CERTIFICATE                EXPIRES                  RESIDUAL TIME   CERTIFICATE AUTHORITY   EXTERNALLY MANAGED
admin.conf                 Mar 29, 2021 09:27 UTC   <invalid>                               no
apiserver                  Mar 29, 2021 09:27 UTC   <invalid>       ca                      no
apiserver-etcd-client      Mar 29, 2021 09:27 UTC   <invalid>       etcd-ca                 no
apiserver-kubelet-client   Mar 29, 2021 09:27 UTC   <invalid>       ca                      no
controller-manager.conf    Mar 29, 2021 09:27 UTC   <invalid>                               no
etcd-healthcheck-client    Mar 29, 2021 09:27 UTC   <invalid>       etcd-ca                 no
etcd-peer                  Mar 29, 2021 09:27 UTC   <invalid>       etcd-ca                 no
etcd-server                Mar 29, 2021 09:27 UTC   <invalid>       etcd-ca                 no
front-proxy-client         Mar 29, 2021 09:27 UTC   <invalid>       front-proxy-ca          no
scheduler.conf             Mar 29, 2021 09:27 UTC   <invalid>                               no

CERTIFICATE AUTHORITY   EXPIRES                  RESIDUAL TIME   EXTERNALLY MANAGED
ca                      Mar 27, 2030 09:27 UTC   8y              no
etcd-ca                 Mar 27, 2030 09:27 UTC   8y              no
front-proxy-ca          Mar 27, 2030 09:27 UTC   8y              no
我通过运行更新证书:kubeadm alpha certs renew all .
W0330 09:20:21.951839   13124 configset.go:202] WARNING: kubeadm cannot validate component configs for API groups [kubelet.config.k8s.io kubeproxy.config.k8s.io]
certificate embedded in the kubeconfig file for the admin to use and for kubeadm itself renewed
certificate for serving the Kubernetes API renewed
certificate the apiserver uses to access etcd renewed
certificate for the API server to connect to kubelet renewed
certificate embedded in the kubeconfig file for the controller manager to use renewed
certificate for liveness probes to healthcheck etcd renewed
certificate for etcd nodes to communicate with each other renewed
certificate for serving etcd renewed
certificate for the front proxy client renewed
certificate embedded in the kubeconfig file for the scheduler manager to use renewed
现在所有证书都更新到 2022 年,所以应该没问题:
CERTIFICATE                EXPIRES                  RESIDUAL TIME   CERTIFICATE AUTHORITY   EXTERNALLY MANAGED
admin.conf                 Mar 30, 2022 09:20 UTC   364d                                    no
apiserver                  Mar 30, 2022 09:20 UTC   364d            ca                      no
apiserver-etcd-client      Mar 30, 2022 09:20 UTC   364d            etcd-ca                 no
apiserver-kubelet-client   Mar 30, 2022 09:20 UTC   364d            ca                      no
controller-manager.conf    Mar 30, 2022 09:20 UTC   364d                                    no
etcd-healthcheck-client    Mar 30, 2022 09:20 UTC   364d            etcd-ca                 no
etcd-peer                  Mar 30, 2022 09:20 UTC   364d            etcd-ca                 no
etcd-server                Mar 30, 2022 09:20 UTC   364d            etcd-ca                 no
front-proxy-client         Mar 30, 2022 09:20 UTC   364d            front-proxy-ca          no
scheduler.conf             Mar 30, 2022 09:20 UTC   364d                                    no

CERTIFICATE AUTHORITY   EXPIRES                  RESIDUAL TIME   EXTERNALLY MANAGED
ca                      Mar 27, 2030 09:27 UTC   8y              no
etcd-ca                 Mar 27, 2030 09:27 UTC   8y              no
front-proxy-ca          Mar 27, 2030 09:27 UTC   8y              no
但是当我运行 kubectl get pods我收到错误:
error: You must be logged in to the server (Unauthorized)
我认为应该是证书的问题,但我不知道如何解决。我应该创建新证书并替换配置文件中的证书吗?

最佳答案

~/.kube/config未随更改更新。
我跑了:

mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config  
它修复了它。

关于kubernetes - 证书续订后,错误 : "You must be logged in to the server (Unauthorized)",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66868323/

相关文章:

kubernetes - 在Kubernetes的生产环境中部署Schema Registry

ssl - kubectl 无法连接到服务器 : x509: certificate signed by unknown authority

kubernetes - core_dns 卡在 ContainerCreating 状态

ssl - 如何检查 kubernetes token 和证书 key 是否过期?

kubernetes - 是否可以为kubeadm工具创建的集群中的Pod创建外部负载均衡器

angular - 如何为PostgreSQL支持的Spring,Angular和Django微服务编写Docker容器

kubernetes - 在 Kubernetes 节点上实现 iptables 规则

kubernetes - 如何获取 "ready"的Pod列表?

kubernetes - 创建自定义 Helm chart

kubernetes - 降级kubectl版本以匹配minikube k8s版本