CLUSTER_NAME=<CLUSTER_NAME>
AWS_ACCOUNT_ID=$(aws sts get-caller-identity --query Account --output text)
Shell
복사
aws kinesis create-stream \
--stream-name demo-stream \
--shard-count 2 \
--region ap-northeast-2
Shell
복사
cat << EOF > iam_policy.json
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "KinesisAccess",
"Effect": "Allow",
"Action": [
"kinesis:DescribeStream",
"kinesis:DescribeStreamSummary",
"kinesis:GetShardIterator",
"kinesis:GetRecords",
"kinesis:ListStreams",
"kinesis:PutRecord",
"kinesis:PutRecords"
],
"Resource": "arn:aws:kinesis:ap-northeast-2:$AWS_ACCOUNT_ID:stream/demo-stream"
}
]
}
EOF
Shell
복사
aws iam create-policy \
--policy-name KinesisPolicy \
--policy-document file://iam_policy.json
Shell
복사
eksctl create iamserviceaccount \
--cluster=$CLUSTER_NAME \
--namespace=keda-kinesis-guidance \
--name=keda-operator \
--role-name=keda-operator-role \
--attach-policy-arn=arn:aws:iam::$AWS_ACCOUNT_ID:policy/KinesisPolicy \
--approve
Shell
복사
helm repo add kedacore https://kedacore.github.io/charts
helm repo update
helm install keda kedacore/keda \
-n keda-kinesis-guidance \
--set serviceAccount.operator.create=false \
--set serviceAccount.operator.name=keda-operator
Shell
복사
apiVersion: keda.sh/v1alpha1
kind: ScaledObject
metadata:
name: aws-kinesis-stream-scaledobject
namespace: keda-kinesis-guidance
spec:
scaleTargetRef:
name: nginx-deployment
minReplicaCount: 2
maxReplicaCount: 100
pollingInterval: 10
cooldownPeriod: 90
triggers:
- type: aws-kinesis-stream
metadata:
# Required
streamName: demo-stream
# Required
awsRegion: "ap-northeast-2"
# Optional: Default: 2
shardCount: "2"
identityOwner: operator
YAML
복사
kubectl apply -f scaledobject.yaml
Shell
복사
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
namespace: keda-kinesis-guidance
labels:
app: nginx
spec:
replicas: 1
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
serviceAccountName: keda-operator
containers:
- name: nginx
image: nginx:latest
ports:
- containerPort: 80
YAML
복사
kubectl apply -f deployment.yaml
Shell
복사