KEDA를 통해 자동 스케일링

완료됨

Kubernetes 이벤트 기반 자동 크기 조정

KEDA는 Kubernetes 이벤트 기반 자동 스케일러입니다. 애플리케이션 자동 크기 조정을 간소화하는 오픈 소스, CNCF 솔루션, 경량 구성 요소입니다. 모든 Kubernetes 클러스터에 KEDA를 추가하고 HPA(Horizontal Pod Autoscaler) 또는 클러스터 자동 스케일러와 같은 표준 Kubernetes 구성 요소와 함께 사용하여 해당 기능을 확장할 수 있습니다. KEDA를 사용하면 이벤트 기반 크기 조정을 활용하려는 특정 앱을 대상으로 지정하고 다른 앱에서 다른 크기 조정 방법을 사용하도록 허용할 수 있습니다. KEDA는 다양한 Kubernetes 애플리케이션 또는 프레임워크와 함께 실행할 수 있는 유연하고 안전한 옵션입니다.

주요 기능 및 특징

  • 0으로 확장 가능한 기능을 사용하여 지속 가능하고 비용 효율적인 애플리케이션 빌드
  • KEDA 스칼라를 사용하여 수요에 맞게 애플리케이션 워크로드 크기 조정
  • 을 사용하여 애플리케이션 자동 크기 조정 ScaledObjects
  • 를 사용하여 작업 자동 크기 조정 ScaledJobs
  • 워크로드에서 자동 크기 조정 및 인증을 분리하여 프로덕션 등급 보안 사용
  • 맞춤형 자동 크기 조정 구성을 사용하는 사용자 고유의 외부 스케일러 가져오기

아키텍처

KEDA는 다음 두 가지 기본 구성 요소를 제공합니다.

  • KEDA 연산자를 사용하면 최종 사용자가 Kubernetes 배포, 작업, StatefulSets 또는 하위 리소스를 정의하는 고객 리소스를 지원하여 0에서 N 인스턴스로 워크로드 크기를 조정할 수 있습니다/scale.
  • 메트릭 서버자동 크기 조정 작업을 추진하기 위해 Kafka 토픽의 메시지 또는 Azure Event Hubs의 이벤트와 같은 외부 메트릭을 HPA에 노출합니다. 업스트림 제한으로 인해 KEDA 메트릭 서버는 클러스터에 설치된 유일한 메트릭 어댑터여야 합니다.

다음 다이어그램에서는 KEDA가 Kubernetes HPA, 외부 이벤트 원본 및 Kubernetes API Server와 통합되어 자동 크기 조정 기능을 제공하는 방법을 보여 줍니다.

A diagram that depicts the KEDA architecture in Kubernetes.

자세한 내용은 공식 KEDA 설명서를 참조하세요.

이벤트 원본 및 스케일러

KEDA 스케일러는 배포를 활성화해야 할지 비활성화해야 할지를 감지하고 특정 이벤트 원본에 대한 사용자 지정 메트릭을 피드할 수 있습니다. 배포 및 StatefulSets는 KEDA를 사용하여 워크로드를 스케일링하는 가장 일반적인 방법입니다. /scale 하위 리소스를 구현하는 사용자 지정 리소스의 크기를 조정할 수도 있습니다. 크기 조정 트리거를 기반으로 KEDA가 크기 조정할 Kubernetes 배포 또는 StatefulSet을 정의할 수 있습니다. KEDA는 이러한 서비스를 모니터링하고 발생하는 이벤트에 따라 자동으로 크기를 확대 또는 축소합니다.

내부적으로 KEDA는 이벤트 원본을 모니터링하고 해당 데이터를 Kubernetes 및 HPA에 공급하여 신속한 리소스 크기 조정을 추진합니다. 리소스의 각 복제본은 이벤트 원본에서 항목을 적극적으로 끌어옵니다. KEDA와 Deployments/StatefulSets을(를) 통해, 이벤트를 기반으로 크기 조정하는 동시에 이벤트 원본과 함께 풍부한 연결 및 처리 의미 체계(예: 순서대로 처리, 재시도, 데드레터, 검사점 지정)를 보존할 수 있습니다.

