K8S异常之Unable to connect to the server: x509: certificate has expired or is not yet valid

2023-05-16

一、问题:k8s证书过期

[root@nb001 ~]# kubectl get node
Unable to connect to the server: x509: certificate has expired or is not yet valid: current time 2022-12-10T10:26:21+08:00 is after 2022-12-10T01:55:52Z

二、解决方案:

2.1 处理步骤

# 备份 kubernetes配置
cp -r /etc/kubernetes  /etc/kubernetes_bak
# 检测证书过期
kubeadm certs check-expiration
# 更新证书
kubeadm certs renew all

2.2 处理步骤详细情况

[root@nb001 ~]# kubeadm  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 -o yaml'
[check-expiration] Error reading configuration from the Cluster. Falling back to default configuration

CERTIFICATE                EXPIRES                  RESIDUAL TIME   CERTIFICATE AUTHORITY   EXTERNALLY MANAGED
admin.conf                 Dec 10, 2022 01:55 UTC   <invalid>                               no      
apiserver                  Dec 10, 2022 01:55 UTC   <invalid>       ca                      no      
apiserver-etcd-client      Dec 10, 2022 01:55 UTC   <invalid>       etcd-ca                 no      
apiserver-kubelet-client   Dec 10, 2022 01:55 UTC   <invalid>       ca                      no      
controller-manager.conf    Dec 10, 2022 01:55 UTC   <invalid>                               no      
etcd-healthcheck-client    Dec 10, 2022 01:55 UTC   <invalid>       etcd-ca                 no      
etcd-peer                  Dec 10, 2022 01:55 UTC   <invalid>       etcd-ca                 no      
etcd-server                Dec 10, 2022 01:55 UTC   <invalid>       etcd-ca                 no      
front-proxy-client         Dec 10, 2022 01:55 UTC   <invalid>       front-proxy-ca          no      
scheduler.conf             Dec 10, 2022 01:55 UTC   <invalid>                               no      

CERTIFICATE AUTHORITY   EXPIRES                  RESIDUAL TIME   EXTERNALLY MANAGED
ca                      Dec 08, 2031 01:55 UTC   8y              no      
etcd-ca                 Dec 08, 2031 01:55 UTC   8y              no      
front-proxy-ca          Dec 08, 2031 01:55 UTC   8y              no     

如上,发现很多证书都是<invalid>的状态,接着更新证书:

[root@nb001 .kube]# kubeadm certs renew all
[renew] Reading configuration from the cluster...
[renew] FYI: You can look at this config file with 'kubectl -n kube-system get cm kubeadm-config -o yaml'
[renew] Error reading configuration from the Cluster. Falling back to default configuration

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

Done renewing certificates. You must restart the kube-apiserver, kube-controller-manager, kube-scheduler and etcd, so that they can use the new certificates.
[root@nb001 .kube]# kubectl get node
Unable to connect to the server: x509: certificate has expired or is not yet valid: current time 2022-12-10T10:33:16+08:00 is after 2022-12-10T01:55:52Z

如下,更新证书后,证书过期时间已经更新为365d


[root@nb001 .kube]# kubeadm 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 -o yaml'
[check-expiration] Error reading configuration from the Cluster. Falling back to default configuration

CERTIFICATE                EXPIRES                  RESIDUAL TIME   CERTIFICATE AUTHORITY   EXTERNALLY MANAGED
admin.conf                 Dec 10, 2023 02:33 UTC   364d                                    no      
apiserver                  Dec 10, 2023 02:33 UTC   364d            ca                      no      
apiserver-etcd-client      Dec 10, 2023 02:33 UTC   364d            etcd-ca                 no      
apiserver-kubelet-client   Dec 10, 2023 02:33 UTC   364d            ca                      no      
controller-manager.conf    Dec 10, 2023 02:33 UTC   364d                                    no      
etcd-healthcheck-client    Dec 10, 2023 02:33 UTC   364d            etcd-ca                 no      
etcd-peer                  Dec 10, 2023 02:33 UTC   364d            etcd-ca                 no      
etcd-server                Dec 10, 2023 02:33 UTC   364d            etcd-ca                 no      
front-proxy-client         Dec 10, 2023 02:33 UTC   364d            front-proxy-ca          no      
scheduler.conf             Dec 10, 2023 02:33 UTC   364d                                    no      

CERTIFICATE AUTHORITY   EXPIRES                  RESIDUAL TIME   EXTERNALLY MANAGED
ca                      Dec 08, 2031 01:55 UTC   8y              no      
etcd-ca                 Dec 08, 2031 01:55 UTC   8y              no      
front-proxy-ca          Dec 08, 2031 01:55 UTC   8y              no      

三、新的问题①及解决方案

