Amazon Web Services (AWS) - Resolve kubectl error "You must be logged in to the server"

by
Jeremy Canfield |
Updated: October 23 2023
| Amazon Web Services (AWS) articles
Let's say kubectl CLI is returning something like this.
~]$ kubectl version
error: You must be logged in to the server (the server has asked for the client to provide credentials)
The aws eks list-clusters command can be used to list your Elastic Kubernetes Service (EKS).
~]$ aws eks list-clusters
{
"clusters": [
"my-cluster"
]
}
And then the aws eks update-kubeconfig command can be used to create or update your hidden .kube/config file.
~]$ aws eks update-kubeconfig --name my-cluster
Added new context arn:aws:eks:us-east-1:123456789012:cluster/my-cluster to /home/john.doe/.kube/config
And then your /home/your_username/.kube/confilg file should contain something like this.
- name: arn:aws:eks:us-east-1:123456789012:cluster/my-cluster
user:
exec:
apiVersion: client.authentication.k8s.io/v1alpha1
args:
- --region
- us-east-1
- eks
- get-token
- --cluster-name
- my-cluster
command: aws
env:
- name: AWS_PROFILE
value: default
If you have access to the Elastic Kubernetes Service (EKS) Cluster, there may be a misconfiguration with the aws-auth config map. The aws-auth config map should have something like this. For example, one possible issue is if there is a subpath such as /eks in the rolearn.
- groups:
- system:bootstrappers
- system:nodes
rolearn: arn:aws:iam::123456789012:role/eks/my-node
username: system:node:{{EC2PrivateDNSName}}
Did you find this article helpful?
If so, consider buying me a coffee over at