$ sudo kubeadm alpha certs check-expiration # [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 -oyaml'
# CERTIFICATE EXPIRES RESIDUAL TIME CERTIFICATE AUTHORITY(认证中心) EXTERNALLY MANAGED(外部管理) # admin.conf Nov 05, 2021 08:47 UTC 328d no # apiserver Nov 05, 2021 08:47 UTC 328d ca no # apiserver-etcd-client Nov 05, 2021 08:47 UTC 328d etcd-ca no # apiserver-kubelet-client Nov 05, 2021 08:47 UTC 328d ca no # controller-manager.conf Nov 05, 2021 08:47 UTC 328d no # etcd-healthcheck-client Nov 05, 2021 08:47 UTC 328d etcd-ca no # etcd-peer Nov 05, 2021 08:47 UTC 328d etcd-ca no # etcd-server Nov 05, 2021 08:47 UTC 328d etcd-ca no # front-proxy-client Nov 05, 2021 08:47 UTC 328d front-proxy-ca no # scheduler.conf Nov 05, 2021 08:47 UTC 328d no
# CERTIFICATE AUTHORITY EXPIRES RESIDUAL TIME EXTERNALLY MANAGED # ca Nov 03, 2030 08:47 UTC 9y no # etcd-ca Nov 03, 2030 08:47 UTC 9y no # front-proxy-ca Nov 03, 2030 08:47 UTC 9y no
~/.k8s$ sudo kubeadm alpha certs renew all --config=./kubeadm-init-config.yaml # W1212 17:17:16.721037 1306627 configset.go:348] WARNING: kubeadm cannot validate component configs for API groups [kubelet.config.k8s.io kubeproxy.config.k8s.io] # certificate embedded in the kubeconfig file for the admin to use and for kubeadm itself renewed # 嵌入在kubeconfig文件中的证书,供管理员使用,并对kubeadm本身进行更新 (admin.conf ) # certificate for serving the Kubernetes API renewed # 更新Kubernetes API服务证书 # certificate the apiserver uses to access etcd renewed # 服务器访问etcd所使用的证书已更新 # certificate for the API server to connect to kubelet renewed # API服务器连接到kubelet的证书已更新 # certificate embedded in the kubeconfig file for the controller manager to use renewed # 证书嵌入在kubeconfig文件中,供控制器管理器使用更新 (controller-manager.conf) # certificate for liveness probes to healthcheck etcd renewed # 健康检查etcd激活探针证书续期 # certificate for etcd nodes to communicate with each other renewed # 用于etcd节点之间通信的证书更新 # certificate for serving etcd renewed # 续期etcd“服务证书” # certificate for the front proxy client renewed # 前代理客户端的证书更新 # certificate embedded in the kubeconfig file for the scheduler manager to use renewed #证书嵌入在kubeconfig文件中,供调度器管理器使用更新 (scheduler.conf )
~/.k8s$ sudo kubeadm alpha certs check-expiration # [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 -oyaml' # PS -> 显示顺序与上面刷新证书的顺序是一致的 # CERTIFICATE EXPIRES RESIDUAL TIME CERTIFICATE AUTHORITY EXTERNALLY MANAGED # admin.conf Dec 12, 2021 09:17 UTC 364d no # apiserver Dec 12, 2021 09:17 UTC 364d ca no # apiserver-etcd-client Dec 12, 2021 09:17 UTC 364d etcd-ca no # apiserver-kubelet-client Dec 12, 2021 09:17 UTC 364d ca no # controller-manager.conf Dec 12, 2021 09:17 UTC 364d no # etcd-healthcheck-client Dec 12, 2021 09:17 UTC 364d etcd-ca no # etcd-peer Dec 12, 2021 09:17 UTC 364d etcd-ca no # etcd-server Dec 12, 2021 09:17 UTC 364d etcd-ca no # front-proxy-client Dec 12, 2021 09:17 UTC 364d front-proxy-ca no # scheduler.conf Dec 12, 2021 09:17 UTC 364d no
# CERTIFICATE AUTHORITY EXPIRES RESIDUAL TIME EXTERNALLY MANAGED # ca Nov 03, 2030 08:47 UTC 9y no # etcd-ca Nov 03, 2030 08:47 UTC 9y no # front-proxy-ca Nov 03, 2030 08:47 UTC 9y no
86 // GenerateSelfSignedCertKeyWithFixtures creates a self-signed certificate and key for the given host. 94 func GenerateSelfSignedCertKeyWithFixtures(host string, alternateIPs []net.IP, alternateDNS []string, fixtureDirector y string) ([]byte, []byte, error) { 96 maxAge := time.Hour * 24 * 365 * 10 // one year self-signed certs 123 NotBefore: validFrom, 124 NotAfter: validFrom.Add(maxAge),
// NewSignedCert creates a signed certificate using the given CA certificate and key func NewSignedCert(cfg *CertConfig, key crypto.Signer, caCert *x509.Certificate, caKey crypto.Signer) (*x509.Certificate, error) { const duration365d = time.Hour * 24 * 365 * 10
结果在这里找到kubeadmconstants.CertificateValidity的定义 vim cmd/kubeadm/app/util/pkiutil/pki_helpers.go # 这个方法里面看到NotAfter: time.Now().Add(kubeadmconstants.CertificateValidity).UTC() # 参数里面是一个常量kubeadmconstants.CertificateValidity # 所以这里可以不修改,我去看看源码能不能找到这个常量的赋值位置 // CertificateValidity defines the validity for all the signed certificates generated by kubeadm CertificateValidity = time.Hour * 24 * 365 * 10 NotBefore: caCert.NotBefore, NotAfter: time.Now().Add(kubeadmconstants.CertificateValidity).UTC(),
vim ./cmd/kubeadm/app/constants/constants.go const ( // KubernetesDir is the directory Kubernetes owns for storing various configuration files KubernetesDir = "/etc/kubernetes" // ManifestsSubDirName defines directory name to store manifests ManifestsSubDirName = "manifests" // TempDirForKubeadm defines temporary directory for kubeadm // should be joined with KubernetesDir. TempDirForKubeadm = "tmp"
// CertificateValidity defines the validity for all the signed certificates generated by kubeadm CertificateValidity = time.Hour * 24 * 365 * 10
// CACertAndKeyBaseName defines certificate authority base name CACertAndKeyBaseName = "ca" // CACertName defines certificate name CACertName = "ca.crt" // CAKeyName defines certificate name CAKeyName = "ca.key"
// APIServerCertAndKeyBaseName defines API's server certificate and key base name APIServerCertAndKeyBaseName = "apiserver" // APIServerCertName defines API's server certificate name APIServerCertName = "apiserver.crt" // APIServerKeyName defines API's server key name APIServerKeyName = "apiserver.key" // APIServerCertCommonName defines API's server certificate common name (CN) APIServerCertCommonName = "kube-apiserver"
// APIServerKubeletClientCertAndKeyBaseName defines kubelet client certificate and key base name APIServerKubeletClientCertAndKeyBaseName = "apiserver-kubelet-client" // APIServerKubeletClientCertName defines kubelet client certificate name APIServerKubeletClientCertName = "apiserver-kubelet-client.crt" // APIServerKubeletClientKeyName defines kubelet client key name APIServerKubeletClientKeyName = "apiserver-kubelet-client.key" // APIServerKubeletClientCertCommonName defines kubelet client certificate common name (CN) APIServerKubeletClientCertCommonName = "kube-apiserver-kubelet-client"
// EtcdCACertAndKeyBaseName defines etcd's CA certificate and key base name EtcdCACertAndKeyBaseName = "etcd/ca" // EtcdCACertName defines etcd's CA certificate name EtcdCACertName = "etcd/ca.crt" // EtcdCAKeyName defines etcd's CA key name EtcdCAKeyName = "etcd/ca.key" // EtcdServerCertAndKeyBaseName defines etcd's server certificate and key base name EtcdServerCertAndKeyBaseName = "etcd/server" // EtcdServerCertName defines etcd's server certificate name EtcdServerCertName = "etcd/server.crt" // EtcdServerKeyName defines etcd's server key name EtcdServerKeyName = "etcd/server.key"
# 编译kubeadm, 这里主要编译kubeadm 即可 make WHAT=cmd/kubeadm GOFLAGS=-v
[check-expiration] FYI: You can look at this config file with 'kubectl -n kube-system get cm kubeadm-config -oyaml'
CERTIFICATE EXPIRES RESIDUAL TIME CERTIFICATE AUTHORITY EXTERNALLY MANAGED admin.conf Dec 12, 2021 09:17 UTC 364d no apiserver Dec 12, 2021 09:17 UTC 364d ca no apiserver-etcd-client Dec 12, 2021 09:17 UTC 364d etcd-ca no apiserver-kubelet-client Dec 12, 2021 09:17 UTC 364d ca no controller-manager.conf Dec 12, 2021 09:17 UTC 364d no etcd-healthcheck-client Dec 12, 2021 09:17 UTC 364d etcd-ca no etcd-peer Dec 12, 2021 09:17 UTC 364d etcd-ca no etcd-server Dec 12, 2021 09:17 UTC 364d etcd-ca no front-proxy-client Dec 12, 2021 09:17 UTC 364d front-proxy-ca no scheduler.conf Dec 12, 2021 09:17 UTC 364d no
CERTIFICATE AUTHORITY EXPIRES RESIDUAL TIME EXTERNALLY MANAGED ca Nov 03, 2030 08:47 UTC 9y no etcd-ca Nov 03, 2030 08:47 UTC 9y no front-proxy-ca Nov 03, 2030 08:47 UTC 9y no
kubeadm alpha certs renew all --config=/root/kubeadm-config.yaml weiyigeek@master:~/.k8s$ sudo kubeadm alpha certs renew all --config=kubeadm-init-config.yaml W1213 13:42:52.803441 2059631 configset.go:348] WARNING: kubeadm cannot validate component configs for API groups [kubelet.config.k8s.io kubeproxy.config.k8s.io] 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 weiyigeek@master:~/.k8s$ sudo kubeadm alpha certs check-expiration [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 -oyaml'
CERTIFICATE EXPIRES RESIDUAL TIME CERTIFICATE AUTHORITY EXTERNALLY MANAGED admin.conf Dec 11, 2030 05:42 UTC 9y no apiserver Dec 11, 2030 05:42 UTC 9y ca no apiserver-etcd-client Dec 11, 2030 05:42 UTC 9y etcd-ca no apiserver-kubelet-client Dec 11, 2030 05:42 UTC 9y ca no controller-manager.conf Dec 11, 2030 05:42 UTC 9y no etcd-healthcheck-client Dec 11, 2030 05:42 UTC 9y etcd-ca no etcd-peer Dec 11, 2030 05:42 UTC 9y etcd-ca no etcd-server Dec 11, 2030 05:42 UTC 9y etcd-ca no front-proxy-client Dec 11, 2030 05:42 UTC 9y front-proxy-ca no scheduler.conf Dec 11, 2030 05:42 UTC 9y no
openssl x509 -in apiserver.crt -text -noout | grep Not
⒎HA集群其余 mater节点证书更新 #!/bin/bash masterNode="192.168.66.20 192.168.66.21" #for host in ${masterNode}; do # scp /etc/kubernetes/pki/{ca.crt,ca.key,sa.key,sa.pub,front-proxy-ca.crt,front-proxy-ca.key} # "${USER}"@$host:/etc/kubernetes/pki/ # scp /etc/kubernetes/pki/etcd/{ca.crt,ca.key} "root"@$host:/etc/kubernetes/pki/etcd # scp /etc/kubernetes/admin.conf "root"@$host:/etc/kubernetes/ #done for host in${CONTROL_PLANE_IPS}; do scp /etc/kubernetes/pki/{ca.crt,ca.key,sa.key,sa.pub,front-proxy-ca.crt,front-proxy-ca.key} "${USER}"@$host:/root/pki/ scp /etc/kubernetes/pki/etcd/{ca.crt,ca.key} "root"@$host:/root/etcd scp /etc/kubernetes/admin.conf "root"@$host:/root/kubernetes/ done
入坑出坑
问题 : Unable to connect to the server: x509: certificate has expired or is not yet valid 故障描述: 使用kubeadm部署的集群,在运行了一年之后今天,出现k8s api无法调取的现象,使用kubectl命令获取资源均返回如下报错
1
Unable to connect to the server: x509: certificate has expired or is not yet valid
方式1.请访问本博主的B站【WeiyiGeek】首页关注UP主, 将自动随机获取解锁验证码。
Method 2.Please visit 【My Twitter】. There is an article verification code in the homepage.
方式3.扫一扫下方二维码,关注本站官方公众号
回复:验证码
将获取解锁(有效期7天)本站所有技术文章哟!