본문으로 바로가기 본문 바로가기
WIKI 기술 지식 베이스

Redis Streams (Redis Sentinel 지원)

원문 보기 위키 갱신

Redis Streams를 기준으로 스케일링하는 redis-sentinel-streams 트리거에 대해 설명할게요. Redis Sentinel을 지원하며, 스트림 기반 메시지 처리 워크로드를 유연하게 확장할 수 있어요.

출처: 문서

본문

트리거 스펙 (Trigger Specification)

Redis 5.0은 추가 전용(append-only) 로그 데이터 구조인 Redis Streams를 도입했어요. 그 기능 중 하나인 Consumer Groups를 사용하면 클라이언트 그룹이 협력해 동일한 메시지 스트림의 서로 다른 부분을 소비할 수 있어요.

redis-streams 트리거를 구성하는 방법은 세 가지가 있어요.

  • Redis Stream의 특정 Consumer Group에 대한 Pending Entries List 기반(참고: XPENDING)
  • Stream Length 기반(참고: XLEN)
  • Consumer Group Lag 기반(참고: XINFO GROUPS). 0으로 스케일다운하는 것을 지원하는 유일한 구성이에요. 중요: 이 기능이 실행되려면 Redis 7+가 필요해요.
triggers:
- type: redis-sentinel-streams
  metadata:
    addresses: localhost:26379 # Required if hosts and ports are not provided. Format - comma separated list of host:port
    hosts: localhost # Comma separated lists of hosts. Required if address is not provided
    ports: "26379" # Comma separated lists of ports. Required if addresses are not provided and hosts has been provided.
    usernameFromEnv: REDIS_USERNAME # optional (can also use authenticationRef)
    passwordFromEnv: REDIS_PASSWORD # optional (can also use authenticationRef)
    stream: my-stream # Required - name of the Redis Stream
    consumerGroup: my-consumer-group # optional - name of consumer group associated with Redis Stream
    pendingEntriesCount: "10" # optional - number of entries in the Pending Entries List for the specified consumer group in the Redis Stream
    streamLength: "50" # optional - Redis stream length, alternative to pendingEntriesCount scaler trigger
    lagCount: "5" # optional - number of lagging entries in the consumer group, alternative to pendingEntriesCount scaler trigger
    activationLagCount: "3" # required if lagCount is provided - lag count at which scaler triggers
    enableTLS: "false" # optional
    unsafeSsl: "false" # optional
    databaseIndex: "0" # optional
    # Alternatively, you can use existing environment variables to read configuration from:
    # See details in "Parameter list" section
    addressesFromEnv: REDIS_ADDRESSES # Optional. You can use this instead of `addresses` parameter
    hostsFromEnv: REDIS_HOSTS # Optional. You can use this instead of `hosts` parameter
    portsFromEnv: REDIS_PORTS # Optional. You can use this instead of `ports` parameter

파라미터 목록:

  • addresses - Redis Sentinel 노드의 호스트와 포트를 host:port 형식으로 쉼표로 구분한 목록. 예: node1:26379, node2:26379, node3:26379. addresses 필드의 대안으로 hosts와 ports 파라미터를 지정할 수 있어요.

  • hosts - Redis Sentinel 노드의 호스트를 쉼표로 구분한 목록. addresses가 제공되면 필요하지 않아요.

  • ports - Redis Sentinel 노드의 해당 호스트에 대한 포트를 쉼표로 구분한 목록. hosts/hostsFromEnv 속성과 함께만 사용해야 하며, addresses가 제공되면 필요하지 않아요.

  • usernameFromEnv - Deployment가 Redis 사용자 이름을 가져오는 데 사용하는 환경 변수 이름. (선택)

  • passwordFromEnv - Deployment가 Redis 비밀번호를 가져오는 데 사용하는 환경 변수 이름. (선택)

  • sentinelUsernameFromEnv - Deployment가 Redis Sentinel 사용자 이름을 가져오는 데 사용하는 환경 변수 이름. (선택)

  • sentinelPasswordFromEnv - Deployment가 Redis Sentinel 비밀번호를 가져오는 데 사용하는 환경 변수 이름. (선택)

  • sentinelMaster - Redis 서버 주소를 가져오기 위해 Sentinel에서의 primary(Sentinel에서 여전히 'master'라고 부름) 이름.

  • stream - Redis Stream 이름.

  • consumerGroup - Redis Stream과 연결된 Consumer group 이름.

    consumerGroup을 설정하면 스케일러가 pendingEntriesCount를 기준으로 동작해요. consumerGroup이 없으면 스케일러는 streamLength를 기준으로 해요.

  • pendingEntriesCount - Pending Entries List 수의 임계값. 워크로드를 스케일링하는 평균 대상 값이에요. (기본값: 5, 선택)

  • streamLength - 스트림 길이의 임계값. 워크로드를 스케일링하는 대체 평균 대상 값. (기본값: 5, 선택)

  • lagCount - consumer group lag 수의 임계값. 워크로드를 스케일링하는 대체 평균 대상 값. (기본값: 5, 선택)

  • activationLagCount - 스케일링을 시작할 lag 수 임계값. 이 값보다 낮은 평균 lag 수는 스케일러를 트리거하지 않아요. (기본값: 0, 선택)

  • enableTLS - tls를 사용해 Redis에 연결 허용. (값: true, false, 기본값: false, 선택)

  • unsafeSsl - 인증서 확인을 건너뛰는 데 사용, 예: 자체 서명 인증서 사용. (값: true, false, 기본값: false, 선택, 이 기능은 enableTLS: true가 필요해요)

  • databaseIndex - 사용할 Redis 데이터베이스 인덱스. 지정하지 않으면 기본값은 0.

