Add keda: Spring Boot 4.2.0 Kafka consumers under KEDA autoscaling (partition cap, lag maths, rebalances, SIGTERM vs SIGKILL)
Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_017ic4b69H5rTewUKPyhGS8r
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
# NOT EXECUTED: the sandbox that produced this module has no Docker daemon, so no cluster was
|
||||
# available. These manifests are checked only for YAML syntax. Apply them to a test cluster first.
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: orders-consumer
|
||||
spec:
|
||||
# KEDA/HPA owns the replica count once the ScaledObject exists; leave `replicas` unset.
|
||||
selector:
|
||||
matchLabels:
|
||||
app: orders-consumer
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: orders-consumer
|
||||
spec:
|
||||
# Must exceed spring.lifecycle.timeout-per-shutdown-phase (25s) plus a margin, otherwise
|
||||
# Kubernetes sends SIGKILL while the container is still finishing its batch.
|
||||
terminationGracePeriodSeconds: 60
|
||||
containers:
|
||||
- name: app
|
||||
image: registry.example.com/keda-consumer:1.0.0 # build with your usual image pipeline
|
||||
env:
|
||||
- name: SPRING_KAFKA_BOOTSTRAP_SERVERS
|
||||
value: kafka.kafka.svc.cluster.local:9092
|
||||
ports:
|
||||
- containerPort: 8080
|
||||
readinessProbe:
|
||||
httpGet: {path: /actuator/health/readiness, port: 8080}
|
||||
livenessProbe:
|
||||
httpGet: {path: /actuator/health/liveness, port: 8080}
|
||||
resources:
|
||||
requests: {cpu: 250m, memory: 512Mi}
|
||||
limits: {memory: 512Mi}
|
||||
@@ -0,0 +1,32 @@
|
||||
# NOT EXECUTED: see deployment.yaml. Field names and defaults were taken from the KEDA 2.21
|
||||
# documentation (ScaledObject specification and the Apache Kafka scaler page).
|
||||
apiVersion: keda.sh/v1alpha1
|
||||
kind: ScaledObject
|
||||
metadata:
|
||||
name: orders-consumer
|
||||
spec:
|
||||
scaleTargetRef:
|
||||
name: orders-consumer
|
||||
pollingInterval: 15 # seconds between scaler checks when scaling from/to zero (default 30)
|
||||
cooldownPeriod: 120 # only delays scale-to-ZERO after the last active trigger (default 300)
|
||||
minReplicaCount: 1 # 0 enables scale-to-zero (the default); 1 keeps one warm pod
|
||||
maxReplicaCount: 6 # keep <= partitions of the topic; more pods than partitions sit idle
|
||||
advanced:
|
||||
horizontalPodAutoscalerConfig:
|
||||
behavior: # passed straight to the HPA
|
||||
scaleDown:
|
||||
stabilizationWindowSeconds: 300
|
||||
policies:
|
||||
- type: Pods
|
||||
value: 1
|
||||
periodSeconds: 60 # remove at most one pod a minute: every removal is a rebalance
|
||||
triggers:
|
||||
- type: kafka
|
||||
metadata:
|
||||
bootstrapServers: kafka.kafka.svc.cluster.local:9092
|
||||
consumerGroup: orders-consumer
|
||||
topic: orders
|
||||
lagThreshold: "100" # target lag PER REPLICA (default 10)
|
||||
activationLagThreshold: "10" # lag must be strictly greater than this to wake from zero
|
||||
offsetResetPolicy: earliest
|
||||
# limitToPartitionsWithLag: "true" # for skewed topics; needs `topic`; not with allowIdleConsumers
|
||||
Reference in New Issue
Block a user