Kubeadm无法在升级时签署证书

时间:2019-09-20 10:46:10

标签: kubernetes kubespray

在使用kubespray将Kubernetes从1.14升级到1.15的过程中,我的团队在“ Upgrade first master”步骤中遇到了以下消息的阻塞问题:

[upgrade/apply] FATAL: couldn''t upgrade control plane.
kubeadm has tried to recover everything into the earlier state.
Errors faced: [failed to renew certificates for component "kube-apiserver":
failed to renew certificate apiserver-kubelet-client:
unable to sign certificate:
must specify at least one ExtKeyUsage,
rename /etc/kubernetes/tmp/kubeadm
-backup-manifests-2019-09-19-09-06-27/kube-apiserver.yaml /etc/kubernetes/manifests/kube-apiserver.yaml: no such file or directory]'

尝试隔离任务并手动运行kubeadm命令行会导致相同的错误消息:

#/usr/local/bin/kubeadm upgrade apply -y v1.15.3 --config=/etc/kubernetes/kubeadm-config.yaml --ignore-preflight-errors=all --allow-experimental-upgrades --allow-release-candidate-upgrades --etcd-upgrade=false -v 6 

,甚至尝试手动续订证书:

/etc/kubernetes/pki# kubeadm alpha certs renew apiserver-kubelet-client -v 9
I0919 14:42:11.515503   18597 initconfiguration.go:105] detected and using CRI socket: /var/run/dockershim.sock
I0919 14:42:11.515897   18597 interface.go:384] Looking for default routes with IPv4 addresses
I0919 14:42:11.515916   18597 interface.go:389] Default route transits interface “eth0”
I0919 14:42:11.516284   18597 interface.go:196] Interface eth0 is up
(...)
I0919 14:42:11.516835   18597 feature_gate.go:216] feature gates: &{map[]}
failed to renew certificate apiserver-kubelet-client: unable to sign certificate: must specify at least one ExtKeyUsage

最终找到了解决方案并将其发布在下面。

1 个答案:

答案 0 :(得分:3)

问题出在kubeadm,它在必须更新旧证书时使用旧证书。但是,当这些初始证书太旧或是手动生成的时,它们可能不包括一些必须存在的必填字段。

在错误消息中,ExtKeyUsage指向X509v3 Extended Key Usage字段。

您可以通过查看证书来进行检查:涉及2个证书:apiserver-kubelet-client.crtfront-proxy-client.crt

它们位于/etc/kubernetes/pki的主控主机上。

您可以使用

进行检查

# openssl x509 -in apiserver-kubelet-client.crt -text -noout

如果它们不包含以下内容(接近尾声),则kubeadm将完全无法更新证书

(...)
        X509v3 extensions:
            X509v3 Key Usage: critical
                Digital Signature, Key Encipherment
            X509v3 Extended Key Usage:
                TLS Web Client Authentication

TL; DR;

解决方案就是按照以下步骤创建全新的证书

######### Backup your certificates (just in case)
master01:/etc/kubernetes/pki# cp -a /etc/kubernetes/pki /root/backup_cert/
######### Delete incomplete certificates
master01:/etc/kubernetes/pki# rm apiserver-kubelet-client.*
master01:/etc/kubernetes/pki# rm front-proxy-client.*
######### Then recreate them
master01:/etc/kubernetes/pki# kubeadm init phase certs apiserver-kubelet-client 
master01:/etc/kubernetes/pki# kubeadm init phase certs front-proxy-client

您现在可以重新启动升级过程,应该可以了。 (注意:如果您的集群处于第一个主节点处于SchedulingDisabled状态的状态,则不要忘记取消托管主机,因为kubespray剧本无法解决该问题)