I've seen this issues in many other forums, and I finally found a solutions that works from me.
First, my issues was purely due to the certificate /var/lib/kubelet/pki/kubelet.crt
, which I can see expired with either:
echo -n | openssl s_client -connect localhost:10250 2>&1 | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' | openssl x509 -text -noout | grep -A 2 Validity
or
sudo openssl x509 -in /var/lib/kubelet/pki/kubelet.crt -text -noout | grep -A 2 Validity
First, you need to enable --rotate-certificates=true
and --rotate-server-certificates=true
in your kubelet. In my case, I installed the cluster using kubeadm
, so I can edit the /etc/systemd/system/kubelet.service.d/10-kubeadm.conf
, and add the following to KUBELET_EXTRA_ARGS
:
Environment="KUBELET_EXTRA_ARGS=--rotate-certificates=true --rotate-server-certificates=true --tls-cipher-suites=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256"
In general, it is just adding these flags to the kubelet exeuction /usr/bin/kubelet --rotate-certificates=true --rotate-server-certificates=true
.
And, reload and restart kubelet with:
sudo systemctl daemon-reload
sudo service kubelet restart
After the restart, I see something like 14114 log.go:172] http: TLS handshake error from 20.0.0.13:57738: no serving certificate available for the kubelet
, which indicates that the certificate needs to be added and approve.
Secondly, we need to approve the csr
from kubernetes (this is something I've never look at before...):
kubectl get csr
There will see the certificate waiting to be approved, so just approved:
kubectl certificate approve csr-dlcf6
And your cluster should now have the server kubelet certificate renew. To verify again:
echo -n | openssl s_client -connect localhost:10250 2>&1 | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' | openssl x509 -text -noout | grep -A 2 Validity
Some notes:
- We have enabled the rotation for both client and server. Client rotation is also part of the automatic cert renew script (https://kubernetes.io/docs/tasks/administer-cluster/kubeadm/kubeadm-certs/)
- After we have enable the rotation the
/var/lib/kubelet/pki/kubelet.crt
is no longer used, instead the symbolic link /var/lib/kubelet/pki/kubelet-server-current.pem
is used and points to the latest rotated certificate.
References: