1 创建一个 IAM policy

#curl -O https://raw.githubusercontent.com/kubernetes-sigs/aws-load-balancer-controller/v2.4.4/docs/install/iam_policy.json
 
#aws iam create-policy \
    --policy-name AWSLoadBalancerControllerIAMPolicy \
    --policy-document file://iam_policy.json


2 创建一个 IAM 角色

my-cluster : 需要更改为真实的EKS集群名称

111122223333: 代表AWS ID帐号,也需要更改111122223333

# eksctl utils associate-iam-oidc-provider --region=ap-southeast-1 --cluster=my-cluster
 
# eksctl create iamserviceaccount \
  --cluster=my-cluster \
  --namespace=kube-system \
  --name=aws-load-balancer-controller \
  --role-name AmazonEKSLoadBalancerControllerRole \
  --attach-policy-arn=arn:aws:iam::111122223333:policy/AWSLoadBalancerControllerIAMPolicy \
  --approve


3 使用Helm v3安装AWS Load Balancer Controller

1)添加 eks-charts 存储库

#helm repo add eks https://aws.github.io/eks-charts

2)更新您的本地存储库,以确保您拥有最新的图表

#helm repo update
#helm install aws-load-balancer-controller eks/aws-load-balancer-controller \
  -n kube-system \
  --set clusterName=my-cluster \
  --set serviceAccount.create=false \
  --set serviceAccount.name=aws-load-balancer-controller 

4 验证控制器是否已安装

#kubectl get deployment -n kube-system aws-load-balancer-controller

输出示例如下:

NAME                           READY   UP-TO-DATE   AVAILABLE   AGE
aws-load-balancer-controller   2/2     2            2           84s


5 常见问题解决

删除命令:helm delete -n kube-system aws-load-balancer-controller

报错:

2023-05-24 03:22:03 [ℹ]  1 existing iamserviceaccount(s) (kube-system/aws-load-balancer-controller) will be excluded
2023-05-24 03:22:03 [ℹ]  1 iamserviceaccount (kube-system/aws-load-balancer-controller) was excluded (based on the include/exclude rules)
2023-05-24 03:22:03 [!]  serviceaccounts that exist in Kubernetes will be excluded, use --override-existing-serviceaccounts to override
2023-05-24 03:22:03 [ℹ]  no tasks
解决办法:

修改以下名称保证唯一性,不建议共用。(可能帐号下有重复的名称导致)

--name=aws-load-balancer-controller

--role-name AmazonEKSLoadBalancerControllerRole

03-16 05:48