0
  • 聊天消息
  • 系統(tǒng)消息
  • 評(píng)論與回復(fù)
登錄后你可以
  • 下載海量資料
  • 學(xué)習(xí)在線課程
  • 觀看技術(shù)視頻
  • 寫文章/發(fā)帖/加入社區(qū)
會(huì)員中心
創(chuàng)作中心

完善資料讓更多小伙伴認(rèn)識(shí)你,還能領(lǐng)取20積分哦,立即完善>

3天內(nèi)不再提示

自建K8S集群認(rèn)證過期

馬哥Linux運(yùn)維 ? 來源:博客園 ? 2025-02-07 12:32 ? 次閱讀
加入交流群
微信小助手二維碼

掃碼添加小助手

加入工程師交流群

今天使用kubectl命令查看pod信息時(shí),一直正常運(yùn)行的k8s集群突然不能訪問了,輸入任何命令都提示以下報(bào)錯(cuò):
Unable to connect to the server: x509: certificate has expired or is not yet valid: current time 2025-01-25T1145+08:00 is after 2024-11-22T2348Z

解決方案:

參考官方文檔:kubeadm證書管理使用命令kubeadm alpha certs來管理證書:

使用命令kubeadm alpha 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 -oyaml'
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

使用如下命令拷貝新生成的配置文件


sudo kubeadm alpha kubeconfig user --client-name=admin --org=system:masters > /tmp/admin.conf
sudo cp /tmp/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config

重啟kubeletsystemctl restart kubelet即可正常使用K8S集群


[root@k8smaster k8s]# kubectl get po
NAME READY STATUS RESTARTS AGE
cron-job-test-1732318920-k2g76 0/1 Completed 0 63d
cron-job-test-1732318980-kcr4x 0/1 Completed 0 63d
cron-job-test-1732319040-b88rf 0/1 Completed 0 63d

再次查看證書到期情況


[root@k8smaster k8s]# 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'
CERTIFICATE EXPIRES RESIDUAL TIME CERTIFICATE AUTHORITY EXTERNALLY MANAGED
admin.conf Jan 25, 2026 05:55 UTC 364d no
apiserver Jan 25, 2026 05:55 UTC 364d ca no
apiserver-etcd-client Jan 25, 2026 05:55 UTC 364d etcd-ca no
apiserver-kubelet-client Jan 25, 2026 05:55 UTC 364d ca no
controller-manager.conf Jan 25, 2026 05:55 UTC 364d no
etcd-healthcheck-client Jan 25, 2026 05:55 UTC 364d etcd-ca no
etcd-peer Jan 25, 2026 05:55 UTC 364d etcd-ca no
etcd-server Jan 25, 2026 05:55 UTC 364d etcd-ca no
front-proxy-client Jan 25, 2026 05:55 UTC 364d front-proxy-ca no
scheduler.conf Jan 25, 2026 05:55 UTC 364d no
CERTIFICATE AUTHORITY EXPIRES RESIDUAL TIME EXTERNALLY MANAGED
ca Nov 20, 2033 23:44 UTC 8y no
etcd-ca Nov 20, 2033 23:44 UTC 8y no
front-proxy-ca Nov 20, 2033 23:44 UTC 8y no

注意事項(xiàng):

官網(wǎng)上給的命令是kubeadm certs check-expiration,標(biāo)識(shí)的k8s版本是V1.15,直接在本地執(zhí)行該命令報(bào)錯(cuò):


[root@k8smaster k8s]# kubeadm certs check-expiration
unknown command "certs" for "kubeadm"
To see the stack trace of this error execute with --v=5 or higher

查了下,我本地的k8s版本是1.19,certs命令放在了kubeadm alpha下,需要將kubeadm certs替換為kubeadm aplha certs執(zhí)行即可


[root@k8smaster k8sh]# kubeadm version
kubeadm version: &version.Info{Major:"1", Minor:"19", GitVersion:"v1.19.5", GitCommit:"e338cf2c6d297aa603b50ad3a301f761b4173aa6", GitTreeState:"clean", BuildDate:"2020-12-09T1140Z", GoVersion:"go1.15.2", Compiler:"gc", Platform:"linux/amd64"}


