Let pods act as an IAM role

Associate a Kubernetes service account with an IAM role, so its pods get short-lived credentials for the role and no access key is stored in the cluster.

Last updated 18 November 2026View as Markdown

Replace my-cluster with your cluster's name or id, shop with the namespace, api with the service account and shop-api with the IAM role's name.

Prerequisites

  • Permission for eks:CreatePodIdentityAssociation on the cluster, and iam:PassRole on the role. To remove an association, eks:DeletePodIdentityAssociation (the console enables Remove only with it on every cluster, eks:*).
  • In the console, also eks:DescribeCluster to open the cluster and eks:ListPodIdentityAssociations on it: without it the Pod identity tab shows neither the associations nor the form.
  • A cluster created after workload identity was introduced. On an older one the page says "This cluster was created before workload identity." and the create answers 409.

Associate the service account

  1. Open Kubernetes, open the cluster, then choose Pod identity.
  2. Under Associate a service account with a role, enter the namespace, the service account and the IAM role name.
  3. Choose Associate.

Result

Pods of that service account created from then on get a projected token for Deutsche Cloud STS and the variables AWS SDKs read: AWS_ROLE_ARN, AWS_WEB_IDENTITY_TOKEN_FILE, AWS_ENDPOINT_URL_STS, AWS_ENDPOINT_URL_S3 and AWS_REGION. An AWS SDK or the AWS CLI then reaches Deutsche Cloud S3 as the role with no code change. Pods already running keep what they had until they restart.

kubectl -n shop run s3 --rm -it --image=public.ecr.aws/aws-cli/aws-cli \
  --overrides='{"spec":{"serviceAccountName":"api"}}' -- s3 ls s3://my-bucket/

Remove an association

On the Pod identity tab, choose Remove on the row, then Delete in the dialog Remove shop/api, or run dcloud eks pod-identity-associations delete my-cluster association-id. Its pods get no new credentials; those already issued run out within the hour.

Refusals

  • 404 "No IAM role named "shop-api"".
  • 403 without iam:PassRole on the role.
  • 409 "shop/api already has a pod identity association on this cluster", "This cluster was created before workload identity; its service-account issuer is not published. Create a new cluster to use pod identity.", or the quota is full.
Did this page help you?