Skip to content

03 · Your own node IAM role

Goal: an IAM role that you created and named, which our nodes will use; the EKS access entry that lets nodes with that role join the cluster; and the one extra permission Auto Mode needs to put your tags on instances.

Why: "your IAM role, not a generated one" is one of the first compliance requirements that pushes teams off the built-ins. A role you own has a name you chose, tags you chose, and a lifecycle you control.

1. Create the role

Nodes are EC2 instances, so the role trusts the EC2 service:

aws iam create-role \
  --role-name "$NODE_ROLE_NAME" \
  --assume-role-policy-document '{
    "Version": "2012-10-17",
    "Statement": [{
      "Effect": "Allow",
      "Principal": { "Service": "ec2.amazonaws.com" },
      "Action": "sts:AssumeRole"
    }]
  }' \
  --tags Key=Talk,Value=mastering-custom-node-pools \
  --query Role.Arn --output text

Expected output is the role ARN:

arn:aws:iam::111122223333:role/auto-mode-nodepools-demo-node

Keep it in a variable; the next commands need it:

export NODE_ROLE_ARN=$(aws iam get-role --role-name "$NODE_ROLE_NAME" --query Role.Arn --output text)
echo "$NODE_ROLE_ARN"

2. Attach the node policies

The two policies AWS requires for an Auto Mode node role:

aws iam attach-role-policy --role-name "$NODE_ROLE_NAME" \
  --policy-arn arn:aws:iam::aws:policy/AmazonEKSWorkerNodeMinimalPolicy

aws iam attach-role-policy --role-name "$NODE_ROLE_NAME" \
  --policy-arn arn:aws:iam::aws:policy/AmazonEC2ContainerRegistryPullOnly

Plus one AWS recommends when you pull from public ECR, which every image in this guide does. Without it, pulls are unauthenticated and can be throttled:

aws iam attach-role-policy --role-name "$NODE_ROLE_NAME" \
  --policy-arn arn:aws:iam::aws:policy/AmazonElasticContainerRegistryPublicReadOnly

These commands print nothing on success. Verify:

aws iam list-attached-role-policies --role-name "$NODE_ROLE_NAME" \
  --query 'AttachedPolicies[].PolicyName' --output table

Other partitions

The policy ARNs above use the aws partition. In AWS China use aws-cn, in GovCloud aws-us-gov.

3. Let the role join the cluster

An IAM role alone doesn't get a node into the cluster. EKS needs an access entry of type EC2 for the role. EKS creates one automatically for the role the built-in pools use, but not for a role you bring yourself.

aws eks create-access-entry \
  --cluster-name "$CLUSTER_NAME" \
  --principal-arn "$NODE_ROLE_ARN" \
  --type EC2 \
  --query 'accessEntry.{type: type, principal: principalArn}'

Then associate the Auto Mode node access policy with it:

aws eks associate-access-policy \
  --cluster-name "$CLUSTER_NAME" \
  --principal-arn "$NODE_ROLE_ARN" \
  --policy-arn arn:aws:eks::aws:cluster-access-policy/AmazonEKSAutoNodePolicy \
  --access-scope type=cluster \
  --query 'associatedAccessPolicy.policyArn'

Verify

aws eks list-associated-access-policies \
  --cluster-name "$CLUSTER_NAME" \
  --principal-arn "$NODE_ROLE_ARN" \
  --query 'associatedAccessPolicies[].policyArn'
[
    "arn:aws:eks::aws:cluster-access-policy/AmazonEKSAutoNodePolicy"
]

If this step is missing, the NodeClass in step 04 never becomes Ready.

4. Let Auto Mode apply your tags

Step 04 stamps mandatory tags (CostCentre, Owner, …) on every instance. That's the compliance requirement that sends many teams to a custom NodeClass in the first place, and it needs one more permission, on a different role.

Auto Mode launches instances using the cluster IAM role (the one eksctl created for the control plane), not the node role. By default, AWS's managed Auto Mode policies don't allow user-defined tags on the resources Auto Mode creates. Without an extra policy, a NodeClass with tags never becomes Ready:

ValidationSucceeded=False  CreateLaunchTemplateAuthCheckFailed:
Controller isn't authorized to call ec2:CreateLaunchTemplate

Find the cluster role eksctl created:

export CLUSTER_ROLE_NAME=$(aws eks describe-cluster --name "$CLUSTER_NAME" \
  --query cluster.roleArn --output text | cut -d/ -f2-)
echo "$CLUSTER_ROLE_NAME"

Add the compute statement from AWS's custom tag policy example as an inline policy. It still only allows launches tagged for this cluster (the eks:eks-cluster-name condition); it just stops rejecting extra tags:

aws iam put-role-policy \
  --role-name "$CLUSTER_ROLE_NAME" \
  --policy-name AutoModeCustomNodeTags \
  --policy-document '{
    "Version": "2012-10-17",
    "Statement": [{
      "Sid": "Compute",
      "Effect": "Allow",
      "Action": ["ec2:CreateFleet", "ec2:RunInstances", "ec2:CreateLaunchTemplate"],
      "Resource": "*",
      "Condition": {
        "StringEquals": {
          "aws:RequestTag/eks:eks-cluster-name": "${aws:PrincipalTag/eks:eks-cluster-name}"
        },
        "StringLike": {
          "aws:RequestTag/eks:kubernetes-node-class-name": "*",
          "aws:RequestTag/eks:kubernetes-node-pool-name": "*"
        }
      }
    }]
  }'

The single quotes matter: ${aws:PrincipalTag/...} is an IAM policy variable, not a shell variable, and must reach IAM unexpanded. Verify:

aws iam list-role-policies --role-name "$CLUSTER_ROLE_NAME" --output text
POLICYNAMES AutoModeCustomNodeTags

Remember to remove it

This policy sits on a role that eksctl's CloudFormation stack owns. Cleanup deletes it before deleting the cluster; if you forget, the stack can't delete the role.

The shortcut (not used here)

You could skip this page and point the NodeClass at the role eksctl created for the built-in pools (computeConfig.nodeRoleArn from step 01), which already has an access entry. It works, but the role is then shared with the built-ins, named by eksctl, and deleted with the cluster stack. That's exactly what a compliance requirement usually rules out.

Next: 04 The NodeClass.