[root@k8smaster k8s]# kubeadm --help
┌──────────────────────────────────────────────────────────┐
│ KUBEADM │
│ Easily bootstrap a secure Kubernetes cluster │
│ │
│ Please give us feedback at: │
│ https://github.com/kubernetes/kubeadm/issues │
└──────────────────────────────────────────────────────────┘
Example usage:
Create a two-machine cluster with one control-plane node
(which controls the cluster), and one worker node
(where your workloads, like Pods and Deployments run).
┌──────────────────────────────────────────────────────────┐
│ On the first machine: │
├──────────────────────────────────────────────────────────┤
│ control-plane# kubeadm init │
└──────────────────────────────────────────────────────────┘
┌──────────────────────────────────────────────────────────┐
│ On the second machine: │
├──────────────────────────────────────────────────────────┤
│ worker# kubeadm join
└──────────────────────────────────────────────────────────┘
You can then repeat the second step on as many other machines as you like.
Usage:
kubeadm [command]
Available Commands:
alpha Kubeadm experimental sub-commands
completion Output shell completion code for the specified shell (bash or zsh)
config Manage configuration for a kubeadm cluster persisted in a ConfigMap in the cluster
help Help about any command
init Run this command in order to set up the Kubernetes control plane
join Run this on any machine you wish to join an existing cluster
reset Performs a best effort revert of changes made to this host by 'kubeadm init ' or 'kubeadm join'
token Manage bootstrap tokens
upgrade Upgrade your cluster smoothly to a newer version with this command
version Print the version of kubeadm
Flags:
--add-dir-header If true, adds the file directory to the header of the lo g messages
-h, --help help for kubeadm
--log-file string If non-empty, use this log file
--log-file-max-size uint Defines the maximum size a log file can grow to. Unit is megabytes. If the value is 0, the maximum file size is unlimited. (default 1800)
--rootfs string [EXPERIMENTAL] The path to the 'real' host root filesyst em.
--skip-headers If true, avoid header prefixes in the log messages
--skip-log-headers If true, avoid headers when opening log files
-v, --v Level number for the log level verbosity
Use "kubeadm [command] --help" for more information about a command.
[root@k8smaster k8s]# kubectl alpha --help
These commands correspond to alpha features that are not enabled in Kubernetes
clusters by default.
Available Commands:
debug Attach a debug container to a running pod
Use "kubectl --help" for more information about a given command.
[root@k8smaster k8s]# kubeadm alpha --help
Kubeadm experimental sub-commands
Usage:
kubeadm alpha [command]
Available Commands:
certs Commands related to handling kubernetes certificates
kubeconfig Kubeconfig file utilities
selfhosting Make a kubeadm cluster self-hosted
Flags:
-h, --help help for alpha
Global Flags:
--add-dir-header If true, adds the file directory to the header of the log messages
--log-file string If non-empty, use this log file
--log-file-max-size uint Defines the maximum size a log file can grow to. Unit is megabytes. If the value is 0, the maximum file size is unlimited. (default 1800)
--rootfs string [EXPERIMENTAL] The path to the 'real' host root filesystem.
--skip-headers If true, avoid header prefixes in the log messages
--skip-log-headers If true, avoid headers when opening log files
-v, --v Level number for the log level verbosity
Additional help topics:
kubeadm alpha phase Invoke subsets of kubeadm functions separately for a manual install
Use "kubeadm alpha [command] --help" for more information about a command.

鏈接:https://www.cnblogs.com/wenha/p/18690938

聲明:本文內(nèi)容及配圖由入駐作者撰寫或者入駐合作網(wǎng)站授權(quán)轉(zhuǎn)載。文章觀點(diǎn)僅代表作者本人,不代表電子發(fā)燒友網(wǎng)立場(chǎng)。文章及其配圖僅供工程師學(xué)習(xí)之用,如有內(nèi)容侵權(quán)或者其他違規(guī)問題,請(qǐng)聯(lián)系本站處理。 舉報(bào)投訴
  • 集群
    +關(guān)注

    關(guān)注

    0

    文章

    102

    瀏覽量

    17401
  • 命令
    +關(guān)注

    關(guān)注

    5

    文章

    736

    瀏覽量

    22794