일부 파라미터는 metadata에 직접 설정하는 대신 환경 변수로 제공할 수 있어요. 환경 변수에서 값을 가져올 수 있는 파라미터 목록은 다음과 같아요.

  • addressesFromEnv - addresses와 비슷하게 Redis Sentinel 노드의 호스트와 해당 포트지만, 스케일 대상의 환경 변수에서 읽어요. Deployment가 Redis Sentinel 노드의 URL을 가져오는 데 사용하는 환경 변수 이름. 해석된 호스트는 node1:26379, node2:26379, node3:26379 ... 같은 형식을 따라야 해요.
  • hostsFromEnv - hosts와 비슷하게 Redis Sentinel 노드의 호스트지만, 스케일 대상의 환경 변수에서 읽어요.
  • portsFromEnv - ports와 비슷하게 Redis Sentinel 노드의 해당 포트지만, 스케일 대상의 환경 변수에서 읽어요.
  • sentinelMasterFromEnv - sentinelMaster와 비슷하게 Redis 서버 주소를 가져올 Sentinel에서의 primary 이름이지만, 스케일 대상의 환경 변수에서 읽어요.

인증 파라미터 (Authentication Parameters)

이 스케일러는 두 가지 인증 모드를 지원해요.

username/password 인증 사용하기 (Using username/password authentication)

metadata의 username과 password 필드를 사용해 Deployment가 Redis 사용자 이름/비밀번호를 가져오는 데 사용하는 환경 변수의 이름을 지정해요. 이는 보통 Secret V1 또는 ConfigMap V1 컬렉션에서 해석돼요. env와 envFrom을 모두 지원해요.

다음은 예시예요.

apiVersion: keda.sh/v1alpha1
kind: ScaledObject
metadata:
  name: redis-streams-scaledobject
  namespace: default
spec:
  scaleTargetRef:
    name: redis-streams-consumer
  pollingInterval: 15
  cooldownPeriod: 200
  maxReplicaCount: 25
  minReplicaCount: 1
  triggers:
    - type: redis-sentinel-streams
      metadata:
        addressesFromEnv: REDIS_ADDRESSES
        usernameFromEnv: REDIS_USERNAME # name of the environment variable in the Deployment
        passwordFromEnv: REDIS_PASSWORD # name of the environment variable in the Deployment
        stream: my-stream
        consumerGroup: consumer-group-1
        pendingEntriesCount: "10"
        sentinelMaster: "myprimary"

TriggerAuthentication 사용하기 (Using TriggerAuthentication)

TLS:

TLS 인증을 구성하는 데 사용되는 파라미터. 이는 인증서 확인을 건너뛰는 비보안 TLS를 정의하는 ScaledObject의 enableTLS 및 unsafeSsl과 함께 사용할 수 없다는 점에 주의하세요.

  • tls - Redis에 대한 SSL 인증을 활성화하려면 이 값을 enable로 설정해요. 설정하지 않으면 Redis에 TLS가 사용되지 않아요. (값: enable, disable, 기본값: disable, 선택)
  • ca - TLS 인증용 인증 기관 파일. (선택)
  • cert - 클라이언트 인증용 인증서. (선택)
  • key - 클라이언트 인증용 키. (선택)
  • keyPassword - 설정하면 keyPassword가 제공된 키의 암호를 해독하는 데 사용돼요. (선택)

