Introduction#
Github shows essential components of an Amazon EKS cluster
- Kubernetes Role and RoleBinding
- Configmap aws-auth
- Kube config file
How It Work#
- Role means permissions, capabilities, which actions allowed on which resources
- RoleBinding means who, user, group mapped to a role
- ClusterRole, ClusterRoleBinding are applied to all namespace
- User kubectl => Kubernetes API => IAM ID => Configmap aws-auth => RoleBinding
Setup K8S Access for an IAM Role#
Kubernetes Role to setup permissions or what actions are allowed
apiVersion: rbac.authorization.k8s.io/v1kind: Rolemetadata:creationTimestamp: nullnamespace: defaultname: dev-rolerules:- apiGroups: [""]resources: ["pods", "services"]verbs: ["get", "list", "patch", "update", "watch"]
Kubernetes RoleBinding to bind an identity (group or user) with the Role
apiVersion: rbac.authorization.k8s.io/v1kind: RoleBindingmetadata:creationTimestamp: nullname: dev-role-bindingnamespace: defaultsubjects:- kind: Username: developerapiGroup: rbac.authorization.k8s.ioroleRef:kind: Rolename: dev-roleapiGroup: rbac.authorization.k8s.io
Update the aws-auth configmap
kubectl edit -n kube-system configmap/aws-auth
An example of the aws-auth, mapping role to user and groups
apiVersion: v1kind: ConfigMapmetadata:name: aws-authnamespace: kube-systemdata:mapRoles: |- rolearn: xxxusername: developer- rolearn: <ARN of instance role (not instance profile)>username: system:node:{{EC2PrivateDNSName}}groups:- system:bootstrappers- system:nodes
Using eksctl as recommended by aws docs
eksctl delete iamidentitymapping \--region=$Region \--cluster=$ClusterName \--arn=$Role \
Update the kube config
aws eks update-kubeconfig --name $ClusterName --role-arn $ROLE