雖然kubeadm已經是達到GA,而且ca證書預設是10年,但是經過其他ca簽發的證書預設只有1年時間,雖然目前還沒有遇到問題,但是需要未雨綢繆,提前驗證證書,本文也是參考大神的文章,經過本人驗證。
環境資訊
kubeadmin 1.13.3
複製程式碼
一.驗證不同時間編譯的二進位制的檔案是否一致
1.yum安裝的kubeadm
[root@host60 ~]# kubeadm version
kubeadm version: &version.Info{Major:"1", Minor:"13", GitVersion:"v1.13.3", GitCommit:"721bfa751924da8d1680787490c54b9179b1fed0", GitTreeState:"clean", BuildDate:"2019-02-01T20:05:53Z", GoVersion:"go1.11.5", Compiler:"gc", Platform:"linux/amd64"}
[root@host60 ~]# md5sum /usr/bin/kubeadm
7e7e0d0245cbcb9ce74b11c745ecc8f8 /usr/bin/kubeadm
複製程式碼
2.原始碼編譯時間節點A
[root@localhost kubernetes]# ./_output/dockerized/bin/linux/amd64/kubeadm version
kubeadm version: &version.Info{Major:"1", Minor:"13", GitVersion:"v1.13.3", GitCommit:"721bfa751924da8d1680787490c54b9179b1fed0", GitTreeState:"clean", BuildDate:"2019-02-25T01:32:35Z", GoVersion:"go1.11.5", Compiler:"gc", Platform:"linux/amd64"}
[root@localhost kubernetes]# md5sum ./_output/dockerized/bin/linux/amd64/kubeadm
789c964f5a76a78059b22e55dc1b13b1 ./_output/dockerized/bin/linux/amd64/kubeadm
複製程式碼
3.原始碼編譯時間節點B
[root@localhost kubernetes]# ./_output/dockerized/bin/linux/amd64/kubeadm version
kubeadm version: &version.Info{Major:"1", Minor:"13", GitVersion:"v1.13.3", GitCommit:"721bfa751924da8d1680787490c54b9179b1fed0", GitTreeState:"clean", BuildDate:"2019-02-25T01:44:22Z", GoVersion:"go1.11.5", Compiler:"gc", Platform:"linux/amd64"}
[root@localhost kubernetes]# md5sum ./_output/dockerized/bin/linux/amd64/kubeadm
9232aa9541f068e823ddbee217136705 ./_output/dockerized/bin/linux/amd64/kubeadm
複製程式碼
由此可以得出一個結論,雖然他們都是基於一套程式碼,甚至編譯環境一樣的,只是在不同時間節點編譯出來的檔案都不是一個檔案,但是應該不會影響使用,所以我才能放心修改原始碼進行重新編譯,並且可以基於他們的檔案進行修改。
二.重新編譯kubeadm原始碼
本文是購買阿里雲美國伺服器來驗證,避免牆的問題,在執行下面操作之前已經編譯過2次,就是上面的上次,如果是初次可能輸出略有不同
1.修改原始碼,檢視改動的程式碼
本文修改過2次,一次是增加10,另外一次是從10改成99
[root@localhost kubernetes]# git diff
diff --git a/staging/src/k8s.io/client-go/util/cert/cert.go b/staging/src/k8s.io/client-go/util/cert/cert.go
index 3429c82..7bc8141 100644
--- a/staging/src/k8s.io/client-go/util/cert/cert.go
+++ b/staging/src/k8s.io/client-go/util/cert/cert.go
@@ -74,7 +74,7 @@ func NewSelfSignedCACert(cfg Config, key crypto.Signer) (*x509.Certificate, erro
Organization: cfg.Organization,
},
NotBefore: now.UTC(),
- NotAfter: now.Add(duration365d * 10).UTC(),
+ NotAfter: now.Add(duration365d * 99).UTC(),
KeyUsage: x509.KeyUsageKeyEncipherment | x509.KeyUsageDigitalSignature | x509.KeyUsageCertSign,
BasicConstraintsValid: true,
IsCA: true,
@@ -109,7 +109,7 @@ func NewSignedCert(cfg Config, key crypto.Signer, caCert *x509.Certificate, caKe
IPAddresses: cfg.AltNames.IPs,
SerialNumber: serial,
NotBefore: caCert.NotBefore,
- NotAfter: time.Now().Add(duration365d).UTC(),
+ NotAfter: time.Now().Add(duration365d * 10).UTC(),
KeyUsage: x509.KeyUsageKeyEncipherment | x509.KeyUsageDigitalSignature,
ExtKeyUsage: cfg.Usages,
}
複製程式碼
2.重新編譯
[root@localhost kubernetes]# ./_output/dockerized/bin/linux/amd64/kubeadm version
kubeadm version: &version.Info{Major:"1", Minor:"13+", GitVersion:"v1.13.3-dirty", GitCommit:"721bfa751924da8d1680787490c54b9179b1fed0", GitTreeState:"dirty", BuildDate:"2019-02-25T02:13:07Z", GoVersion:"go1.11.5", Compiler:"gc", Platform:"linux/amd64"}
[root@localhost kubernetes]# md5sum ./_output/dockerized/bin/linux/amd64/kubeadm
0e11ca6f3bbccb59a35485be8da49dab ./_output/dockerized/bin/linux/amd64/kubeadm複製程式碼
對比上面的2次編譯git版本出現不同,是因為修改過的程式碼導致的
GitVersion:"v1.13.3-dirty"複製程式碼
3.準備kubeadm配置初始環境
為了避免其他原因,所以就在這個伺服器進行配置,主要就是安裝kubelet,過程略
yum install -y kubelet
複製程式碼
4.初始化叢集
由於只是驗證證書,所以並沒有準備配置檔案,而是直接初始化
我的初始化過程是錯誤的,因為這裡主要是驗證證書的問題,只要證書正常生產即可,其他的暫時不考慮
kubeadm init複製程式碼
5.驗證叢集證書
[root@iZrj95ing09kixersspt6gZ pki]# openssl x509 -in ca.crt -noout -dates
notBefore=Feb 25 02:27:28 2019 GMT
notAfter=Feb 1 02:27:28 2118 GMT
[root@iZrj95ing09kixersspt6gZ pki]# openssl x509 -in apiserver.crt -noout -dates
notBefore=Feb 25 02:27:28 2019 GMT
notAfter=Feb 22 02:27:29 2029 GMT
[root@iZrj95ing09kixersspt6gZ pki]# openssl x509 -in apiserver-etcd-client.crt -noout -dates
notBefore=Feb 25 02:27:27 2019 GMT
notAfter=Feb 22 02:27:28 2029 GMT
[root@iZrj95ing09kixersspt6gZ pki]# openssl x509 -in apiserver-kubelet-client.crt -noout -dates
notBefore=Feb 25 02:27:28 2019 GMT
notAfter=Feb 22 02:27:29 2029 GMT
[root@iZrj95ing09kixersspt6gZ pki]# openssl x509 -in front-proxy-client.crt -noout -dates
notBefore=Feb 25 02:27:27 2019 GMT
notAfter=Feb 22 02:27:27 2029 GMT
[root@iZrj95ing09kixersspt6gZ pki]# openssl x509 -in front-proxy-ca.crt -noout -dates
notBefore=Feb 25 02:27:27 2019 GMT
notAfter=Feb 1 02:27:27 2118 GMT
[root@iZrj95ing09kixersspt6gZ pki]# openssl x509 -in etcd/ca.e^Cnoout -dates
[root@iZrj95ing09kixersspt6gZ pki]# cd etcd
[root@iZrj95ing09kixersspt6gZ etcd]# openssl x509 -in ca.crt -noout -dates
notBefore=Feb 25 02:27:27 2019 GMT
notAfter=Feb 1 02:27:27 2118 GMT
[root@iZrj95ing09kixersspt6gZ etcd]# openssl x509 -in healthcheck-client.crt -noout -dates
notBefore=Feb 25 02:27:27 2019 GMT
notAfter=Feb 22 02:27:28 2029 GMT
[root@iZrj95ing09kixersspt6gZ etcd]# openssl x509 -in peer.crt -noout -dates
notBefore=Feb 25 02:27:27 2019 GMT
notAfter=Feb 22 02:27:28 2029 GMT
[root@iZrj95ing09kixersspt6gZ etcd]# openssl x509 -in server.crt -noout -dates
notBefore=Feb 25 02:27:27 2019 GMT
notAfter=Feb 22 02:27:28 2029 GMT
複製程式碼
可以看到CA證書是100年,其他經過他簽發的證書是10年,但是我剛才程式碼的修改明明是從1改成99了,為什麼簽發的證書只有10年呢,這個問題就留給大家去思考,其實我也不知道,你們知道了可以告訴我!
三.百度網盤下載
1.已有版本
v1.13.3複製程式碼