3.1 再次查看kubectl get node,发现有新的错误:error: You must be logged in to the server (Unauthorized)


[root@nb001 .kube]# kubectl get node
error: You must be logged in to the server (Unauthorized)

3.2 上述错误解决方案

  1. 备份配置文件 cp -rp $HOME/.kube/config $HOME/.kube/config.bak ,并生成新的配置文件sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
  2. 执行kubectl get node查看解决结果

详情如下:

[root@nb001 .kube]# cd /etc/kubernetes
[root@nb001 kubernetes]# ls
admin.conf  controller-manager.conf  kubelet.conf  manifests  pki  scheduler.conf
[root@nb001 kubernetes]# cd $HOME/.kube/
[root@nb001 .kube]# ls
cache  config
[root@nb001 .kube]# cp -rp config  config.bak
[root@nb001 .kube]# ls
cache  config  config.bak
[root@nb001 .kube]# sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
cp: overwrite ‘/root/.kube/config’? y
[root@nb001 .kube]# ls -lrth
total 20K
-rw------- 1 root root 5.5K Dec 10  2021 config.bak
drwxr-x--- 4 root root 4.0K Dec 10  2021 cache
-rw------- 1 root root 5.5K Dec 10 10:35 config
[root@nb001 .kube]# kubectl get node
NAME    STATUS   ROLES                  AGE    VERSION
nb001   Ready    control-plane,master   365d   v1.21.5
nb002   Ready    <none>                 365d   v1.21.5
nb003   Ready    <none>                 241d   v1.21.5

四、新的问题②及解决方案

4.1 上述问题解决后,执行kubectl apply、kubectl create命令可以正常执行,但无法实际操作资源

换句话说:就是执行了,但没生效
举例: 比如你更新 service-user.yaml 调整了镜像版本,想重新部署下user服务。执行kubectl apply -f service-user.yaml ,但实际pod还是上次部署的pod,并没有重新部署。其余不生效的情况类似。

此外:在kuboard上的表现如下图,都是空的:
在这里插入图片描述

4.2 解决方案

  1. 重启kubelet
systemctl restart kubelet
  1. 重启kube-apiserver、kube-controller-manage、kube-scheduler
# 如果是docker作为容器的话,可执行如下命令。其余容器方法类似
docker ps |grep kube-apiserver|grep -v pause|awk '{print $1}'|xargs -i docker restart {}
docker ps |grep kube-controller-manage|grep -v pause|awk '{print $1}'|xargs -i docker restart {}
docker ps |grep kube-scheduler|grep -v pause|awk '{print $1}'|xargs -i docker restart {}
  1. 重新部署user服务即可

至此,由于k8s证书过期引起的问题得到彻底解决。

End

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

