Task weight: 2%

Use context: kubectl config use-context k8s-c2-AC

Check how long the kube-apiserver server certificate is valid on cluster2-controlplane1 . Do this with openssl or cfssl. Write the exipiration date into /opt/course/22/expiration .

Also run the correct kubeadm command to list the expiration dates and confirm both methods show the same date.

Write the correct kubeadm command that would renew the apiserver server certificate into /opt/course/22/kubeadm-renew-certs.sh .


译文

cluster2-controlplane1 上检查 kube-apiserver 服务器证书的有效期。 使用 openssl 或 cfssl 执行此操作。 将过期日期写入 /opt/course/22/expiration 中。

同时运行正确的 kubeadm 命令列出过期日期,并确认两种方法显示的日期相同。

将 更新apiserver服务器证书 正确 kubeadm命令 写入 /opt/course/22/kubeadm-renew-certs.sh 中。


解答
kubectl config use-context k8s-c2-AC

连接到controlplane1,并检查证书过期时间

ssh cluster2-controlplane1

root@cluster2-controlplane1:~# find /etc/kubernetes/pki | grep apiserver
root@cluster2-controlplane1:~# openssl x509 -noout -text -in /etc/kubernetes/pki/apiserver.crt | grep Validity -A2

check-cert-0

使用kubeadm 来获取过期时间

root@cluster2-controlplane1:~# kubeadm certs check-expiration | grep apiserver

check-cert-1

写过期时间到文件

echo "Jan 10 05:00:49 2024 GMT" > /opt/course/22/expiration

更新证书

echo "kubeadm certs renew apiserver" > /opt/course/22/kubeadm-renew-certs.sh