附065.kubefsb部署Kubernetes更新职称证书
一 查看证书
1.1 查看过期时间-方式一
1 [root@master01 ~]# tree /etc/kubernetes/pki/2 [root@master01 ~]# for tls in `find /etc/kubernetes/pki -maxdepth 2 -name "*.crt"`; \
3 do echo ===============$tls===============; \
4 openssl x509 -in $tls -text| grep Not; \
5 done
1.1 查看过期时间-方式二
1 [root@master01 ~]# tree /etc/kubernetes/pki/
1 [root@master01 ~]# kubeadm alpha certs check-expiration
二 证书类别
2.1 集群根证书
1 [root@master01 ~]# ll /etc/kubernetes/pki/ca*2 -rw-r--r-- 1 root root 1.1K Jun 15 21:08 /etc/kubernetes/pki/ca.crt
3 -rw------- 1 root root 1.7K Jun 15 21:08 /etc/kubernetes/pki/ca.key
- kube-apiserver 组件持有的服务端证书
1 [root@master01 ~]# ll /etc/kubernetes/pki/apiserver.*2 -rw-r--r-- 1 root root 1.3K Jun 15 21:08 /etc/kubernetes/pki/apiserver.crt
3 -rw------- 1 root root 1.7K Jun 15 21:08 /etc/kubernetes/pki/apiserver.key
- kubelet 组件持有的客户端证书
1 [root@master01 ~]# ll /etc/kubernetes/pki/apiserver-kubelet-client.*2 -rw-r--r-- 1 root root 1.1K Jun 15 21:08 /etc/kubernetes/pki/apiserver-kubelet-client.crt
3 -rw------- 1 root root 1.7K Jun 15 21:08 /etc/kubernetes/pki/apiserver-kubelet-client.key
2.2 汇聚层证书
1 [root@master01 ~]# ll /etc/kubernetes/pki/front-proxy-ca.*2 -rw-r--r-- 1 root root 1.1K Jun 15 21:08 /etc/kubernetes/pki/front-proxy-ca.crt
3 -rw------- 1 root root 1.7K Jun 15 21:08 /etc/kubernetes/pki/front-proxy-ca.key
1 [root@master01 ~]# ll /etc/kubernetes/pki/front-proxy-client.*2 -rw-r--r-- 1 root root 1.1K Jun 15 21:08 /etc/kubernetes/pki/front-proxy-client.crt
3 -rw------- 1 root root 1.7K Jun 15 21:08 /etc/kubernetes/pki/front-proxy-client.key
2.3 etcd集群根证书
1 [root@master01 ~]# ll /etc/kubernetes/pki/etcd/ca.*2 -rw-r--r-- 1 root root 1017 Jun 15 21:08 /etc/kubernetes/pki/etcd/ca.crt
3 -rw------- 1 root root 1.7K Jun 15 21:08 /etc/kubernetes/pki/etcd/ca.key
- etcd server服务端证书
1 [root@master01 ~]# ll /etc/kubernetes/pki/etcd/server.*2 -rw-r--r-- 1 root root 1.2K Jun 15 21:08 /etc/kubernetes/pki/etcd/server.crt
3 -rw------- 1 root root 1.7K Jun 15 21:08 /etc/kubernetes/pki/etcd/server.key
- etcd 集群中peer节点互相通信使用的客户端证书
1 [root@master01 ~]# ll /etc/kubernetes/pki/etcd/peer.*2 -rw-r--r-- 1 root root 1.2K Jun 15 21:08 /etc/kubernetes/pki/etcd/peer.crt
3 -rw------- 1 root root 1.7K Jun 15 21:08 /etc/kubernetes/pki/etcd/peer.key
- pod 中定义 Liveness 探针使用的客户端证书
1 [root@master01 ~]# ll /etc/kubernetes/pki/etcd/healthcheck-client.*2 -rw-r--r-- 1 root root 1.1K Jun 15 21:08 /etc/kubernetes/pki/etcd/healthcheck-client.crt
3 -rw------- 1 root root 1.7K Jun 15 21:08 /etc/kubernetes/pki/etcd/healthcheck-client.key
- 配置在 kube-apiserver 中用来与 etcd server 做双向认证的客户端证书
1 [root@master01 ~]# ll /etc/kubernetes/pki/apiserver-etcd-client.*2 -rw-r--r-- 1 root root 1.1K Jun 15 21:08 /etc/kubernetes/pki/apiserver-etcd-client.crt
3 -rw------- 1 root root 1.7K Jun 15 21:08 /etc/kubernetes/pki/apiserver-etcd-client.key
2.4 Serveice Account密钥
1 [root@master01 ~]# ll /etc/kubernetes/pki/sa.*2 -rw------- 1 root root 1.7K Jun 15 21:08 /etc/kubernetes/pki/sa.key
3 -rw------- 1 root root 451 Jun 15 21:08 /etc/kubernetes/pki/sa.pub
三 更新证书方法一
3.1 备份集群配置
1 [root@master01 ~]# kubeadm config view > kubeadm-cluster.yaml
3.2 更新证书
1 [root@master01 ~]# kubeadm alpha certs renew --help #查看帮助
1 [root@master01 ~]# kubeadm alpha certs renew all --config=kubeadm-cluster.yaml #更新所有证书
1 [root@master01 ~]# kubeadm alpha certs check-expiration #确认验证
1 [root@master01 ~]# scp -rp kubeadm-cluster.yaml root@master02:/root/2 [root@master01 ~]# scp -rp kubeadm-cluster.yaml root@master03:/root/
3 [root@master02 ~]# kubeadm alpha certs renew all --config=kubeadm-cluster.yaml
4 [root@master03 ~]# kubeadm alpha certs renew all --config=kubeadm-cluster.yaml
3.3 启用证书
1 [root@master01 ~]# docker ps |grep -E 'k8s_kube-apiserver|k8s_kube-controller-manager|k8s_kube-scheduler|k8s_etcd_etcd' | awk -F ' ' '{print $1}' |xargs docker restart2 [root@master02 ~]# docker ps |grep -E 'k8s_kube-apiserver|k8s_kube-controller-manager|k8s_kube-scheduler|k8s_etcd_etcd' | awk -F ' ' '{print $1}' |xargs docker restart
3 [root@master03 ~]# docker ps |grep -E 'k8s_kube-apiserver|k8s_kube-controller-manager|k8s_kube-scheduler|k8s_etcd_etcd' | awk -F ' ' '{print $1}' |xargs docker restart
四 更新证书方法二
4.1 备份集群配置
1 [root@master01 ~]# kubeadm config view > kubeadm-cluster.yaml
4.2 查看当前版本
1 [root@master01 ~]# kubectl version
4.3 获取源码
1 [root@master01 ~]# wget https://github.com/kubernetes/kubernetes/archive/v1.18.3.tar.gz2 [root@master01 ~]# tar -zxvf v1.18.3.tar.gz
3
4.4 修改CA证书时间
1 [root@master01 ~]# vi kubernetes-1.18.3/staging/src/k8s.io/client-go/util/cert/cert.go2 ……
3 57 func NewSelfSignedCACert(cfg Config, key crypto.Signer) (*x509.Certificate, error) {
4 ……
5 65 NotBefore: now.UTC(),
6 66 NotAfter: now.Add(duration365d * 100).UTC(),
7 ……
4.5 修改其他证书时间
1 [root@master01 ~]# vi kubernetes-1.18.3/cmd/kubeadm/app/constants/constants.go2 ……
3 39 const (
4 48 // CertificateValidity defines the validity for all the signed certificates generated by kubeadm
5 49 CertificateValidity = time.Hour * 24 * 365 * 100
6 ……
7 [root@master01 kubernetes-1.18.3]# cat build/build-image/cross/VERSION
8 v1.13.9-5 #使用官方corss版本
4.6 编译kubeadm方式一
1 [root@master01 kubernetes-1.18.3]# docker pull us.gcr.io/k8s-artifacts-prod/build-image/kube-cross:v1.13.9-52 [root@master01 ~]# docker run --rm -v /root/kubernetes-1.18.3/:/go/src/k8s.io/kubernetes -it us.gcr.io/k8s-artifacts-prod/build-image/kube-cross:v1.13.9-5 bash
3 root@51e96585ea73:/go# cd /go/src/k8s.io/kubernetes
4 root@51e96585ea73:/go/src/k8s.io/kubernetes# make all WHAT=cmd/kubeadm GOFLAGS=-v
1 root@51e96585ea73:/go/src/k8s.io/kubernetes# exit #退出容器2 [root@master01 ~]# mv /usr/bin/kubeadm /usr/bin/kubeadm_backup #备份原kubeadm
3 [root@master01 ~]# cp kubernetes-1.18.3/_output/local/bin/linux/amd64/kubeadm /usr/bin/kubeadm
4 [root@master01 ~]# kubeadm version #查看版本
4.7 编译kubeadm方式二
1 [root@master01 ~]# yum -y install gcc make rsync jq2 [root@master01 ~]# wget https://dl.google.com/go/go1.13.9.linux-amd64.tar.gz
3 [root@master01 ~]# tar zxvf go1.13.9.linux-amd64.tar.gz -C /usr/local/
4 [root@master01 ~]# vi /etc/profile.d/goenv.sh
5#go setting
6 export GOROOT=/usr/local/go
7 export GOPATH=/usr/local/gopath
8 export PATH=$PATH:$GOROOT/bin
9 [root@master01 ~]# source /etc/profile
10 [root@master01 ~]# go version
11 go version go1.13.9 linux/amd64
12 [root@master01 ~]# cd kubernetes-1.18.3/
13 [root@master01 kubernetes-1.18.3]# make all WHAT=cmd/kubeadm GOFLAGS=-v
14 [root@master01 kubernetes-1.18.3]# mv /usr/bin/kubeadm /usr/bin/kubeadm_backup #备份原kubeadm
15 [root@master01 kubernetes-1.18.3]# cp _output/local/bin/linux/amd64/kubeadm /usr/bin/kubeadm
4.8 备份集群配置
1 [root@master01 ~]# kubeadm config view > kubeadm-cluster.yaml
4.8 更新证书
1 [root@master01 ~]# ssh root@master02 "mv /usr/bin/kubeadm /usr/bin/kubeadm_backup"2 [root@master01 ~]# ssh root@master03 "mv /usr/bin/kubeadm /usr/bin/kubeadm_backup"
3 [root@master01 ~]# scp -rp kubeadm-cluster.yaml root@master02:/root/
4 [root@master01 ~]# scp -rp kubeadm-cluster.yaml root@master03:/root/
5 [root@master01 ~]# kubeadm alpha certs renew all --config=kubeadm-cluster.yaml
6 [root@master02 ~]# kubeadm alpha certs renew all --config=kubeadm-cluster.yaml
7 [root@master03 ~]# kubeadm alpha certs renew all --config=kubeadm-cluster.yaml
8 [root@master01 ~]# kubeadm alpha certs check-expiration #确认验证
4.9 启用证书
以上是 附065.kubefsb部署Kubernetes更新职称证书 的全部内容, 来源链接: utcz.com/a/55350.html