Using ELB on EKS
Create AWS Load Balancer Controller IAM role
CLUSTER_NAME="<cluster name>"
POLICY_NAME="<policy name>"
ROLE_NAME="<role name>"
PROJECT_NAME="<project name>"
REGION="<region>"
curl -L -o aws-load-balancer-controller-iam-policy.json https://raw.githubusercontent.com/kubernetes-sigs/aws-load-balancer-controller/main/docs/install/iam_policy.json
POLICY_ARN=$(aws iam create-policy \
--policy-name $POLICY_NAME \
--policy-document file://aws-load-balancer-controller-iam-policy.json \
--query 'Policy.Arn' \
--output text \
# --tags Key=project,Value=$PROJECT_NAME \ # AWS CLI v2
)
eksctl create iamserviceaccount \
--cluster=$CLUSTER_NAME \
--namespace=kube-system \
--name=aws-load-balancer-controller \
--role-name "$ROLE_NAME" \
--attach-policy-arn=$POLICY_ARN \
--tags project=$PROJECT_NAME \
--region $REGION \
--override-existing-serviceaccounts \
--approve
$CLUSTER_NAME="<cluster name>"
$POLICY_NAME="<policy name>"
$ROLE_NAME="<role name>"
$PROJECT_NAME="<project name>"
$REGION="<region>"
curl.exe -L -o aws-load-balancer-controller-iam-policy.json https://raw.githubusercontent.com/kubernetes-sigs/aws-load-balancer-controller/main/docs/install/iam_policy.json
$POLICY_ARN = aws iam create-policy `
--policy-name $POLICY_NAME `
--policy-document file://aws-load-balancer-controller-iam-policy.json `
--query 'Policy.Arn' `
--output text `
--tags Key=project,Value=$PROJECT_NAME
eksctl create iamserviceaccount `
--cluster=$CLUSTER_NAME `
--namespace=kube-system `
--name=aws-load-balancer-controller `
--role-name "$ROLE_NAME" `
--attach-policy-arn=$POLICY_ARN `
--tags project=$PROJECT_NAME `
--region $REGION `
--override-existing-serviceaccounts `
--approve
Install AWS Load Balancer Controller using helm
VPC_ID="<vpc id>"
CLUSTER_NAME="<cluster name>"
REGION="<region>"
helm repo add eks https://aws.github.io/eks-charts
helm repo update
helm install aws-load-balancer-controller eks/aws-load-balancer-controller \
-n kube-system \
--set clusterName=$CLUSTER_NAME \
--set serviceAccount.create=false \
--set serviceAccount.name=aws-load-balancer-controller \
--set region=$REGION \
--set vpcId=$VPC_ID
kubectl get deployment aws-load-balancer-controller \
-n kube-system \
-w
$VPC_ID="<vpc id>"
$CLUSTER_NAME="<cluster name>"
$REGION="<region>"
helm repo add eks https://aws.github.io/eks-charts
helm repo update
helm install aws-load-balancer-controller eks/aws-load-balancer-controller `
-n kube-system `
--set clusterName=$CLUSTER_NAME `
--set serviceAccount.create=false `
--set serviceAccount.name=aws-load-balancer-controller `
--set region=$REGION `
--set vpcId=$VPC_ID
kubectl get deployment aws-load-balancer-controller `
-n kube-system `
-w
Create ALB using Ingress
AWS Load Balancer Controller Documentation
Create NLB using Service (type: LoadBalancer
)
Note
If you want to use NLB, you should create a tag to target's security group like this: