In this post, we will see How To Fix - Error: You must be logged in to the server (Unauthorized) in Kubernetes.
Error: You must be logged in to the server (Unauthorized) in Kubernetes
First thing first, do basic check to verify the IAM user..
aws sts get-caller-identity
kubectl edit -n kube-system configmap/aws-auth
Subsequently you will be granted an editor to map new users. Create role bound to the kubernetes cluster for the same user as in the ConfigMap. Do using below -
kubectl create clusterrolebinding ops-user-cluster-admin-binding --clusterrole=cluster-admin --user=user1
aws sts get-caller-identity
aws eks --region region-code update-kubeconfig --name cluster1
kubectl get svc
{
"Effect": "Allow",
"Action": "sts:AssumeRole",
"Resource": "arn:aws:iam::xxxxxxxxxxx:role/eks-role"
}
{
"Sid": "",
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam::xxxxxxxxxxx:user/user1"
},
"Action": "sts:AssumeRole"
$ aws sts get-caller-identity
aws eks --region region-code update-kubeconfig --name cluster_name --role-arn arn:aws:iam::xxxxxxxxxxx:user/eks-role
kubectl get svc
export AWS_ACCESS_KEY_ID="***************"
export AWS_SECRET_ACCESS_KEY="*************"
export AWS_SESSION_TOKEN="************************"
you must be logged in to the server (unauthorized) kubectl, aks error: you must be logged in to the server (unauthorized) kubectl get pods error: you must be logged in to the server (unauthorized), error you must be logged in to the server (unauthorized) codebuild, error: you must be logged in to the server (unauthorized) gke, aws-auth configmap, error you must be logged in to the server (unauthorized) openshift, error you must be logged in to the server (unauthorized),