首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >轮换Kubernetes证书的最佳实践是什么

轮换Kubernetes证书的最佳实践是什么
EN

Stack Overflow用户
提问于 2021-05-22 04:35:07
回答 2查看 795关注 0票数 3

目前,我正在使用脚本在Kubernetes证书过期之前对其进行续订。但这是一个手动的过程。我必须仔细监控到期日期,并提前运行此脚本。在不更新控制平面的情况下自动更新所有控制平面证书的推荐方法是什么?kubelet的-- rotate *标志是旋转所有组件(例如控制器)还是仅用于kubelet?PS: Kubernetes集群使用kubeadm创建。

EN

回答 2

Stack Overflow用户

发布于 2021-05-23 23:24:25

从kubernetes 1.8开始,添加了证书轮换。你可以在这里读到,https://kubernetes.io/docs/tasks/tls/certificate-rotation/

票数 0
EN

Stack Overflow用户

发布于 2021-06-01 19:30:48

回答以下问题:

在不更新控制平面的情况下自动更新所有控制平面证书的推荐方法是什么

根据k8s文档和最佳实践,最佳实践是对控制平面升级使用“自动证书续订”:

自动证书续订

注意:为了保证安全,最好的做法是经常升级集群。

--

为什么这是推荐的方式:

从最佳实践的角度来看,您应该升级control-plane以修补漏洞、添加功能并使用当前支持的版本。

每次control-plane升级都会按照说明续订证书(默认为true):

  • $ kubeadm upgrade apply --help

代码语言:javascript
复制
--certificate-renewal    Perform the renewal of certificates used by component changed during upgrades. (default true)

您还可以通过运行以下命令来检查control-plane证书的过期时间:

  • $ kubeadm certs check-expiration

代码语言:javascript
复制
[check-expiration] Reading configuration from the cluster...
[check-expiration] FYI: You can look at this config file with 'kubectl -n kube-system get cm kubeadm-config -o yaml'
 
CERTIFICATE                EXPIRES                  RESIDUAL TIME   CERTIFICATE AUTHORITY   EXTERNALLY MANAGED
admin.conf                 May 30, 2022 13:36 UTC   364d                                    no      
apiserver                  May 30, 2022 13:36 UTC   364d            ca                      no      
apiserver-etcd-client      May 30, 2022 13:36 UTC   364d            etcd-ca                 no      
apiserver-kubelet-client   May 30, 2022 13:36 UTC   364d            ca                      no      
controller-manager.conf    May 30, 2022 13:36 UTC   364d                                    no      
etcd-healthcheck-client    May 30, 2022 13:36 UTC   364d            etcd-ca                 no      
etcd-peer                  May 30, 2022 13:36 UTC   364d            etcd-ca                 no      
etcd-server                May 30, 2022 13:36 UTC   364d            etcd-ca                 no      
front-proxy-client         May 30, 2022 13:36 UTC   364d            front-proxy-ca          no      
scheduler.conf             May 30, 2022 13:36 UTC   364d                                    no      
 
CERTIFICATE AUTHORITY   EXPIRES                  RESIDUAL TIME   EXTERNALLY MANAGED
ca                      May 28, 2031 13:36 UTC   9y              no      
etcd-ca                 May 28, 2031 13:36 UTC   9y              no      
front-proxy-ca          May 28, 2031 13:36 UTC   9y              no  

附注!

由于kubeadmkubelet配置为自动证书续订,因此kubelet.conf不包括在上面的列表中。

从默认情况下可以看到:

kubeadm生成的

  • 客户端证书将在1年后过期。由kubeadm创建的
  • CA将在10年后过期。

还有其他功能允许您以“半自动”的方式轮换证书。

您可以选择手动续订证书,方法是:

  • $ kubeadm certs renew

其中,您可以自动(使用命令)续订指定的(或所有)证书:

  • $ kubeadm certs renew all

代码语言:javascript
复制
[renew] Reading configuration from the cluster...
[renew] FYI: You can look at this config file with 'kubectl -n kube-system get cm kubeadm-config -o yaml'
 
certificate embedded in the kubeconfig file for the admin to use and for kubeadm itself renewed
certificate for serving the Kubernetes API renewed
certificate the apiserver uses to access etcd renewed
certificate for the API server to connect to kubelet renewed
certificate embedded in the kubeconfig file for the controller manager to use renewed
certificate for liveness probes to healthcheck etcd renewed
certificate for etcd nodes to communicate with each other renewed
certificate for serving etcd renewed
certificate for the front proxy client renewed
certificate embedded in the kubeconfig file for the scheduler manager to use renewed
 
Done renewing certificates. You must restart the kube-apiserver, kube-controller-manager, kube-scheduler and etcd, so that they can use the new certificates.

请具体查看输出:

代码语言:javascript
复制
You must restart the kube-apiserver, kube-controller-manager, kube-scheduler and etcd, so that they can use the new certificates.

如上所述,您需要重新启动control-plane的组件才能使用新证书,但请记住:

  • $ kubectl delete pod -n kube-system kube-scheduler-ubuntu 将不会work.

您将需要重新启动负责该组件的docker容器:

  • $ docker ps | grep -i "scheduler"
  • $ docker restart 8c361562701b (示例)

代码语言:javascript
复制
8c361562701b   38f903b54010             "kube-scheduler --au…"   11 minutes ago      Up 11 minutes                k8s_kube-scheduler_kube-scheduler-ubuntu_kube-system_dbb97c1c9c802fa7cf2ad7d07938bae9_5
b709e8fb5e6c   k8s.gcr.io/pause:3.4.1   "/pause"                 About an hour ago   Up About an hour             k8s_POD_kube-scheduler-ubuntu_kube-system_dbb97c1c9c802fa7cf2ad7d07938bae9_0

正如下面的链接所指出的,kubelet可以自动续订其证书(kubeadm以启用此选项的方式配置群集):

根据您的环境中使用的版本,可以禁用此功能。据我所知,目前在kubeadm管理的最新版本的k8s中,默认情况下该选项是启用的。

请记住,在开始使用任何kubernetes节点/控制平面/更新/升级到之前,请阅读特定于您的k8s版本(示例)的“紧急升级说明”:

定义证书轮换的自动方式可以采用任何一种方式,但您可以使用前面提到的命令自动执行此过程。您需要创建一个脚本(您已经有了),该脚本将放在cron中,并在一段时间后触发并更新它们。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/67643559

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档