原文標(biāo)題:自建K8S集群認(rèn)證過期

文章出處:【微信號(hào):magedu-Linux,微信公眾號(hào):馬哥Linux運(yùn)維】歡迎添加關(guān)注!文章轉(zhuǎn)載請(qǐng)注明出處。

收藏 人收藏
加入交流群
微信小助手二維碼

掃碼添加小助手

加入工程師交流群

    評(píng)論

    相關(guān)推薦
    熱點(diǎn)推薦

    什么是 K8S,如何使用 K8S

    連續(xù)性。 適用場(chǎng)景: 大規(guī)模容器集群管理。 微服務(wù)架構(gòu)的部署與運(yùn)維。 需要彈性伸縮的在線服務(wù)。 多租戶環(huán)境(如開發(fā)測(cè)試、生產(chǎn)環(huán)境隔離)。 總的來說,K8S 通過標(biāo)準(zhǔn)化容器管理,極大降低了分布式系統(tǒng)的運(yùn)維復(fù)雜度,是云原生時(shí)代的核心基礎(chǔ)設(shè)施。
    發(fā)表于 06-25 06:45

    K8s 從懵圈到熟練 – 集群網(wǎng)絡(luò)詳解

    導(dǎo)讀:阿里云 K8S 集群網(wǎng)絡(luò)目前有兩種方案:一種是 flannel 方案;另外一種是基于 calico 和彈性網(wǎng)卡 eni 的 terway 方案。Terway 和 flannel 類似
    發(fā)表于 10-14 15:06

    搭建K8s環(huán)境平臺(tái)的步驟

    1 搭建K8s環(huán)境平臺(tái)規(guī)劃1.1 單master集群1.2 多master集群
    發(fā)表于 11-04 06:03

    Docker不香嗎為什么還要用K8s

    Docker 雖好用,但面對(duì)強(qiáng)大的集群,成千上萬(wàn)的容器,突然感覺不香了。 這時(shí)候就需要我們的主角 Kubernetes 上場(chǎng)了,先來了解一下 K8s 的基本概念,后面再介紹實(shí)踐,由淺入深步步為營(yíng)
    的頭像 發(fā)表于 06-02 11:56 ?3667次閱讀

    簡(jiǎn)單說明k8s和Docker之間的關(guān)系

    這篇文章主要介紹了k8s和Docker關(guān)系簡(jiǎn)單說明,本文利用圖文講解的很透徹,有需要的同學(xué)可以研究下 最近項(xiàng)目用到kubernetes(以下簡(jiǎn)稱k8s,ks之間有
    的頭像 發(fā)表于 06-24 15:48 ?3694次閱讀

    K8S集群服務(wù)訪問失敗怎么辦 K8S故障處理集錦

    問題1:K8S集群服務(wù)訪問失?。?? ? 原因分析:證書不能被識(shí)別,其原因?yàn)椋鹤远x證書,過期等。 解決方法:更新證書即可。 問題2:K8S集群
    的頭像 發(fā)表于 09-01 11:11 ?1.6w次閱讀
    <b class='flag-5'>K8S</b><b class='flag-5'>集群</b>服務(wù)訪問失敗怎么辦 <b class='flag-5'>K8S</b>故障處理集錦

    3個(gè)管理多k8s集群實(shí)用工具

    命令就會(huì)很低效。 今天介紹3個(gè)工具會(huì)讓你在多k8s集群環(huán)境中工作的很輕松。我將從以下幾個(gè)方面來評(píng)估工具實(shí)用性。
    的頭像 發(fā)表于 04-26 10:33 ?1447次閱讀
    3個(gè)管理多<b class='flag-5'>k8s</b><b class='flag-5'>集群</b>實(shí)用工具

    k8s集群環(huán)境中工作有多快

    命令就會(huì)很低效。 今天介紹3個(gè)工具會(huì)讓你在多k8s集群環(huán)境中工作的很輕松。我將從以下幾個(gè)方面來評(píng)估工具實(shí)用性: 速度 如果你有多個(gè)k8s集群可選擇,你切換
    的頭像 發(fā)表于 05-29 14:28 ?763次閱讀
    多<b class='flag-5'>k8s</b><b class='flag-5'>集群</b>環(huán)境中工作有多快

    切換k8s上下文有多快

    use-context 命令就會(huì)很低效。 今天介紹3個(gè)工具會(huì)讓你在多k8s集群環(huán)境中工作的很輕松。我將從以下幾個(gè)方面來評(píng)估工具實(shí)用性: 速度 如果你有多個(gè)k8s集群可選擇,你切換
    的頭像 發(fā)表于 05-29 15:26 ?962次閱讀
    切換<b class='flag-5'>k8s</b>上下文有多快

    k8s是什么意思?kubeadm部署k8s集群k8s部署)|PetaExpres

    k8s是什么意思? kubernetes簡(jiǎn)稱K8s,是一個(gè)開源的,用于管理云平臺(tái)中多個(gè)主機(jī)上的容器化的應(yīng)用,Kubernetes的目標(biāo)是讓部署容器化的應(yīng)用簡(jiǎn)單并且高效(powerful
    發(fā)表于 07-19 13:14 ?1307次閱讀

    K8s集群管理:為什么需要多集群、多集群的優(yōu)勢(shì)是什么

    隨著K8s和云原生技術(shù)的快速發(fā)展,以及各大廠商在自己的數(shù)據(jù)中心使用K8s的API進(jìn)行容器化應(yīng)用編排和管理,讓應(yīng)用交付本身變得越來越標(biāo)準(zhǔn)化和統(tǒng)一化,并且實(shí)現(xiàn)了與底層基礎(chǔ)設(shè)施的完全解耦,為多集群和混合云提供了一個(gè)堅(jiān)實(shí)技術(shù)基礎(chǔ)。
    發(fā)表于 09-14 10:48 ?2029次閱讀
    <b class='flag-5'>K8s</b>多<b class='flag-5'>集群</b>管理:為什么需要多<b class='flag-5'>集群</b>、多<b class='flag-5'>集群</b>的優(yōu)勢(shì)是什么

    納尼?自建K8s集群日志收集還能通過JMQ保存到JES

    作者:京東科技 劉恩浩 一、背景 基于K8s集群的私有化交付方案中,日志收集采用了ilogtail+logstash+kafka+es方案,其中ilogtail負(fù)責(zé)日志收集,logstash負(fù)責(zé)對(duì)數(shù)
    的頭像 發(fā)表于 09-30 14:45 ?418次閱讀

    k8s云原生開發(fā)要求

    IO性能。網(wǎng)絡(luò)要求穩(wěn)定,建議使用私有網(wǎng)絡(luò)VPC,并配置與Kubernetes兼容的網(wǎng)絡(luò)插件。操作系統(tǒng)需與K8s版本匹配,虛擬化平臺(tái)支持Docker等。此外,還需關(guān)注安全配置,如禁用Swap、調(diào)整Sysctl等,以及etcd數(shù)據(jù)存儲(chǔ)后端的配置。合理配置硬件可確保K8s
    的頭像 發(fā)表于 10-24 10:03 ?555次閱讀
    <b class='flag-5'>k8s</b>云原生開發(fā)要求

    混合云部署k8s集群方法有哪些?

    混合云部署k8s集群方法是首先需在本地與公有云分別建立K8s集群,并確保網(wǎng)絡(luò)連接。接著,配置kubeconfig文件連接兩集群,并安裝云服務(wù)
    的頭像 發(fā)表于 11-07 09:37 ?474次閱讀

    如何通過Docker和K8S集群實(shí)現(xiàn)高效調(diào)用GPU

    在有GPU資源的主機(jī)安裝,改主機(jī)作為K8S集群的Node。
    的頭像 發(fā)表于 03-18 16:50 ?423次閱讀
    如何通過Docker和<b class='flag-5'>K8S</b><b class='flag-5'>集群</b>實(shí)現(xiàn)高效調(diào)用GPU

    電子發(fā)燒友

    中國(guó)電子工程師最喜歡的網(wǎng)站

    • 2931785位工程師會(huì)員交流學(xué)習(xí)
    • 獲取您個(gè)性化的科技前沿技術(shù)信息
    • 參加活動(dòng)獲取豐厚的禮品