Reputation: 1545
The scenario is simple to reproduce:
kubectl top nodes
$ kubectl get configmap -n kube-system aws-auth -o yaml
apiVersion: v1
data:
mapRoles: |
- rolearn: arn:aws:iam::xxxxxxxxxxxx:role/EKS-Workers2-NodeInstanceRole-HWD4HSSO7NP1
username: system:node:{{EC2PrivateDNSName}}
groups:
- system:bootstrappers
- system:nodes
- rolearn: arn:aws:iam::xxxxxxxxxxxx:role/Admin
groups:
- system:masters
kind: ConfigMap
...
$ kubectl top nodes
Error from server (Forbidden): nodes.metrics.k8s.io is forbidden: User "system:anonymous" cannot list nodes.metrics.k8s.io at the cluster scope: no RBAC policy matched
Adititonal info:
$ kubectl version
Client Version: version.Info{Major:"1", Minor:"13", GitVersion:"v1.13.2", GitCommit:"cff46ab41ff0bb44d8584413b598ad8360ec1def", GitTreeState:"clean", BuildDate:"2019-01-10T23:35:51Z", GoVersion:"go1.11.4", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"12+", GitVersion:"v1.12.10-eks-2e569f", GitCommit:"2e569fd887357952e506846ed47fc30cc385409a", GitTreeState:"clean", BuildDate:"2019-07-25T23:13:33Z", GoVersion:"go1.10.8", Compiler:"gc", Platform:"linux/amd64"}
Upvotes: 0
Views: 1322
Reputation: 3791
As I mentioned in my comment, the solution is to add username regardless of whether you are using IAM roles or IAM users in AWS. Mapping must be specified in your configmap otherwise that username will never be created in the kubernetes cluster and so it won’t be mapped to any permissions.
So you are missing username part in your newly added block to mapRoles.
Docs are a bit old in places and it is always good to be explicit in configmaps. This is at least something I usually try to follow.
I am happy you managed to make it work. :)
Upvotes: 2