k8s1.20.6用kubeadm安裝的3master+3node證書續(xù)期

失敗翻車記錄

一曲稼、查看k8s中所有證書的到期時(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                 Oct 03, 2022 07:37 UTC   4d                                      no      
apiserver                  Oct 03, 2022 07:37 UTC   4d              ca                      no      
apiserver-etcd-client      Oct 03, 2022 07:37 UTC   4d              etcd-ca                 no      
apiserver-kubelet-client   Oct 03, 2022 07:37 UTC   4d              ca                      no      
controller-manager.conf    Oct 03, 2022 07:37 UTC   4d                                      no      
etcd-healthcheck-client    Oct 03, 2022 07:37 UTC   4d              etcd-ca                 no      
etcd-peer                  Oct 03, 2022 07:37 UTC   4d              etcd-ca                 no      
etcd-server                Oct 03, 2022 07:37 UTC   4d              etcd-ca                 no      
front-proxy-client         Oct 03, 2022 07:37 UTC   4d              front-proxy-ca          no      
scheduler.conf             Oct 03, 2022 07:37 UTC   4d                                      no      

CERTIFICATE AUTHORITY   EXPIRES                  RESIDUAL TIME   EXTERNALLY MANAGED
ca                      Oct 01, 2031 07:37 UTC   9y              no      
etcd-ca                 Oct 01, 2031 07:37 UTC   9y              no      
front-proxy-ca          Oct 01, 2031 07:37 UTC   9y              no

查看基礎(chǔ)配置

#  kubectl get node -o wide
NAME      STATUS   ROLES                  AGE    VERSION   INTERNAL-IP       EXTERNAL-IP   OS-IMAGE                KERNEL-VERSION                CONTAINER-RUNTIME
master1   Ready    control-plane,master   361d   v1.20.6   192.168.100.171   <none>        CentOS Linux 7 (Core)   3.10.0-1160.42.2.el7.x86_64   docker://20.10.6
master2   Ready    control-plane,master   361d   v1.20.6   192.168.100.172   <none>        CentOS Linux 7 (Core)   3.10.0-514.el7.x86_64         docker://20.10.6
master3   Ready    control-plane,master   361d   v1.20.6   192.168.100.173   <none>        CentOS Linux 7 (Core)   3.10.0-514.el7.x86_64         docker://20.10.6
node01    Ready    <none>                 361d   v1.20.6   192.168.100.174   <none>        CentOS Linux 7 (Core)   3.10.0-514.el7.x86_64         docker://20.10.6
node02    Ready    <none>                 361d   v1.20.6   192.168.100.175   <none>        CentOS Linux 7 (Core)   3.10.0-514.el7.x86_64         docker://20.10.6
node03    Ready    <none>                 361d   v1.20.6   192.168.100.176   <none>        CentOS Linux 7 (Core)   3.10.0-514.el7.x86_64         docker://20.10.6

二醒陆、查看CA證書過期時(shí)間:

# openssl x509 -in /etc/kubernetes/pki/ca.crt -noout -text |grep Not
            Not Before: Oct  3 07:37:14 2021 GMT
            Not After : Oct  1 07:37:14 2031 GMT

查看集群證書過期時(shí)間:

# openssl x509 -in /etc/kubernetes/pki/apiserver.crt -noout -text |grep ' Not '
            Not Before: Oct  3 07:37:14 2021 GMT
            Not After : Oct  3 07:37:15 2022 GMT

如果集群證書還沒有過期
獲取一個(gè)創(chuàng)建好的 k8s集群的初始化配置文件
kubeadm config view > kubeadm.yaml

三翠拣、備份證書和配置文件

備份證書

[root@master1 ~]# mkdir 0929
[root@master1 ~]# cd 0929
[root@master1 0929]# ll /etc/kubernetes/
總用量 32
-rw------- 1 root root 5568 10月  3 2021 admin.conf
-rw------- 1 root root 5603 10月  3 2021 controller-manager.conf
-rw------- 1 root root 1924 10月  3 2021 kubelet.conf
drwxr-xr-x 2 root root  113 1月  10 2022 manifests
drwxr-xr-x 3 root root 4096 10月  3 2021 pki
-rw------- 1 root root 5555 10月  3 2021 scheduler.conf
[root@master1 0929]#  cp -rp /etc/kubernetes  ./
[root@master1 0929]# ll
總用量 0
drwxr-xr-x 4 root root 125 1月   8 2022 kubernetes
[root@master1 0929]# ll kubernetes/
總用量 32
-rw------- 1 root root 5568 10月  3 2021 admin.conf
-rw------- 1 root root 5603 10月  3 2021 controller-manager.conf
-rw------- 1 root root 1924 10月  3 2021 kubelet.conf
drwxr-xr-x 2 root root  113 1月  10 2022 manifests
drwxr-xr-x 3 root root 4096 10月  3 2021 pki
-rw------- 1 root root 5555 10月  3 2021 scheduler.conf

備份靜態(tài)pod配置文件

[root@master1 0929]# ll /etc/kubernetes/manifests/
總用量 16
-rw------- 1 root root 2226 10月  3 2021 etcd.yaml
-rw------- 1 root root 3379 1月  10 2022 kube-apiserver.yaml
-rw------- 1 root root 2827 10月  6 2021 kube-controller-manager.yaml
-rw------- 1 root root 1413 10月  6 2021 kube-scheduler.yaml
[root@master1 0929]# cp -r /etc/kubernetes/manifests ./
[root@master1 0929]# ll
總用量 0
drwxr-xr-x 4 root root 125 1月   8 2022 kubernetes
drwxr-xr-x 2 root root 113 9月  29 11:02 manifests
[root@master1 0929]# ll manifests/
總用量 16
-rw------- 1 root root 2226 9月  29 11:02 etcd.yaml
-rw------- 1 root root 3379 9月  29 11:02 kube-apiserver.yaml
-rw------- 1 root root 2827 9月  29 11:02 kube-controller-manager.yaml
-rw------- 1 root root 1413 9月  29 11:02 kube-scheduler.yaml

備份etcd

[root@master1 0929]# mkdir -p /data/etcd_backup_dir
[root@master1 0929]#   ll /data/etcd_backup_dir/
總用量 10060
-rwxr-xr-x 1 root root     351 1月  16 2022 etcd_backup.sh
-rw------- 1 root root 5144608 1月  16 2022 etcd-snapshot-20220116.db
-rw------- 1 root root 5144608 1月  16 2022 snap-202201161455.db

[root@master1 0929]# ETCDCTL_API=3 etcdctl --endpoints 127.0.0.1:2379  --cert="/etc/kubernetes/pki/etcd/server.crt"  --key="/etc/kubernetes/pki/etcd/server.key"  --cacert="/etc/kubernetes/pki/etcd/ca.crt"   snapshot save /data/etcd_backup_dir/snap-$(date +%Y%m%d%H%M).db
{"level":"info","ts":1664420716.5343292,"caller":"snapshot/v3_snapshot.go:119","msg":"created temporary db file","path":"/data/etcd_backup_dir/snap-202209291105.db.part"}
{"level":"info","ts":"2022-09-29T11:05:16.555+0800","caller":"clientv3/maintenance.go:200","msg":"opened snapshot stream; downloading"}
{"level":"info","ts":1664420716.555565,"caller":"snapshot/v3_snapshot.go:127","msg":"fetching snapshot","endpoint":"127.0.0.1:2379"}
{"level":"info","ts":"2022-09-29T11:05:17.360+0800","caller":"clientv3/maintenance.go:208","msg":"completed snapshot read; closing"}
{"level":"info","ts":1664420717.4313715,"caller":"snapshot/v3_snapshot.go:142","msg":"fetched snapshot","endpoint":"127.0.0.1:2379","size":"5.3 MB","took":0.896710978}
{"level":"info","ts":1664420717.431757,"caller":"snapshot/v3_snapshot.go:152","msg":"saved","path":"/data/etcd_backup_dir/snap-202209291105.db"}
Snapshot saved at /data/etcd_backup_dir/snap-202209291105.db
[root@master1 0929]# ll /data/etcd_backup_dir/
總用量 15248
-rwxr-xr-x 1 root root     351 1月  16 2022 etcd_backup.sh
-rw------- 1 root root 5144608 1月  16 2022 etcd-snapshot-20220116.db
-rw------- 1 root root 5144608 1月  16 2022 snap-202201161455.db
-rw------- 1 root root 5308448 9月  29 11:05 snap-202209291105.db

物理備份

[root@master1 ~]# ll /var/lib/etcd
總用量 0
drwx------ 4 root root 29 9月  29 09:38 member
[root@master1 ~]# ll /var/lib/etcd/member/
總用量 0
drwx------ 2 root root 246 9月  29 10:36 snap
drwx------ 2 root root 244 9月  29 09:38 wal
[root@master1 ~]# mkdir -p /data/etcd_data_back
[root@master1 ~]# cp -r /var/lib/etcd /data/etcd_data_back/etcd.bak
[root@master1 ~]# ll /data/etcd_data_back/
總用量 0
drwx------ 3 root root 20 9月  29 11:13 etcd.bak
[root@master1 ~]# ll /data/etcd_data_back/etcd.bak/
總用量 0
drwx------ 4 root root 29 9月  29 11:13 member
[root@master1 ~]# ll /data/etcd_data_back/etcd.bak/member/
總用量 0
drwx------ 2 root root 246 9月  29 11:13 snap
drwx------ 2 root root 244 9月  29 11:13 wal

四按摘、更新證書

# 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.

# 由輸出內(nèi)容可知朗徊,更新的內(nèi)容為:
Kubernetes API的證書快骗;
apiserver的證書娜庇,用來訪問etcd;
API server的證書方篮,用來連接kubelet名秀;
嵌入在kubeconfig文件中,用于controller manager的使用藕溅;
liveness probes的證書匕得,用來對(duì)etcd作health check;
etcd節(jié)點(diǎn)的證書,用來互相訪問汁掠;
前端代理服務(wù)的證書略吨;
嵌入在kubeconfig文件中,用于scheduler manager的使用考阱。

把舊版的證書轉(zhuǎn)移到別的路徑翠忠, 暫時(shí)清空 /etc/kubernetes/manifests/

[root@master1 ~]#  cd /etc/kubernetes/manifests/
[root@master1 manifests]# mkdir -p /data/manifests
[root@master1 manifests]# mv ./* /data/manifests/
[root@master1 manifests]# ll /data/manifests/
總用量 16
-rw------- 1 root root 2226 9月  29 11:43 etcd.yaml
-rw------- 1 root root 3379 9月  29 11:43 kube-apiserver.yaml
-rw------- 1 root root 2827 9月  29 11:43 kube-controller-manager.yaml
-rw------- 1 root root 1413 9月  29 11:43 kube-scheduler.yaml

等待1分鐘 期間測(cè)試下

[root@master1 manifests]# kubectl get po -A
The connection to the server 10.170.13.8:6443 was refused - did you specify the right host or port?

連接不上也正常

恢復(fù)一下/etc/kubernetes/manifests yaml文件

[root@master1 manifests]# pwd
/etc/kubernetes/manifests
[root@master1 manifests]# cp -rp /data/manifests/*   ./
[root@master1 manifests]# ll
總用量 16
-rw------- 1 root root 2226 10月  3 2021 etcd.yaml
-rw------- 1 root root 3379 1月  10 2022 kube-apiserver.yaml
-rw------- 1 root root 2827 10月  6 2021 kube-controller-manager.yaml
-rw------- 1 root root 1413 10月  6 2021 kube-scheduler.yaml

查看下 pod的情況

[root@master1 manifests]# kubectl get po -A

[root@master1 manifests]# kubectl get no

五、 查看新的證書過期時(shí)間

# kubeadm  certs check-expiration

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末乞榨,一起剝皮案震驚了整個(gè)濱河市秽之,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌吃既,老刑警劉巖考榨,帶你破解...
    沈念sama閱讀 211,743評(píng)論 6 492
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場(chǎng)離奇詭異鹦倚,居然都是意外死亡河质,警方通過查閱死者的電腦和手機(jī),發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 90,296評(píng)論 3 385
  • 文/潘曉璐 我一進(jìn)店門申鱼,熙熙樓的掌柜王于貴愁眉苦臉地迎上來愤诱,“玉大人云头,你說我怎么就攤上這事捐友。” “怎么了溃槐?”我有些...
    開封第一講書人閱讀 157,285評(píng)論 0 348
  • 文/不壞的土叔 我叫張陵匣砖,是天一觀的道長(zhǎng)。 經(jīng)常有香客問我昏滴,道長(zhǎng)猴鲫,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 56,485評(píng)論 1 283
  • 正文 為了忘掉前任谣殊,我火速辦了婚禮拂共,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘姻几。我一直安慰自己宜狐,他們只是感情好,可當(dāng)我...
    茶點(diǎn)故事閱讀 65,581評(píng)論 6 386
  • 文/花漫 我一把揭開白布蛇捌。 她就那樣靜靜地躺著抚恒,像睡著了一般。 火紅的嫁衣襯著肌膚如雪络拌。 梳的紋絲不亂的頭發(fā)上俭驮,一...
    開封第一講書人閱讀 49,821評(píng)論 1 290
  • 那天,我揣著相機(jī)與錄音春贸,去河邊找鬼混萝。 笑死遗遵,一個(gè)胖子當(dāng)著我的面吹牛,可吹牛的內(nèi)容都是我干的譬圣。 我是一名探鬼主播瓮恭,決...
    沈念sama閱讀 38,960評(píng)論 3 408
  • 文/蒼蘭香墨 我猛地睜開眼,長(zhǎng)吁一口氣:“原來是場(chǎng)噩夢(mèng)啊……” “哼厘熟!你這毒婦竟也來了屯蹦?” 一聲冷哼從身側(cè)響起,我...
    開封第一講書人閱讀 37,719評(píng)論 0 266
  • 序言:老撾萬榮一對(duì)情侶失蹤绳姨,失蹤者是張志新(化名)和其女友劉穎登澜,沒想到半個(gè)月后,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體飘庄,經(jīng)...
    沈念sama閱讀 44,186評(píng)論 1 303
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡脑蠕,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 36,516評(píng)論 2 327
  • 正文 我和宋清朗相戀三年,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了跪削。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片谴仙。...
    茶點(diǎn)故事閱讀 38,650評(píng)論 1 340
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡,死狀恐怖碾盐,靈堂內(nèi)的尸體忽然破棺而出晃跺,到底是詐尸還是另有隱情,我是刑警寧澤毫玖,帶...
    沈念sama閱讀 34,329評(píng)論 4 330
  • 正文 年R本政府宣布掀虎,位于F島的核電站,受9級(jí)特大地震影響付枫,放射性物質(zhì)發(fā)生泄漏烹玉。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 39,936評(píng)論 3 313
  • 文/蒙蒙 一阐滩、第九天 我趴在偏房一處隱蔽的房頂上張望二打。 院中可真熱鬧,春花似錦掂榔、人聲如沸继效。這莊子的主人今日做“春日...
    開封第一講書人閱讀 30,757評(píng)論 0 21
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽莲趣。三九已至,卻和暖如春饱溢,著一層夾襖步出監(jiān)牢的瞬間喧伞,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 31,991評(píng)論 1 266
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留潘鲫,地道東北人翁逞。 一個(gè)月前我還...
    沈念sama閱讀 46,370評(píng)論 2 360
  • 正文 我出身青樓,卻偏偏與公主長(zhǎng)得像溉仑,于是被迫代替她去往敵國和親挖函。 傳聞我的和親對(duì)象是個(gè)殘疾皇子,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 43,527評(píng)論 2 349

推薦閱讀更多精彩內(nèi)容