Got "Unauthorized" when accessing an authorized cluster endpoint

Rancher Server: v2.6.8
Kubernetes Cluster: RKE2
Version: v1.24.4+rke2r1

Hi there, I have created a RKE2 cluster via Rancher Server. I downloaded the kubeconfig file from Rancher UI, and I was trying to access the cluster with kubectl and kubeconfig. I was able to access the cluster via Rancher Server’s context. However, if I access that cluster directly using:

kubectl --kubeconfig /custom/path/kube.config --context <CLUSTER_NAME>-<NODE_NAME> get pods

as describe here: Access a Cluster with Kubectl and kubeconfig | Rancher Manager

I got an error “error: You must be logged in to the server (Unauthorized)”

Is there anyone know the reason why? And how to fix it?

Thanks!

Look like the user inside that kubeconfig does not have an access privilege to connect that cluster…

Hi @Sang_Nguyen , this doesn’t appear to be a cluster setup via Rancher Setup (as defined in the sticky post). I’ll move your post to the appropriate topic.