在管理证书以前,你须要了解kubernetes如何使用PKI证书的相关知识:官方文档node
check-expiration 可用于检查证书过时时间:api
kubeadm alpha certs check-expiration
输出以下内容;安全
CERTIFICATE EXPIRES RESIDUAL TIME EXTERNALLY MANAGED admin.conf Oct 06, 2020 03:56 UTC 364d no apiserver Oct 06, 2020 10:41 UTC 364d no apiserver-etcd-client Oct 06, 2020 03:55 UTC 364d no apiserver-kubelet-client Oct 06, 2020 03:55 UTC 364d no controller-manager.conf Oct 06, 2020 03:56 UTC 364d no etcd-healthcheck-client Oct 02, 2020 12:14 UTC 361d no etcd-peer Oct 02, 2020 12:14 UTC 361d no etcd-server Oct 02, 2020 12:14 UTC 361d no front-proxy-client Oct 06, 2020 03:55 UTC 364d no scheduler.conf Oct 06, 2020 03:56 UTC 364d no
该命令显示了 全部证书的到期/剩余时间,包括在etc/kubernetes/pki目录下的客户端证书及由kubeadm嵌入到KUBECONFIG文件中的客户端证书(admin.conf,controller-manager.conf和scheduler.conf)。app
注意:ide
- kubelet.conf未包含在上面的列表中,由于kubeadm将已将其配置为自动更新。
- kubeadm没法管理由外部CA签名的证书。
自动续订指的是,在用kubeadm升级控制平面时 自动更新全部证书。ui
若是对证书续约没有要求,并按期升级kubernetes版本,每次升级间隔时间少于1年,最佳作法是常常升级集群以确保安全。this
若是不想在升级集群时续约证书,则给 kubeadm upgrade apply 或 kubeadm upgrade node 传递参数:--certificate-renewal=falserest
使用 kubeadm alpha certs renew 命令 能够随时手动续订证书,该命令使用存储在/etc/kubernetes/pki中的 CA (or front-proxy-CA)证书和密钥来更新证书。code
若是是HA集群,则在全部控制平面执行。server
kubeadm alpha certs 命令详解:
Available Commands: certificate-key 生成证书和key check-expiration 检测证书过时时间 renew 续订Kubernetes集群的证书
用的最多的续订证书的 renew子命令,如今来看下该命令帮助:
root@k8s-master:~# kubeadm alpha certs renew -h This command is not meant to be run on its own. See list of available subcommands. Usage: kubeadm alpha certs renew [flags] kubeadm alpha certs renew [command] Available Commands: admin.conf Renew the certificate embedded in the kubeconfig file for the admin to use and for kubeadm itself all Renew all available certificates apiserver Renew the certificate for serving the Kubernetes API apiserver-etcd-client Renew the certificate the apiserver uses to access etcd apiserver-kubelet-client Renew the certificate for the API server to connect to kubelet controller-manager.conf Renew the certificate embedded in the kubeconfig file for the controller manager to use etcd-healthcheck-client Renew the certificate for liveness probes to healtcheck etcd etcd-peer Renew the certificate for etcd nodes to communicate with each other etcd-server Renew the certificate for serving etcd front-proxy-client Renew the certificate for the front proxy client scheduler.conf Renew the certificate embedded in the kubeconfig file for the scheduler manager to use Flags: -h, --help help for renew Global Flags: --log-file string If non-empty, use this log file --log-file-max-size uint Defines the maximum size a log file can grow to. Unit is megabytes. If the value is 0, the maximum file size is unlimited. (default 1800) --rootfs string [EXPERIMENTAL] The path to the 'real' host root filesystem. --skip-headers If true, avoid header prefixes in the log messages --skip-log-headers If true, avoid headers when opening log files -v, --v Level number for the log level verbosity
如上所知,指定某个证书就能续订该证书,指定 all
则续订全部证书。
命令执行后,注意:
kubeadm alpha certs命令仅支持v1.15及其以上的版本。
从上面检测中知道,当前 apiserver.crt 到期时间是 Oct 06, 2020 03:55 UTC ,剩余364d。
1. 执行renew更新:
root@k8s-master:~# kubeadm alpha certs renew apiserver certificate for serving the Kubernetes API renewed
2. 重启控制平面:
重启kubelet会自动从新建立核心组件
systemctl restart kubelet
3. 验证:
root@k8s-master:~# kubeadm alpha certs check-expiration CERTIFICATE EXPIRES RESIDUAL TIME EXTERNALLY MANAGED apiserver Oct 06, 2020 10:41 UTC 364d no
apiserver证书到期时间发生了变化, 不过不是顺延一年, 而是 从你 执行renew成功的时间开始续签一年。
若是要将全部证书续签一年,则执行:
kubeadm alpha certs renew all
经过外部CA签发证书,须要kubeadm 生成一个CSR提交给CA。
1. 生成CSR和私钥:
kubeadm alpha certs renew apiserver --csr-only --csr-dir /tmp/apiserver.csr
2. 查看CSR和私钥:
命令输出结果中提供了CSR和私钥。
root@k8s-master:~# ls /tmp/apiserver.csr/ apiserver.csr apiserver.key
3. 使用该私钥到CA上请求签发证书。
将颁发的证书及私钥复制到PKI目录/etc/kubernetes/pki中。