인증(Authentication):

  • username - 인증할 Redis 사용자 이름.
  • password - 인증할 Redis 비밀번호.

TriggerAuthentication CRD를 사용해 인증을 구성할 수 있어요. 예를 들어:

apiVersion: v1
kind: Secret
metadata:
  name: redis-streams-auth
type: Opaque
data:
  redis_username: <encoded redis username>
  redis_password: <encoded redis password>
  tls: "enable"
  ca: <your ca>
  cert: <your cert>
  key: <your key>
---
apiVersion: keda.sh/v1alpha1
kind: TriggerAuthentication
metadata:
  name: keda-redis-stream-triggerauth
spec:
  secretTargetRef:
    - parameter: username
      name: redis-streams-auth # name of the Secret
      key: redis_username # name of the key in the Secret
    - parameter: password
      name: redis-streams-auth # name of the Secret
      key: redis_password # name of the key in the Secret
    - parameter: tls
      name: redis-streams-auth
      key: tls
    - parameter: ca
      name: redis-streams-auth
      key: ca
    - parameter: cert
      name: redis-streams-auth
      key: cert
    - parameter: key
      name: redis-streams-auth
      key: key
---
apiVersion: keda.sh/v1alpha1
kind: ScaledObject
metadata:
  name: redis-streams-scaledobject
  namespace: default
spec:
  scaleTargetRef:
    name: redis-streams-consumer
  pollingInterval: 15
  cooldownPeriod: 200
  maxReplicaCount: 25
  minReplicaCount: 1
  triggers:
    - type: redis-sentinel-streams
      metadata:
        address: node1:26379, node2:26379, node3:26379
        stream: my-stream
        consumerGroup: consumer-group-1
        pendingEntriesCount: "10"
        sentinelMaster: "myprimary"
      authenticationRef:
        name: keda-redis-stream-triggerauth # name of the TriggerAuthentication resource

streamLength 사용하기 (Using streamLength)

redis stream의 XLEN을 기준으로 스케일링하려면 consumerGroup을 설정하지 마세요. 예:

apiVersion: keda.sh/v1alpha1
kind: ScaledObject
metadata:
  name: redis-streams-scaledobject
  namespace: default
spec:
  scaleTargetRef:
    name: redis-streams-consumer
  pollingInterval: 20
  cooldownPeriod: 200
  maxReplicaCount: 10
  minReplicaCount: 1
  triggers:
    - type: redis-sentinel-streams
      metadata:
        addressesFromEnv: REDIS_ADDRESSES
        usernameFromEnv: REDIS_USERNAME # name of the environment variable in the Deployment
        passwordFromEnv: REDIS_PASSWORD # name of the environment variable in the Deployment
        stream: my-stream
        streamLength: "50"
        sentinelMaster: "myprimary"

lagCount 사용하기 (Using lagCount)

redis stream의 XINFO GROUPS를 기준으로 스케일링하려면 activationLagCount를 반드시 설정하세요. 예:

apiVersion: keda.sh/v1alpha1
kind: ScaledObject
metadata:
  name: redis-streams-scaledobject
  namespace: default
spec:
  scaleTargetRef:
    name: redis-streams-consumer
  pollingInterval: 15
  cooldownPeriod: 200
  maxReplicaCount: 25
  minReplicaCount: 1
  triggers:
    - type: redis-cluster-streams
      metadata:
        addressesFromEnv: REDIS_ADDRESSES
        usernameFromEnv: REDIS_USERNAME # name of the environment variable in the Deployment
        passwordFromEnv: REDIS_PASSWORD # name of the environment variable in the Deployment
        stream: my-stream
        consumerGroup: consumer-group-1
        lagCount: "10"
        activationLagCount: "3"

더 알아보기 (Learn more)

Redis Streams 스케일러는 consumerGroup 유무에 따라 동작 방식이 달라져요. 컨슈머 그룹이 있으면 처리되지 않은 항목(pending)을, 없으면 전체 스트림 길이를 기준으로 삼아요. 0으로 스케일다운이 필요하다면 Redis 7+가 필요한 lag 기반 구성을 살펴보세요.