Code Monkey home page Code Monkey logo

update-kube-cert's Introduction

该脚本用于处理已过期或者即将过期的kubernetes集群证书

kubeadm生成的证书有效期为为1年,该脚本可将kubeadm生成的证书有效期更新为10年

该脚本只处理master节点上的证书:kubeadm默认配置了kubelet证书自动更新,node节点kubelet.conf所指向的证书会自动更新

小于v1.17版本的master初始化节点(执行kubeadm init的节点) kubelet.conf里的证书并不会自动更新,这算是一个bug,该脚本会一并处理更新master节点的kubelet.conf所包含的证书

1. 使用说明

小于等于v1.9版本,etcd默认是不使用TLS连接,没有etcd相关证书,只需要更新master证书即可

大于等于v1.10版本,etcd默认开启TLS,需要更新etcd证书和master证书

该脚本适用于所有k8s版本集群证书更新,但大于等于v1.15版本建议使用kubeadm命令更新

该脚本仅需要在master和etcd节点执行,无需在node节点执行

1.1. 拉取脚本

git clone https://github.com/yuyicai/update-kube-cert.git
cd update-kubeadm-cert
chmod 755 update-kubeadm-cert.sh

执行时请使用./update-kubeadm-cert.sh all或者bash update-kubeadm-cert.sh all,不要使用sh update-kubeadm-cert.sh all,因为某些发行版sh并不是链接到bash,会不兼容

1.2. 同时更新etcd证书和master证书

如果master和etcd在同一个节点,执行以下命令更新证书全部etcd证书和master证书

如果有多个master节点,在每个master节点都执行一次

./update-kubeadm-cert.sh all

将更新以下证书和kubeconfig配置文件

/etc/kubernetes
├── admin.conf
├── controller-manager.conf
├── scheduler.conf
├── kubelet.conf
└── pki
    ├── apiserver.crt
    ├── apiserver-etcd-client.crt
    ├── apiserver-kubelet-client.crt
    ├── front-proxy-client.crt
    └── etcd
        ├── healthcheck-client.crt
        ├── peer.crt
        └── server.crt

1.3. 只更新etcd证书

如果有多个etcd节点,在每个etcd节点上都执行一次

./update-kubeadm-cert.sh etcd

将更新以下etcd证书

/etc/kubernetes
 └── pki
  ├── apiserver-etcd-client.crt
  └── etcd
      ├── healthcheck-client.crt
      ├── peer.crt
      └── server.crt

1.4. 只更新master证书

如果有多个master节点,在每个master节点都执行一次

./update-kubeadm-cert.sh master

将更新以下master证书和kubeconfig配置文件

/etc/kubernetes
├── admin.conf
├── controller-manager.conf
├── scheduler.conf
├── kubelet.conf
└── pki
    ├── apiserver.crt
    ├── apiserver-kubelet-client.crt
    └── front-proxy-client.crt

2. 证书更新失败回滚

脚本会自动备份/etc/kubernetes目录到/etc/kubernetes.old-$(date +%Y%m%d)目录(备份目录名录示例:kubernetes.old-20200325)

若更新证书失败需要回滚,手动将份/etc/kubernetes.old-$(date +%Y%m%d)目录覆盖/etc/kubernetes目录

3. kubeadm 证书相关命令发展

  • v1.8版开始提供了证书生成命令kubeadm alpha phase certs <cert_name>
  • v1.13版开始证书生成命令改为kubeadm init phase certs <cert_name>
  • v1.15版增加了证书更新命令kubeadm alpha certs renew <cert_name>(这个命令与上面两个区别是:上面两个是生成证书,这个是更新证书),v1.15版之后建议使用kubeadm alpha certs renew <cert_name>来更新证书

4. 关于大于等于v1.15版本

大于等于v1.15的版本建议直接使用kubeadm alpha certs renew <cert_name>来更新证书有效期,更新后延长一年

小坑:

kubeadm alpha certs renew 并不会更新kubelet证书(kubelet.conf文件里面写的客户端证书),因为kubelet证书是默认开启自动更新的

但是在执行kubeadm init的master节点的kubelet.conf文件里面的证书是以base64编码写死在conf文件的(和controller-manager.conf一样),在用kubeadm命令更新master证书时需要手动将kubelet.conf文件的 client-certificate-dataclient-key-data 该为:

client-certificate: /var/lib/kubelet/pki/kubelet-client-current.pem
client-key: /var/lib/kubelet/pki/kubelet-client-current.pem

这个问题在v1.17版得到了解决kubernetes/kubeadm#1753

update-kube-cert's People

Contributors

yuyicai avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.