Search

EKS

public_a=$(aws ec2 describe-subnets --filters "Name=tag:Name,Values=keda-public-subnet-a" --query "Subnets[].SubnetId[]" --region ap-northeast-2 --output text) public_b=$(aws ec2 describe-subnets --filters "Name=tag:Name,Values=keda-public-subnet-b" --query "Subnets[].SubnetId[]" --region ap-northeast-2 --output text) private_a=$(aws ec2 describe-subnets --filters "Name=tag:Name,Values=keda-private-subnet-a" --query "Subnets[].SubnetId[]" --region ap-northeast-2 --output text) private_b=$(aws ec2 describe-subnets --filters "Name=tag:Name,Values=keda-private-subnet-b" --query "Subnets[].SubnetId[]" --region ap-northeast-2 --output text) sed -i "s|public_a|$public_a|g" cluster.yaml sed -i "s|public_b|$public_b|g" cluster.yaml sed -i "s|private_a|$private_a|g" cluster.yaml sed -i "s|private_b|$private_b|g" cluster.yaml eksctl create cluster -f cluster.yaml
Shell
복사
CLUSTER_NAME=order-cluster AWS_ACCOUNT_ID=$(aws sts get-caller-identity --query Account --output text)
Shell
복사
cat << EOF > iam_policy.json { "Version": "2012-10-17", "Statement": [ { "Sid": "GetQueueAttributes", "Effect": "Allow", "Action": [ "sqs:GetQueueAttributes", "sqs:ReceiveMessage", "sqs:GetQueueUrl", "sqs:ListQueues", "sqs:deletemessage" ], "Resource": "*" } ] } EOF
Shell
복사
aws iam create-policy \ --policy-name SqsPolicy \ --policy-document file://iam_policy.json
Shell
복사
eksctl create iamserviceaccount \ --cluster=$CLUSTER_NAME \ --namespace=order \ --name=keda-operator \ --role-name=keda-operator-role \ --attach-policy-arn=arn:aws:iam::$AWS_ACCOUNT_ID:policy/SqsPolicy \ --approve
Shell
복사
helm repo add kedacore https://kedacore.github.io/charts helm repo update helm install keda kedacore/keda \ -n order \ --set serviceAccount.operator.create=false \ --set serviceAccount.operator.name=keda-operator
Shell
복사
apiVersion: apps/v1 kind: Deployment metadata: name: order-processor namespace: order labels: app: order-processor spec: replicas: 1 selector: matchLabels: app: order-processor template: metadata: labels: app: order-processor spec: serviceAccountName: keda-operator containers: - name: order-processor image: 362708816803.dkr.ecr.ap-northeast-2.amazonaws.com/order-app:v1 env: - name: QUEUE_URL value: "https://sqs.ap-northeast-2.amazonaws.com/362708816803/order-queue" - name: REGION_NAME value: ap-northeast-2 ports: - containerPort: 8080
YAML
복사
kubectl apply -f deployment.yaml
Shell
복사
apiVersion: keda.sh/v1alpha1 kind: ScaledObject metadata: name: order-processor-scaler namespace: order spec: scaleTargetRef: name: order-processor minReplicaCount: 1 maxReplicaCount: 10 pollingInterval: 10 cooldownPeriod: 60 advanced: horizontalPodAutoscalerConfig: behavior: scaleDown: stabilizationWindowSeconds: 30 policies: - type: Percent value: 100 periodSeconds: 15 triggers: - type: aws-sqs-queue metadata: queueURL: https://sqs.ap-northeast-2.amazonaws.com/362708816803/order-queue activationQueueLength: "0" queueLength: "5" awsRegion: ap-northeast-2 identityOwner: operator
YAML
복사
kubectl apply -f keda.yaml
Shell
복사