First, we will have to set up an OIDC provider with the cluster and create the IAM policy to be used by the ALB Ingress Controller. This step is required to give IAM permissions to a Fargate pod running in the cluster using the IAM for Service Accounts feature.
eksctl utils associate-iam-oidc-provider \
--cluster eksworkshop-eksctl \
--region=$AWS_REGION \
--approve
The next step is to create the IAM policy that will be used by the ALB Ingress Controller deployment. This policy will be later associated to the Kubernetes Service Account and will allow the ALB Ingress Controller pods to create and manage the ALB’s resources in your AWS account for you.
aws iam create-policy \
--policy-name ALBIngressControllerIAMPolicy \
--policy-document https://raw.githubusercontent.com/kubernetes-sigs/aws-alb-ingress-controller/${ALB_INGRESS_VERSION}/docs/examples/iam-policy.json
You will see the policy information output as shown below. Note down the ARN of the policy that you just created.
Output:
We need the policy’s Amazon Resource Name (ARN) to create the Service Account with the proper permissions.
export FARGATE_POLICY_ARN=$(aws iam list-policies --query 'Policies[?PolicyName==`ALBIngressControllerIAMPolicy`].Arn' --output text)
Next, create a Kubernetes Service Account by executing the following command
eksctl create iamserviceaccount \
--name alb-ingress-controller \
--namespace 2048-game \
--cluster eksworkshop-eksctl \
--attach-policy-arn ${FARGATE_POLICY_ARN} \
--approve \
--override-existing-serviceaccounts
The above command deploys a CloudFormation template that creates an IAM role and attaches the IAM policy to it. The IAM role gets associated with a Kubernetes Service Account. You can see details of the service account created with the following command.
For more information on IAM Roles for Service Accounts follow this link.
kubectl get sa alb-ingress-controller -n 2048-game -o yaml
Output:
Next, you will have to create a Cluster Role and Cluster Role Binding that grant requisite permissions to the Service Account you just created.
curl -sS https://raw.githubusercontent.com/kubernetes-sigs/aws-alb-ingress-controller/${ALB_INGRESS_VERSION}/docs/examples/rbac-role.yaml \
| sed 's/namespace: kube-system/namespace: 2048-game/g' \
| kubectl apply -f -