Renew kubernetes pki after expired

前端 未结 8 1607
星月不相逢
星月不相逢 2020-12-02 23:48

My kubernetes PKI expired (API server to be exact) and I can\'t find a way to renew it. The error I get is

May 27 08:43:51 node1 kubelet[8751]: I0527 08:43:5         


        
相关标签:
8条回答
  • 2020-12-03 00:19

    Try to do cert renewal via kubeadm init phase certs command.

    You can check certs expiration via the following command:

    openssl x509 -in /etc/kubernetes/pki/apiserver.crt -noout -text

    openssl x509 -in /etc/kubernetes/pki/apiserver-kubelet-client.crt -noout -text

    First, ensure that you have most recent backup of k8s certificates inventory /etc/kubernetes/pki/*.

    Delete apiserver.* and apiserver-kubelet-client.* cert files in /etc/kubernetes/pki/ directory.

    Spawn a new certificates via kubeadm init phase certs command:

    sudo kubeadm init phase certs apiserver

    sudo kubeadm init phase certs apiserver-kubelet-client

    Restart kubelet and docker daemons:

    sudo systemctl restart docker; sudo systemctl restart kubelet

    You can find more related information in the official K8s documentation.

    0 讨论(0)
  • 2020-12-03 00:25
    [root@nrchbs-slp4115 ~]# kubectl get apiservices |egrep metrics
    v1beta1.metrics.k8s.io                 kube-system/metrics-server   True        125m
    
    
    [root@nrchbs-slp4115 ~]# kubectl get svc -n kube-system
    NAME             TYPE        CLUSTER-IP   EXTERNAL-IP   PORT(S)                  AGE
    kube-dns         ClusterIP   10.96.0.10   <none>        53/UDP,53/TCP,9153/TCP   20d
    metrics-server   ClusterIP   10.99.2.11   <none>        443/TCP                  125m
    
    
    [root@nrchbs-slp4115 ~]# kubectl get ep -n kube-system
    NAME                      ENDPOINTS                                               AGE
    kube-controller-manager   <none>                                                  20d
    kube-dns                  10.244.0.5:53,10.244.0.6:53,10.244.0.5:53 + 3 more...   20d
    kube-scheduler            <none>                                                  20d
    metrics-server            10.244.2.97:443                                         125m
    [root@nrchbs-slp4115 ~]#
    
    0 讨论(0)
  • 2020-12-03 00:27

    This topic is also discussed in:

    • https://github.com/kubernetes/kubeadm/issues/581
      • after 1.15 kubeadm upgrade automatically will renewal the certificates for you!
      • also 1.15 added a command to check cert expiration in kubeadm
    • Kubernetes: expired certificate

    Kubernetes v1.15 provides docs for "Certificate Management with kubeadm":

    • https://kubernetes.io/docs/tasks/administer-cluster/kubeadm/kubeadm-certs/
    • Check certificate expiration:
    kubeadm alpha certs check-expiration
    
    • Automatic certificate renewal:
      • kubeadm renews all the certificates during control plane upgrade.
    • Manual certificate renewal:
      • You can renew your certificates manually at any time with the kubeadm alpha certs renew command.
      • This command performs the renewal using CA (or front-proxy-CA) certificate and key stored in /etc/kubernetes/pki.

    Overall for Kubernetes v1.14 I find this procedure the most helpful:

    • https://stackoverflow.com/a/56334732/1147487
    0 讨论(0)
  • 2020-12-03 00:28

    This will update all certs under /etc/kubernetes/ssl

    kubeadm alpha certs renew all --config=/etc/kubernetes/kubeadm-config.yaml
    

    and do this to restart server commpenont:

    kill -s SIGHUP $(pidof kube-apiserver)
    kill -s SIGHUP $(pidof kube-controller-manager)
    kill -s SIGHUP $(pidof kube-scheduler)
    
    0 讨论(0)
  • 2020-12-03 00:29

    I was using Kubernetes v15.1 and updated my certificates as explained above, but I still got the same error. The /etc/kubernetes/kubelet.conf was still referring to the expired/old "client-certificate-data".

    After some research I found out that kubeadm is not updating the /etc/kubernetes/kubelet.conf file if the certificate-renew was not set to true. So please be aware of a bug of kubeadm below version 1.17 (https://github.com/kubernetes/kubeadm/issues/1753).

    kubeadm only upgrades if the cluster upgrade was done with certificate-renewal=true. So I manually had to delete the /etc/kubernetes/kubelet.conf and regenerated it with kubeadm init phase kubeconfig kubelet which finally fixed my problem.

    0 讨论(0)
  • 2020-12-03 00:31

    I use a config.yaml to configure the Masters so for me, the answer was:

    sudo -i
    mkdir -p ~/k8s_backup/etcd
    cd /etc/kubernetes/pki/
    mv {apiserver.crt,apiserver-etcd-client.key,apiserver-kubelet-client.crt,front-proxy-ca.crt,front-proxy-client.crt,front-proxy-client.key,front-proxy-ca.key,apiserver-kubelet-client.key,apiserver.key,apiserver-etcd-client.crt} ~/k8s_backup
    cd /etc/kubernetes/pki/etcd
    mv {healthcheck-client.crt,healthcheck-client.key,peer.crt,peer.key,server.crt,server.key} ~/k8s_backup/etcd/
    kubeadm init phase certs all --ignore-preflight-errors=all --config /etc/kubernetes/config.yaml
    
    cd /etc/kubernetes
    mv {admin.conf,controller-manager.conf,kubelet.conf,scheduler.conf} ~/k8s_backup
    kubeadm init phase kubeconfig all --config /etc/kubernetes/config.yaml --ignore-preflight-errors=all
    

    For good measure I reboot

    shutdown now -r
    
    0 讨论(0)
提交回复
热议问题