IAMポリシーの問題
このセクションでは、AWS Load Balancer ControllerがApplication Load Balancerを作成・管理するために必要なIAMアクセス許可がないという問題に対処します。IAMポリシー設定の問題を特定して修正する手順を説明します。
ステップ1:Service AccountのRoleを特定する
まず、Load Balancer Controllerが使用しているservice accountを調べます。ControllerはAWS APIを呼び出すためにIAM Roles for Service Accounts (IRSA)を使用しています:
~$kubectl get serviceaccounts -n kube-system -l app.kubernetes.io/name=aws-load-balancer-controller -o yaml
出力例:
~/environment/eks-workshop/modules/troubleshooting/alb/files/iam_issue_service_account_role.yaml
apiVersion: v1
items:
- apiVersion: v1
automountServiceAccountToken: true
kind: ServiceAccount
metadata:
annotations:
eks.amazonaws.com/role-arn: arn:aws:iam::xxxxxxxxxxxx:role/alb-controller-20240611131524228000000002
meta.helm.sh/release-name: aws-load-balancer-controller
meta.helm.sh/release-namespace: kube-system
creationTimestamp: "2024-06-11T13:15:32Z"
labels:
app.kubernetes.io/instance: aws-load-balancer-controller
app.kubernetes.io/managed-by: Helm
app.kubernetes.io/name: aws-load-balancer-controller
app.kubernetes.io/version: v2.7.1
helm.sh/chart: aws-load-balancer-controller-1.7.1
name: aws-load-balancer-controller-sa
namespace: kube-system
resourceVersion: "4950707"
uid: 6d842045-f2b4-4406-869b-f2addc67ff4d
kind: List
metadata:
resourceVersion: ""
A
eks.amazonaws.com/role-arn:このタグは、正しいアクセス許可が必要なIAM roleを参照しています。
ステップ2:Controllerのログを確認する
Load Balancer Controllerのログを調べて、アクセス許可の問題を理解しましょう:
~$kubectl logs -n kube-system -l app.kubernetes.io/name=aws-load-balancer-controller
次のようなエラーが表示されるかもしれません:
{"level":"error","ts":"2024-06-11T14:24:24Z","msg":"Reconciler error","controller":"ingress","object":{"name":"ui","namespace":"ui"},"namespace":"ui","name":"ui","reconcileID":"49d27bbb-96e5-43b4-b115-b7a07e757148","error":"AccessDenied: User: arn:aws:sts::xxxxxxxxxxxx:assumed-role/alb-controller-20240611131524228000000002/1718115201989397805 is not authorized to perform: elasticloadbalancing:CreateLoadBalancer on resource: arn:aws:elasticloadbalancing:us-west-2:xxxxxxxxxxxx:loadbalancer/app/k8s-ui-ui-5ddc3ba496/* because no identity-based policy allows the elasticloadbalancing:CreateLoadBalancer action\n\tstatus code: 403, request id: a24a1620-3a75-46b7-b3c3-9c80fada159e"}
このエラーは、IAM roleにelasticloadbalancing:CreateLoadBalancerアクセス許可がないことを示しています。
ステップ3:IAMポリシーを修正する
この問題を解決するには、正しいアクセス許可でIAM roleを更新する必要があります。このワークショップでは、AWS Load Balancer Controllerのインストールガイドに基づいて、必要なIAMポリシーのアクセス許可を持つ正しいポリシーをあらかじめ作成しています。
次の手順で修正します: