Error from server (Forbidden): pods is forbidden: User cannot list resource "pods" in API group at the cluster scope

9.1k Views Asked by At

My private AKS Cluster is accessible only to the root user using kubectl on a jumphost. But for a non-root user it throws below error message:

someuser@jump-vm$ kubectl get pods -A
Error from server (Forbidden): pods is forbidden: User "XX-XX-XX-XX-XX" cannot list resource "XX" in API group " " at the cluster scope

How to resolve this error?

2

There are 2 best solutions below

0
4c74356b41 On BEST ANSWER

in this case solution was to delete the old config from $HOME/.kube/ and re-initialize it after az login with the user in question

0
RSW On

It seems the Azure VM from the private AKS cluster was being accessed was set to automatic restart which caused some issue with kubectl or kubelogin.

I followed below steps for both -- root as well as non-root user and after kubectl worked successfully.

root@jump-vm# cd ~ && cd .kube/
root@jump-vm# rm -r cache && rm config 
root@jump-vm# az login --tenant <tenant-id>
root@jump-vm# az account set --subscription <subscription-id>
root@jump-vm# az aks get-credentials --resource-group <resource-group-name> --name <aks-clutser-name>
root@jump-vm# kubelogin convert-kubeconfig -l azurecli

someuser@jump-vm$ cd ~ && cd .kube/
someuser@jump-vm$ rm -r cache && rm config 
someuser@jump-vm$ az login --tenant <tenant-id>
someuser@jump-vm$ az account set --subscription <subscription-id>
someuser@jump-vm$ az aks get-credentials --resource-group <resource-group-name> --name <aks-clutser-name>
someuser@jump-vm$ kubelogin convert-kubeconfig -l azurecli