# How to Set up AWS Load Balancer Controller

Ref: https://kubernetes-sigs.github.io/aws-load-balancer-controller/v2.3/deploy/installation/#add-controller-to-cluster

## Setup IAM role for service accounts

First, let’s deploy an Amazon EKS cluster with eksctl. For this you can use, for example, Homebrew on macOS:

```
brew install weaveworks/tap/eksctl
```

1. Create IAM OIDC provider

```
eksctl utils associate-iam-oidc-provider \
    --region <region-code> \
    --cluster <your-cluster-name> \
    --approve
```

2. Download IAM policy for the AWS Load Balancer Controller

```
curl -o iam-policy.json https://raw.githubusercontent.com/kubernetes-sigs/aws-load-balancer-controller/v2.3.1/docs/install/iam_policy.json
```


3. Create an IAM policy called AWSLoadBalancerControllerIAMPolicy

```
aws iam create-policy \
    --policy-name AWSLoadBalancerControllerIAMPolicyForNA \
    --policy-document file://iam-policy.json
```

Take note of the policy ARN that is returned

```
{
    "Policy": {
        "PolicyName": "AWSLoadBalancerControllerIAMPolicyForNA",
        "PolicyId": "ANPA3VJFN74A7S6UTIQ4N",
        "Arn": "arn:aws:iam::801626783489:policy/AWSLoadBalancerControllerIAMPolicyForNA",
        "Path": "/",
        "DefaultVersionId": "v1",
        "AttachmentCount": 0,
        "PermissionsBoundaryUsageCount": 0,
        "IsAttachable": true,
        "CreateDate": "2022-01-08T15:53:17+00:00",
        "UpdateDate": "2022-01-08T15:53:17+00:00"
    }
}
```

4. Create a IAM role and ServiceAccount for the AWS Load Balancer controller, use the ARN from the step above

```
eksctl create iamserviceaccount \
--cluster=wordpress-cluster \
--namespace=kube-system \
--name=aws-load-balancer-controller \
--attach-policy-arn=arn:aws:iam::801626783489:policy/AWSLoadBalancerControllerIAMPolicyForNA \
--override-existing-serviceaccounts \
--region us-west-1 \
--approve
```


## Add Load Balancer Controller to Cluster

1. Add the EKS chart repo to helm
```
helm repo add eks https://aws.github.io/eks-charts
```

2. Install the TargetGroupBinding CRDs if upgrading the chart via helm upgrade.
```
kubectl apply -k "github.com/aws/eks-charts/stable/aws-load-balancer-controller//crds?ref=master"
```

3. Install the helm chart if using IAM roles for service accounts. NOTE you need to specify both of the chart values serviceAccount.create=false and serviceAccount.name=aws-load-balancer-controller
```
helm install aws-load-balancer-controller eks/aws-load-balancer-controller -n kube-system --set clusterName=wordpress-cluster --set serviceAccount.create=false --set serviceAccount.name=aws-load-balancer-controller
```