스케일링된 개체 사양

apiVersion: keda.sh/v1alpha1
kind: ScaledObject
metadata:
  name: {scaled-object-name}
spec:
  scaleTargetRef:
    apiVersion:    {api-version-of-target-resource}  # Optional. Default: apps/v1
    kind:          {kind-of-target-resource}         # Optional. Default: Deployment
    name:          {name-of-target-resource}         # Mandatory. Must be in the same namespace as the ScaledObject
    envSourceContainerName: {container-name}         # Optional. Default: .spec.template.spec.containers[0]
  pollingInterval: 30                                # Optional. Default: 30 seconds
  cooldownPeriod:  300                               # Optional. Default: 300 seconds
  minReplicaCount: 0                                 # Optional. Default: 0
  maxReplicaCount: 100                               # Optional. Default: 100
  advanced:                                          # Optional. Section to specify advanced options
    restoreToOriginalReplicaCount: true/false        # Optional. Default: false
    horizontalPodAutoscalerConfig:                   # Optional. Section to specify HPA related options
      behavior:                                      # Optional. Use to modify HPA's scaling behavior
        scaleDown:
          stabilizationWindowSeconds: 300
          policies:
          - type: Percent
            value: 100
            periodSeconds: 15
  triggers:
  # {list of triggers to activate scaling of the target resource}

크기 조정된 작업 사양

이벤트 구동 코드를 배포로서 크기 조정하는 대안으로, 코드를 Kubernetes 작업으로 실행하고 크기 조정할 수도 있습니다. 이 옵션을 고려해야 하는 주된 이유는 장기 실행 실행을 처리해야 하는 경우입니다. 배포 내에서 여러 이벤트를 처리하는 대신 검색된 각 이벤트는 자체 Kubernetes 작업을 예약합니다. 이 방법을 사용하면 각 이벤트를 격리된 상태로 처리하고 큐의 이벤트 수에 따라 동시 실행 수를 조정할 수 있습니다.

apiVersion: keda.sh/v1alpha1
kind: ScaledJob
metadata:
  name: {scaled-job-name}
spec:
  jobTargetRef:
    parallelism: 1                            # [max number of desired pods](https://kubernetes.io/docs/concepts/workloads/controllers/jobs-run-to-completion/#controlling-parallelism)
    completions: 1                            # [desired number of successfully finished pods](https://kubernetes.io/docs/concepts/workloads/controllers/jobs-run-to-completion/#controlling-parallelism)
    activeDeadlineSeconds: 600                #  Specifies the duration in seconds relative to the startTime that the job may be active before the system tries to terminate it; value must be positive integer
    backoffLimit: 6                           # Specifies the number of retries before marking this job failed. Defaults to 6
    template:
      # describes the [job template](https://kubernetes.io/docs/concepts/workloads/controllers/jobs-run-to-completion/)
  pollingInterval: 30                         # Optional. Default: 30 seconds
  successfulJobsHistoryLimit: 5               # Optional. Default: 100. How many completed jobs should be kept.
  failedJobsHistoryLimit: 5                   # Optional. Default: 100. How many failed jobs should be kept.
  envSourceContainerName: {container-name}    # Optional. Default: .spec.JobTargetRef.template.spec.containers[0]
  maxReplicaCount: 100                        # Optional. Default: 100
  scalingStrategy:
    strategy: "custom"                        # Optional. Default: default. Which Scaling Strategy to use. 
    customScalingQueueLengthDeduction: 1      # Optional. A parameter to optimize custom ScalingStrategy.
    customScalingRunningJobPercentage: "0.5"  # Optional. A parameter to optimize custom ScalingStrategy.
  triggers:
  # {list of triggers to create jobs}

지식 점검

1.

Kubernetes 내에서 KEDA가 수행하는 주요 역할은 무엇인가요?

2.

KEDA는 어떤 유형의 워크로드를 스케일링할 수 있나요?

3.

크기 조정된 작업을 사용하는 기본적인 이유는 무엇인가요?