<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[k8s集群证书过期1.19.7]]></title><description><![CDATA[<p dir="auto"><a href="https://www.cnblogs.com/hukey/p/16600243.html" rel="nofollow ugc">https://www.cnblogs.com/hukey/p/16600243.html</a></p>
]]></description><link>http://an.forum.genostack.com/topic/999/k8s集群证书过期1-19-7</link><generator>RSS for Node</generator><lastBuildDate>Sat, 13 Jun 2026 09:38:00 GMT</lastBuildDate><atom:link href="http://an.forum.genostack.com/topic/999.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 22 Nov 2023 10:08:05 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to k8s集群证书过期1.19.7 on Thu, 23 Nov 2023 02:20:03 GMT]]></title><description><![CDATA[<p dir="auto"><a href="/assets/uploads/files/1700705985504-kubeadm">kubeadm</a> 证书时间100年</p>
]]></description><link>http://an.forum.genostack.com/post/2359</link><guid isPermaLink="true">http://an.forum.genostack.com/post/2359</guid><dc:creator><![CDATA[zhanglu]]></dc:creator><pubDate>Thu, 23 Nov 2023 02:20:03 GMT</pubDate></item><item><title><![CDATA[Reply to k8s集群证书过期1.19.7 on Thu, 23 Nov 2023 02:09:42 GMT]]></title><description><![CDATA[<p dir="auto">k8s集群证书过期两种处理方式</p>
<ol>
<li>
<p dir="auto">是一年续期</p>
</li>
<li>
<p dir="auto">更改一个超长时间：最长100年：源码编译kubeadm</p>
</li>
<li>
<p dir="auto">获取源码</p>
</li>
</ol>
<pre><code>wget https://github.com/kubernetes/kubernetes/archive/v1.19.7.tar.gz
tar -zxvf v1.19.7.tar.gz
mv kubernetes-1.19.7 kubernetes
cd kubernetes
</code></pre>
<ol start="2">
<li>修改CA为100年</li>
</ol>
<pre><code>vim ./staging/src/k8s.io/client-go/util/cert/cert.go

