Search

HTTP Addon

CLUSTER_NAME=<CLUSTER_NAME> AWS_ACCOUNT_ID=$(aws sts get-caller-identity --query Account --output text)
Shell
복사
helm repo add kedacore https://kedacore.github.io/charts helm repo update helm install keda kedacore/keda --namespace keda --create-namespace helm install http-add-on kedacore/keda-add-ons-http --namespace keda
Shell
복사
helm repo add eks https://aws.github.io/eks-charts helm repo update eks 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
Shell
복사
public_a=$(aws ec2 describe-subnets --filters "Name=tag:Name,Values=skills-public-subnet-a" --query "Subnets[].SubnetId[]" --region ap-northeast-2 --output text) public_b=$(aws ec2 describe-subnets --filters "Name=tag:Name,Values=skills-public-subnet-b" --query "Subnets[].SubnetId[]" --region ap-northeast-2 --output text) private_a=$(aws ec2 describe-subnets --filters "Name=tag:Name,Values=skills-private-subnet-a" --query "Subnets[].SubnetId[]" --region ap-northeast-2 --output text) private_b=$(aws ec2 describe-subnets --filters "Name=tag:Name,Values=skills-private-subnet-b" --query "Subnets[].SubnetId[]" --region ap-northeast-2 --output text) public_subnet_name=("$public_a" "$public_b") private_subnet_name=("$private_a" "$private_b") for name in "${public_subnet_name[@]}" do aws ec2 create-tags --resources $name --tags Key=kubernetes.io/role/elb,Value=1 done for name in "${private_subnet_name[@]}" do aws ec2 create-tags --resources $name --tags Key=kubernetes.io/role/internal-elb,Value=1 done
Shell
복사
apiVersion: apps/v1 kind: Deployment metadata: name: nginx-deployment namespace: keda labels: app: nginx spec: replicas: 1 selector: matchLabels: app: nginx template: metadata: labels: app: nginx spec: containers: - name: nginx image: nginx:latest ports: - containerPort: 80
YAML
복사
kubectl apply -f deployment.yaml
Shell
복사
apiVersion: v1 kind: Service metadata: name: nginx-svc namespace: keda spec: selector: app: nginx ports: - protocol: TCP port: 80 targetPort: 80 type: ClusterIP
YAML
복사
kubectl apply -f service.yaml
Shell
복사
apiVersion: networking.k8s.io/v1 kind: Ingress metadata: name: keda-ingress namespace: keda annotations: alb.ingress.kubernetes.io/load-balancer-name: keda-alb alb.ingress.kubernetes.io/scheme: internet-facing alb.ingress.kubernetes.io/target-type: ip alb.ingress.kubernetes.io/listen-ports: '[{"HTTP": 80}]' alb.ingress.kubernetes.io/healthcheck-path: / alb.ingress.kubernetes.io/healthcheck-interval-seconds: "5" alb.ingress.kubernetes.io/healthcheck-timeout-seconds: "3" alb.ingress.kubernetes.io/healthy-threshold-count: "3" alb.ingress.kubernetes.io/unhealthy-threshold-count: "2" alb.ingress.kubernetes.io/target-group-attributes: deregistration_delay.timeout_seconds=30 spec: ingressClassName: alb rules: - http: paths: - path: / pathType: Prefix backend: service: name: keda-add-ons-http-interceptor-proxy port: number: 8080
YAML
복사
kubectl apply -f ingress.yaml
Shell
복사
kind: HTTPScaledObject apiVersion: http.keda.sh/v1alpha1 metadata: name: nginx-http-scaledobject namespace: keda spec: hosts: - <ALB_DOMAIN> scalingMetric: requestRate: targetValue: 3 window: 30s granularity: 5s scaleTargetRef: name: nginx-deployment service: nginx-svc port: 80 replicas: min: 1 max: 20 scaledownPeriod: 60
YAML
복사
kubectl apply -f httpscaledobject.yaml
Shell
복사
kubectl logs -n keda -l app=keda-operator
Shell
복사
while true; do curl http://<ALB-DNS-Name>; done
Shell
복사
nginx 파드가 성공적으로 스케일링된 모습 확인 가능
트래픽이 없을 시 성공적으로 스케일 다운까지 성공적으로 된 모습 확인 가능