K8S异常之Unable to connect to the server: x509: certificate has expired or is not yet valid 的相关文章

  • Android广播发送机制剖析【android广播系列二】

    上篇博客大致说了说广播的注册机制 xff0c 动态注册和静态注册广播的原理还不一样 xff0c 动态广播最后HashMap中了 xff0c 最后放到mReceiverResolver中 xff0c 以后当ActivityManagerSer
  • 观察者模式--Java设计模式

    观察者模式定义 xff1a 定义了对象之间的一对多的依赖 xff0c 这样一来 xff0c 当一个对象发生改变状态的时候 xff0c 它的所有依赖者都会收到通知并自动更新 参考如下图 xff1a 观察者设计模式也叫发布 订阅模式 也可以称作
  • Android——RuntimePermission介绍

    1 介绍 androidM版本上 xff0c 对permission的管理做了部分改动 xff0c 针对dangerous permission xff0c 不在安装的时候给予权限 xff0c 而是在运行过程中咨询用户是否给予app响应的权
  • Android中launcherMode="singleTask"详解【android源码解析六】

    android中launcherMode有4中属性 xff1a standard 默认 xff0c singleTop xff0c singleTask和 singleInstance xff1b 网上有好多例子讲解这四种关系的 xff1a
  • Android闹钟最终版【android源码闹钟解析】

    我以前写了个复杂闹钟的demo xff0c 参见 Android闹钟 复杂版 大明进化十五 但是里面的bug有一些 xff0c 好多人留言 xff0c 所以我就看看源码 xff0c 找找原因 xff1f 顺便把源码代码整理出来 xff0c
  • Smali--Dalvik虚拟机指令语言-->【android_smali语法学习一】

    最近一周在研究rom移植 xff0c 所以就对Smali语言学习了一下 xff0c Smali语言其实就是Davlik的寄存器语言 xff1b Smali语言就是android的应用程序 apk通过apktool反编译出来的都有一个smal
  • 程序员平均月薪过万,想当程序员的话,大学学那些专业会更好呢?

    在互联网时代 xff0c 程序员成为炙手可热的职业 虽然加班累成狗 xff0c 也有可能面临英年早秃的局面 xff0c 但是不得不说程序员的工资高于很多很多传统行业职位的工资 据统计 xff0c 应届程序员毕业生在一线城市平均月薪达到8k
  • android4.0自定义锁屏总结【android锁屏研究一】

    最近搬家了 xff0c 从北京 gt 深圳 xff0c 除了天气有点不同外 xff0c 其他的都差不多 xff0c 工作性质和以前也类似 xff01 纪念一下自己的迁移 题外话 转载请表明出处 xff1a http blog csdn ne
  • android系统锁屏详解【android锁屏解析二】

    谷歌的代码写的确实不错 xff0c 我很幸运 xff0c 一开始接触代码就赶上了谷歌这个开源的系统 xff0c 让我的视野开阔了很多 xff0c 也让我看到了优秀的代码工程师写到的代码 心怀感恩之心 题记 我的有篇文章说了这个锁屏 xff0
  • 单片机学习笔记8--按键和外部中断(基于百问网STM32F103系列教程)

    第八章 按键和外部中断 第一节 按键原理 GPIO内部上拉较弱 xff0c 可根据满足电路需求选择是用内部的上拉还是自己外接上拉 根据原理图可知 xff0c 当按键松开时 xff0c 单片机引脚连接在高电平上 xff0c GPIO口输入高电
  • ARM架构与编程6--重定位(基于百问网ARM架构与编程教程视频)

    一 启动程序流程 我们之前讲过 xff0c 单片机有根据boot的不同 xff0c 有三种启动方式 xff1a boot0boot1启动模式0Xflash启动10系统存储器11内置SRAM 单片机上电复位后 xff0c 运行main函数 以
  • LVGL8.1版本笔记

    之前学过LVGL6 xff0c 现在版本更新到LVGL8了 xff0c 学习下新版本 xff0c 本文主要是记录一些LVGL8的新特性 xff0c 区别和lvgl6的不同之处 lv task handler 的作用 链接 lv task h
  • STM32F407定时器输入捕获

    STM32F407定时器一共有14个 其中分为基本定时器 通用定时器 高级定时器 具体功能如上图所示 下面介绍下输入捕获模式 输入捕获 xff1a 通过检测TIMx CHx上的边沿信号 在边沿信号发生跳变的时候 将当前的定时器的值 TIMx
  • 几种常见的存储器

    存储器分为易失性存储器和非易失性存储器 其中的易失性是指存储器掉电是否能保存数据 易失性存储器 xff1a 就是我们常说的RAM xff0c 这种存储器掉电后所有数据都消失 xff0c 不会被保存 xff0c 重新上电之后 xff0c 原来
  • FreeRTOS初级篇----优先级实验

    FreeRTOS创建任务时 xff0c 可以设置任务的优先级 在FreeRTOS中优先级的值越小 xff0c 优先级越低 xff0c 其他的RTOS都是优先级值越小 xff0c 优先级越高 xff0c 这点需要注意 任务优先级实验 xff1
  • FreeRTOS初级篇----删除任务

    任务既然可以被创建 xff0c 那么自然也可以被删除 xff0c 对于某些执行一次或几次就不需要的任务来说 xff0c 可以在执行完成后 xff0c 把此任务删除 xff0c 可以通过别的任务将其删除 xff0c 也可以任务自己删除自己 任
  • FreeRTOS初级篇----一个函数创建多个任务

    之前说过 xff0c 创建任务的时候 xff0c 可以传递给任务参数 xff0c 下面通过实验 xff0c 对一个任务函数传入不同的参数展示如何使用一个函数创建多个任务 任务函数 xff1a 把传入的数据转换为int型数据然后打印出来 sp
  • 大学生想要通过看书自学编程,却始终没成功,是因为你没有技巧!

    在大学里面 xff0c 有很多的方式来学习编程 xff0c 从在线教程到完成在线课程 xff0c 到密集编程的新手训练营 教程都很棒 xff0c 但它们通常只给你基础知识 与此同时 xff0c 在线教程和线下课程可能非常昂贵 xff0c 虽
  • FreeRTOS初级篇----任务管理

    一 任务状态 再FreeRTOS中 xff0c CPU同一时刻只执行一个任务 xff0c 只不过是所有任务切换的速度特别快 xff0c 默认1ms切换一次任务 xff0c 所以宏观上来看就是CPU再同时运行所有任务 根据任务的执行情况 xf
  • FreeRTOS中级篇

    一 内存管理 1 五种内存管理模式 FreeRTOS提供了5种内存管理实现方法 xff0c 可以根据不同的使用场合选择不同的模式 关于5中内存管理模式可以看下面这篇文章 链接 https zhuanlan zhihu com p 11527

随机推荐