func NewSelfSignedCACert(cfg Config, key crypto.Signer) (*x509.Certificate, error) {
    now := time.Now()
    tmpl := x509.Certificate{
        SerialNumber: new(big.Int).SetInt64(0),
        Subject: pkix.Name{
            CommonName:   cfg.CommonName,
            Organization: cfg.Organization,
        },
        NotBefore:             now.UTC(),
        NotAfter:              now.Add(duration365d * 100).UTC(),  # 这里10修改为100
</code></pre>
<pre><code>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 * 100	# 这里乘以 100 年



</code></pre>
<ol start="3">
<li>
<p dir="auto">本地编译<br />
apt  install -y gcc make jq rsync</p>
</li>
<li>
<p dir="auto">安装go环境<br />
cat ./build/build-image/cross/VERSION<br />
v1.15.5-1<br />
下载go，上传到 master节点<br />
wget <a href="https://dl.google.com/go/go1.15.1.linux-amd64.tar.gz" rel="nofollow ugc">https://dl.google.com/go/go1.15.1.linux-amd64.tar.gz</a></p>
</li>
</ol>
<p dir="auto">tar xf go1.15.Linux-amd64.tar.gz -C /usr/local/</p>
<pre><code># 编辑/etc/profile文件添加如下：
vim /etc/profile

export GOROOT=/usr/local/go
export GOPATH=/usr/local/gopath
export PATH=$PATH:$GOROOT/bin


source /etc/profile
</code></pre>
<ol start="5">
<li>编译kubeadm</li>
</ol>
<pre><code># 编译kubeadm, 这里主要编译kubeadm 即可
make all WHAT=cmd/kubeadm GOFLAGS=-v

# 编译kubelet
# make all WHAT=cmd/kubelet GOFLAGS=-v

# 编译kubectl
# make all WHAT=cmd/kubectl GOFLAGS=-v

#编译完产物在 _output/bin/kubeadm 目录下，
#其中bin是使用了软连接
#真实路径是_output/local/bin/Linux/amd64/kubeadm
mv /usr/bin/kubeadm /usr/bin/kubeadm_backup
cp _output/local/bin/Linux/amd64/kubeadm /usr/bin/kubeadm
chmod +x /usr/bin/kubeadm
</code></pre>
<ol start="6">
<li>更新证书</li>
</ol>
<p dir="auto">查看证书到期时间：</p>
<blockquote>
<p dir="auto">kubeadm alpha certs check-expiration<br />
续订全部证书：<br />
kubeadm alpha certs renew all</p>
</blockquote>
<p dir="auto">kubeadm alpha certs check-expiration</p>
<pre><code>[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                 Jul 25, 2121 10:00 UTC   99y                                     no      
apiserver                  Jul 25, 2121 10:00 UTC   99y             ca                      no      
apiserver-etcd-client      Jul 25, 2121 10:00 UTC   99y             etcd-ca                 no      
apiserver-kubelet-client   Jul 25, 2121 10:00 UTC   99y             ca                      no      
controller-manager.conf    Jul 25, 2121 10:00 UTC   99y                                     no      
etcd-healthcheck-client    Jul 25, 2121 10:00 UTC   99y             etcd-ca                 no      
etcd-peer                  Jul 25, 2121 10:00 UTC   99y             etcd-ca                 no      
etcd-server                Jul 25, 2121 10:00 UTC   99y             etcd-ca                 no      
front-proxy-client         Jul 25, 2121 10:00 UTC   99y             front-proxy-ca          no      
scheduler.conf             Jul 25, 2121 10:00 UTC   99y                                     no      

CERTIFICATE AUTHORITY   EXPIRES                  RESIDUAL TIME   EXTERNALLY MANAGED
ca                      Jul 25, 2121 10:00 UTC   99y             no      
etcd-ca                 Jul 25, 2121 10:00 UTC   99y             no      
front-proxy-ca          Jul 25, 2121 10:00 UTC   99y             no
</code></pre>
<p dir="auto">如果集群证书已经过期，在上面的基础继续如下步骤：</p>
<pre><code>docker restart `docker ps | grep etcd | awk '{print $1}'`
docker restart `docker ps | grep kube-apiserver | awk '{print $1}'`
docker restart `docker ps | grep kube-controller | awk '{print $1}'`
docker restart `docker ps | grep kube-scheduler | awk '{print $1}'`
</code></pre>
<p dir="auto">更新 kubeconfig 文件</p>
<pre><code>root@k8s-master(10.0.0.11)~&gt;kubeadm init phase kubeconfig all 

I0818 15:48:50.617013    3929 version.go:252] remote version is much newer: v1.24.4; falling back to: stable-1.19
W0818 15:48:52.891141    3929 configset.go:348] WARNING: kubeadm cannot validate component configs for API groups [kubelet.config.k8s.io kubeproxy.config.k8s.io]
[kubeconfig] Using kubeconfig folder "/etc/kubernetes"
[kubeconfig] Using existing kubeconfig file: "/etc/kubernetes/admin.conf"
[kubeconfig] Using existing kubeconfig file: "/etc/kubernetes/kubelet.conf"
[kubeconfig] Using existing kubeconfig file: "/etc/kubernetes/controller-manager.conf"
[kubeconfig] Using existing kubeconfig file: "/etc/kubernetes/scheduler.conf"
</code></pre>
<p dir="auto">覆盖原admin文件</p>
<pre><code>mv $HOME/.kube/config $HOME/.kube/config.old
cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
chown $(id -u):$(id -g) $HOME/.kube/config
</code></pre>
]]></description><link>http://an.forum.genostack.com/post/2358</link><guid isPermaLink="true">http://an.forum.genostack.com/post/2358</guid><dc:creator><![CDATA[zhanglu]]></dc:creator><pubDate>Thu, 23 Nov 2023 02:09:42 GMT</pubDate></item></channel></rss>