You encounter a situation where,
1. On running any kubectl command on the supervisor cluster, it errors out with- "you must be logged in to the server (the server has asked for the client to provide credentials".
2. The kubelet service, kube-api server, etcd and all the other static containers are running.
3. The certificates on the supervisor cluster are all up to date.
4. The certificate inside the "client-certificate-data" of the admin.conf file is expired.
vSphere with Tanzu
During cluster creation, the file admin.conf is created by kubeadm on control plane nodes and it contains a certificate with Subject: O = kubeadm:cluster-admins, CN = kubernetes-admin. The same is renewed/replaced via kubeadm itself and is not renewed/replaced by the certmgr script used to replace other supervisor certificates.
To renew the admin.conf certificate, run the command- "kubeadm certs renew all". If run successfully, it explicitly outputs that the certificate embedded in the kubeconfig file is renewed. For example, see below
root@<supervisor-dns-name> [ /etc/kubernetes ]# kubeadm certs renew all
[renew] Reading configuration from the cluster...[renew] FYI: You can look at this config file with 'kubectl -n kube-system get cm kubeadm-config -o yaml'
certificate embedded in the kubeconfig file for the admin to use and for kubeadm itself renewedcertificate for serving the Kubernetes API renewedcertificate the apiserver uses to access etcd renewedcertificate for the API server to connect to kubelet renewedcertificate embedded in the kubeconfig file for the controller manager to use renewedcertificate for liveness probes to healthcheck etcd renewedcertificate for etcd nodes to communicate with each other renewedcertificate for serving etcd renewedcertificate for the front proxy client renewedkubeConfig file /etc/kubernetes/scheduler.conf does not have an embedded client certificateTo see the stack trace of this error execute with --v=5 or higher
Once completed also run through the knowledge article Unable to run kubectl commands in a Supervisor Cluster due to "error: You must be logged in to the server (Unauthorized)" to complete the restart of related pods/containers.
NOTE: As this does not renew all certificates in the system also run through knowledge article Replace vSphere with Tanzu Supervisor Certificates to make sure any other expired certificates are also updated.
Certificate Management with kubeadm: https://kubernetes.io/docs/tasks/administer-cluster/kubeadm/kubeadm-certs/