Tuesday, June 22, 2021

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

 The reason why you would receive following error when you try to access an EKS cluster is that the user who created the EKS cluster is different what you are using to run kubectl commands:

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


In order to resolve this, either use aws-iam-authenticator or use the same user to run your kubectl commands with which you created the cluster. I  normally like to work with the kubeconfig file present so I use the same user for both creating EKS cluster and running kubectl commands. I also set my config and credentials in AWS as follows:


AWS .config file entry:

[profile eks-np]

region = ap-southeast-2

output = json


AWS credentials file entry:

[eks-np]

aws_access_key_id = <key id>

aws_secret_access_key = <access key>

region = ap-southeast-2


and then run following command to update your .kube file with cluster and context info:

aws eks --region ap-southeast-2 update-kubeconfig --name ekscluster --profile eks-np


I hope that helps.

No comments: