0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

EKSクラスタにAWS LoadBalancer Controllerを導入する

Last updated at Posted at 2021-02-27

eksctlで作成したEKSクラスタに対して、AWS LoadBalancer Controllerを導入する方法

下記ファイルをDLする

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

IAMポリシーを作成する

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

AWSロードバランサーコントローラーのIAMロールとServiceAccountを作成する

eksctl create iamserviceaccount \
--cluster=eks-dev-cluster \
--namespace=kube-system \
--name=aws-load-balancer-controller \
--attach-policy-arn=arn:aws:iam::XXXXXXXXXXXXXX:policy/AWSLoadBalancerControllerIAMPolicy \
--profile=hogehogeplofile \
--approve

ここで、AWS LoadBalancerをEKSクラスターにデプロイします。

curl -o v2_0_0_full.yaml https://raw.githubusercontent.com/kubernetes-sigs/aws-load-balancer-controller/main/docs/install/v2_0_0_full.yaml
kubectl apply -f v2_0_0_full.yaml

eksctlで作成しなかったEKSクラスタに対して、AWS LoadBalancer Controllerを導入する方法

AWSアカウントIDを環境変数に設定します。

AWS_ACCOUNT_ID=$(aws sts get-caller-identity --query "Account" --profile hogehogeplofile --output text)

OIDC IDプロバイダーを環境変数に設定します。

OIDC_PROVIDER=$(aws eks describe-cluster --name eks-dev-cluster --query "cluster.identity.oidc.issuer" --output text --profile hogehogeplofile --region ap-northeast-1 | sed -e "s/^https:\/\///")

jsonを作ります。

read -r -d '' TRUST_RELATIONSHIP <<EOF
{
"Version": "2012-10-17",
"Statement": [
  {
    "Effect": "Allow",
    "Principal": {
      "Federated": "arn:aws:iam::${AWS_ACCOUNT_ID}:oidc-provider/${OIDC_PROVIDER}"
    },
    "Action": "sts:AssumeRoleWithWebIdentity",
    "Condition": {
      "StringEquals": {
        "${OIDC_PROVIDER}:sub": "system:serviceaccount:kube-system:aws-load-balancer-controller"
      }
    }
  }
]
}
EOF
echo "${TRUST_RELATIONSHIP}" > trust.json

サービスのロールを作ります。

aws iam create-role --role-name aws-load-balancer-controller-role --assume-role-policy-document file://trust.json --description "role for aws-load-balancer-controller" --profile hogehogeplofile 

IAMポリシーをロールにアタッチします

aws iam attach-role-policy --role-name aws-load-balancer-controller-role --policy-arn=arn:aws:iam::XXXXXXXXXX:policy/AWSLoadBalancerControllerIAMPolicy --profile hogehogeplofile 

ここで、AWS LoadBalancerをEKSクラスターにデプロイします。

curl -o v2_0_0_full.yaml https://raw.githubusercontent.com/kubernetes-sigs/aws-load-balancer-controller/main/docs/install/v2_0_0_full.yaml
kubectl apply -f v2_0_0_full.yaml

サービスアカウントにIAMロールを指定します。

kubectl annotate serviceaccount -n kube-system aws-load-balancer-controller eks.amazonaws.com/role-arn=arn:aws:iam::XXXXXXXXXX:role/aws-load-balancer-controller-role

参考文献

https://github.com/awsdocs/amazon-eks-user-guide/blob/master/doc_source/create-service-account-iam-policy-and-role.md
https://github.com/awsdocs/amazon-eks-user-guide/blob/master/doc_source/specify-service-account-role.md
https://blog.sallah-kokaina.com/aws-alb-load-balancer-controller-no-eksctl-managed-cloudformation-stacks-found-error-ckhj5lwrt00w37ys145db8fbq
https://kubernetes-sigs.github.io/aws-load-balancer-controller/latest/guide/controller/installation/
https://aws.amazon.com/jp/premiumsupport/knowledge-center/eks-alb-ingress-controller-setup/

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?