免責事項:これは英文の記事「TKGm Certificate Rotation - Control Plane Nodes」の日本語訳です。記事はベストエフォートで翻訳を進めているため、ローカライズ化コンテンツは最新情報ではない可能性があります。最新情報は英語版の記事で参照してください。
概要
TKGm の Kubernetes クラスタが1年以内にアップグレードされない場合、クラスタ内で使用される証明書が期限切れになります。
この KB では Control Plane ノード上の Kubernetes に関する証明書を手動で更新する方法を説明します。
KB対象外
事象
Kubernetes クラスタの証明書が既に期限切れの場合、 kubectl は下記のメッセージを出力します。
kubectl get nodes
#> Unable to connect to the server: x509: certificate has expired or is not yet valid
全ての Control Plane ノードに SSH でログインして証明書の期限を確認できます。
# Log in to all 3 CP nodes, one by one.
ssh capv@${KCP_IPADDR}
sudo -i
kubeadm certs check-expiration
#> CERTIFICATE EXPIRES RESIDUAL TIME CERTIFICATE AUTHORITY
#> admin.conf Jan 09, 2025 05:03 UTC 364d ca
#> apiserver Jan 09, 2025 05:03 UTC 364d ca
#> apiserver-etcd-client Jan 09, 2025 05:03 UTC 364d etcd-ca
#> apiserver-kubelet-client Jan 09, 2025 05:03 UTC 364d ca
#> controller-manager.conf Jan 09, 2025 05:03 UTC 364d ca
#> etcd-healthcheck-client Jan 09, 2025 05:03 UTC 364d etcd-ca
#> etcd-peer Jan 09, 2025 05:03 UTC 364d etcd-ca
#> etcd-server Jan 09, 2025 05:03 UTC 364d etcd-ca
#> front-proxy-client Jan 09, 2025 05:03 UTC 364d front-proxy-ca
#> scheduler.conf Jan 09, 2025 05:03 UTC 364d ca
#>
#> CERTIFICATE AUTHORITY EXPIRES RESIDUAL TIME
#> ca Jan 07, 2034 05:02 UTC 9y
#> etcd-ca Jan 07, 2034 05:02 UTC 9y
#> front-proxy-ca Jan 07, 2034 05:02 UTC 9y
1. 対象K8s クラスタのコンテキストに切り替え
tanzu cluster list -A --include-management-cluster
kubectl config get-contexts
kubectl config use-context <TARGET_CONTEXT>
2. Control Plane ノードの一つに SSH でログイン
# Check the CP node IP address
kubectl get nodes -owide
KCP=192.168.x.x
ssh capv@${KCP}
sudo -i
# Check the current cert status
kubeadm certs check-expiration
3. 証明書を更新
kubeadm certs renew all
# Restart the pods
crictl stop $(crictl ps --name kube-apiserver -q)
crictl stop $(crictl ps --name kube-controller-manager -q)
crictl stop $(crictl ps --name kube-scheduler -q)
crictl stop $(crictl ps --name etcd -q)
crictl stop $(crictl ps --name kube-vip -q) # optional when using kube-vip
# Check
kubeadm certs check-expiration
4. 全ての Control Plane ノードに対して同じ手順を適用します
5. 全ての Control Plane ノードの k8s 証明書を更新後に、Tanzu CLI と kubectl の証明書を更新する必要があります