k8s证书配置过期时间(默认1年,修改源码解决)

参考文档: https://blog.51cto.com/11889458/2323328

  • 下载源码并切换分支
git clone https://github.com/kubernetes/kubernetes.git -b release-1.17  v1.17.3
  • 安装go
mkdir /data/soft
cd /data/soft/
wget https://dl.google.com/go/go1.13.6.linux-amd64.tar.gz
tar zxvf go1.13.6.linux-amd64.tar.gz -C /usr/local/

vim /etc/profile
export GOROOT=/usr/local/go
export GOPATH=/usr/local/gopath
export PATH=$PATH:$GOROOT/bin

source /etc/profile
go version
  • 修改源码
vim /data/v1.17.3/staging/src/k8s.io/client-go/util/cert/cert.go
96         maxAge := time.Hour * 24 * 365 * 10         // one year self-signed certs

vim /data/v1.17.3/cmd/kubeadm/app/constants/constants.go
47         CertificateValidity = time.Hour * 24 * 365 * 10
  • 编译
cd /data/v1.17.3/
KUBE_BUILD_PLATFORMS=linux/amd64 make WHAT=cmd/kubeadm GOFLAGS=-v GOGCFLAGS="-N -l"
  • 将编译出的二进制也执行文件替换到现有系统的kubeadm目录
ls -l /data/v1.17.3/_output/bin/kubeadm
mv /usr/bin/kubeadm /usr/bin/kubeadm_backup
ln -s /data/v1.17.3/_output/bin/kubeadm /usr/bin/kubeadm
  • 重新初始化集群
kubeadm reset
kubeadm init --config=kubeadm-config.yaml --upload-certs | tee kubeadm-init.log
rm -rf $HOME/.kube
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
  • 验证结果
cd /etc/kubernetes/pki/
openssl x509 -in front-proxy-client.crt   -noout -text  |grep Not
openssl x509 -in apiserver.crt   -noout -text  |grep Not

k8s证书配置过期时间(默认1年,修改源码解决)