0

I have a cluster with RBAC in AKS, and it works just fine, but sometimes (it seems after my laptop goes to sleep) I just get this error and have to create context again:

kubectl error: You must be logged in to the server (Unauthorized)

It does not seem to happen all the time. Sometimes many sleep cycles (few days) passes, sometimes just few hours. It seem totally random.

Would appreciate any help on figuring out why this is happening.

My set up is like that (I don't know if it is important though):

I usually work on Windows Subsystem for Linux 2, but I have the same version of kubectl on windows itself and the config files are the same between the two (I linked kubectl config from linux).

I am pretty sure though I did not use windows kubectl last time it happened, only linux version

Ilya Chernomordik
  • 27,817
  • 27
  • 121
  • 207
  • are you running on linux? – Sajeetharan Jan 12 '21 at 16:41
  • @Sajeetharan I am running on WSL2, so partially linux :) Have extended the question – Ilya Chernomordik Jan 12 '21 at 16:47
  • check if any of these helps https://github.com/Azure/AKS/issues/1761 – Sajeetharan Jan 12 '21 at 17:12
  • I have seen that already, but it does not seem that this is the case... I don't have to reauthenticate after each command and have same kubectl version – Ilya Chernomordik Jan 12 '21 at 17:19
  • 1
    I have a similar issue, though it consistently requires reauthentication after 1 hour, suggesting the problem is related to the refresh token. It's only occurring with clusters that have AKS managed AAD integration, this issue suggests upgrading az cli plus some other suggestions you might find helpful https://github.com/Azure/AKS/issues/1669 – Nick Graham Jan 12 '21 at 20:22
  • It looks like it is not resolved though, but people switched to using kubelogin... – Ilya Chernomordik Jan 13 '21 at 08:16

1 Answers1

2

I had the same issue with WSL2 and the reason is lack of time sync after laptop sleeping (see https://github.com/microsoft/WSL/issues/4245)

After running sudo hwclock -s I have no more error message and can run kubectl comand.

Mr R
  • 754
  • 7
  • 19