Kubernetes 證書升級(jí)

使用 kubeadm 安裝 kubernetes 的證書有效期只有一年時(shí)間,所以我們需要在證書過(guò)過(guò)期之前對(duì)集群證書進(jìn)行更新,在操作之前一定要先對(duì)證書目錄進(jìn)行備份,防止操作錯(cuò)誤進(jìn)行回滾。

1. 檢查證書過(guò)期時(shí)間

首先,使用kubeadm certs check-expiration命令檢查集群中的證書過(guò)期時(shí)間。

~ # 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'

CERTIFICATE                EXPIRES                  RESIDUAL TIME   CERTIFICATE AUTHORITY   EXTERNALLY MANAGED
admin.conf                 Jul 16, 2023 09:55 UTC   90d             ca                      no      
apiserver                  Jul 16, 2023 09:54 UTC   90d             ca                      no      
apiserver-etcd-client      Jul 16, 2023 09:54 UTC   90d             etcd-ca                 no      
apiserver-kubelet-client   Jul 16, 2023 09:54 UTC   90d             ca                      no      
controller-manager.conf    Jul 16, 2023 09:55 UTC   90d             ca                      no      
etcd-healthcheck-client    Jul 16, 2023 09:53 UTC   90d             etcd-ca                 no      
etcd-peer                  Jul 16, 2023 09:53 UTC   90d             etcd-ca                 no      
etcd-server                Jul 16, 2023 09:53 UTC   90d             etcd-ca                 no      
front-proxy-client         Jul 16, 2023 09:54 UTC   90d             front-proxy-ca          no      
scheduler.conf             Jul 16, 2023 09:55 UTC   90d             ca                      no      

CERTIFICATE AUTHORITY   EXPIRES                  RESIDUAL TIME   EXTERNALLY MANAGED
ca                      Dec 28, 2030 09:14 UTC   7y              no      
etcd-ca                 Dec 28, 2030 09:14 UTC   7y              no      
front-proxy-ca          Dec 28, 2030 09:14 UTC   7y              no   

有些低版本的使用的是kubeadm alpha certs check-expiratio

2. 備份舊證書和配置文件等

在升級(jí)證書之前,需要備份舊證書和密鑰以免更新證書的時(shí)候出錯(cuò),kubeadm生成的證書一般在/etc/kubernetes/pki

# 創(chuàng)建備份目錄
/home # mkdir /etc/kubernetes.bak
# 備份舊證書
/home # cp -r /etc/kubernetes/pki/ /etc/kubernetes.bak
# 備份配置文件
/home # cp /etc/kubernetes/*.conf /etc/kubernetes.bak
# 備份etcd數(shù)據(jù)
/home # cp -r /var/lib/etcd /var/lib/etcd.bak                                                                                                              
/home # cp -r /var/lib/etcd /var/lib/etcd.bak                                                                                                     

3. 執(zhí)行證書升級(jí)命令

/home # 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'

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.

再次檢查證書過(guò)期時(shí)間

/home # 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'

CERTIFICATE                EXPIRES                  RESIDUAL TIME   CERTIFICATE AUTHORITY   EXTERNALLY MANAGED
admin.conf                 Apr 16, 2024 08:14 UTC   364d            ca                      no      
apiserver                  Apr 16, 2024 08:14 UTC   364d            ca                      no      
apiserver-etcd-client      Apr 16, 2024 08:14 UTC   364d            etcd-ca                 no      
apiserver-kubelet-client   Apr 16, 2024 08:14 UTC   364d            ca                      no      
controller-manager.conf    Apr 16, 2024 08:14 UTC   364d            ca                      no      
etcd-healthcheck-client    Apr 16, 2024 08:14 UTC   364d            etcd-ca                 no      
etcd-peer                  Apr 16, 2024 08:14 UTC   364d            etcd-ca                 no      
etcd-server                Apr 16, 2024 08:14 UTC   364d            etcd-ca                 no      
front-proxy-client         Apr 16, 2024 08:14 UTC   364d            front-proxy-ca          no      
scheduler.conf             Apr 16, 2024 08:14 UTC   364d            ca                      no      

CERTIFICATE AUTHORITY   EXPIRES                  RESIDUAL TIME   EXTERNALLY MANAGED
ca                      Dec 28, 2030 09:14 UTC   7y              no      
etcd-ca                 Dec 28, 2030 09:14 UTC   7y              no      
front-proxy-ca          Dec 28, 2030 09:14 UTC   7y              no      

證書過(guò)期時(shí)間已更新

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • kubernetes的所用到的證書都是放在/etc/kubernetes/pki/目錄下,其中包括etcd,kub...
    hgjsj閱讀 444評(píng)論 0 0
  • 目錄:1、證書過(guò)期時(shí)間查詢2、證書過(guò)期處理2.1、客戶端kubelet證書自動(dòng)續(xù)期2.2、重新生成默認(rèn)一年時(shí)長(zhǎng)證書...
    Feel_狗煥閱讀 13,775評(píng)論 0 4
  • 問(wèn)題及修復(fù) 手里有個(gè)實(shí)驗(yàn)環(huán)境部署了一年多,最近重新啟用想做一些測(cè)試驗(yàn)證,信心滿滿的準(zhǔn)備先跑下kubectl get...
    shadowlan閱讀 687評(píng)論 0 0
  • 一、集群使用證書[https://kubernetes.io/zh-cn/docs/setup/best-prac...
    宏勢(shì)閱讀 790評(píng)論 0 5
  • Kubernetes集群證書的使用壽命為一年。如果Kubernetes集群證書在Kubernetes master...
    lyyao09閱讀 1,363評(píng)論 0 0

友情鏈接更多精彩內(nèi)容