kubelet證書過時解決方法

昨天收到報警短信:集羣中某node狀態爲notReady,因爲是長期不用的,因此放到今天才有空處理,如下記錄處理過程。node

查看kubelet日誌,發現不停的打印證書過時相關提示信息。linux

如下操做基於kubernetes集羣版本:v1.6.6bootstrap

kubelete 證書默認有效期一年api

1.查看證書有效期,這裏使用之前下載的cfssl-certinfoapp

curl -s -L -o /usr/local/bin/cfssl-certinfo https://pkg.cfssl.org/R1.2/cfssl-certinfo_linux-amd64
chmod +x /usr/local/bin/cfssl-certinfo
cfssl-certinfo -cert /etc/kubernetes/ssl/kubelet.crt
  顯示內容以下:curl

{
"subject": {
"common_name": "test@1505813004",
"names": [
"test@1505813004"
]
},
"issuer": {
"common_name": "test@1505813004",
"names": [
"test@1505813004"
]
},
"serial_number": "1",
"sans": [
"test"
],
"not_before": "2017-10-24T09:23:24Z",
"not_after": "2018-10-24T09:23:24Z",
"sigalg": "SHA256WithRSA",
"authority_key_id": "",
"subject_key_id": "",
"pem": "-----BEGIN CERTIFICATE-----\nMIIDDKDK........EHi\nThGfI/wURC0=\n-----END CERTIFICATE-----\n"
}url

  1. 從新生成證書

在證書過時node刪除kubelet相關證書文件及配置文件而後重啓kubelet,
kubelet會向apiserver發起一個csr
rm /etc/kubernetes/kubelet.kubeconfig
rm /etc/kubernetes/ssl/kubelet.*
systemctl restart kubelet
systemctl status kubeletrest

//查看未受權的CSR請求:
kubectl get csr

//approve CSR 請求:
kubectl certificate approve csr-4pw6g
NAME AGE REQUESTOR CONDITION
csr-4pw6g 1h kubelet-bootstrap Approved,Issued日誌

  1. 重啓kubelet

//重啓kubelet
systemctl restart kubeletserver

//查看node狀態
kubectl get no
NAME STATUS AGE VERSION
external Ready 1y v1.6.6

  1. 另:在kubernetes1.7以後,能夠採用集羣自動簽發證書方案,但仍然須要手動重啓kubelet, 在1.8以後,就能夠自動簽發,自動renew證書;也能夠設置更長的有效期。後繼再添加整理相關內容。
相關文章
相關標籤/搜索