aula-05: KEDA + Victoria Metrics para auto-scaling
- Auto-scaling baseado em pods indisponíveis e restarts - Victoria Metrics para coleta de métricas - NGINX Ingress com retry automático (5 tentativas) - Configuração ultra-agressiva: +5 pods/segundo - Script setup.sh para instalação completa - Mínimo 5 pods, máximo 30 pods
This commit is contained in:
65
aula-05/ingress-nginx.yaml
Normal file
65
aula-05/ingress-nginx.yaml
Normal file
@@ -0,0 +1,65 @@
|
||||
# NGINX Ingress com "Keep Request" + Retry automático
|
||||
# Quando um pod falha, tenta automaticamente outro pod (até 5 tentativas)
|
||||
# Quando todos os pods estão indisponíveis, aguarda até 99s antes de retornar 503
|
||||
apiVersion: networking.k8s.io/v1
|
||||
kind: Ingress
|
||||
metadata:
|
||||
name: node-bugado-nginx
|
||||
annotations:
|
||||
# Retry automático: tenta outro pod quando recebe erro
|
||||
nginx.ingress.kubernetes.io/proxy-next-upstream: "error timeout http_502 http_503 http_504"
|
||||
nginx.ingress.kubernetes.io/proxy-next-upstream-tries: "5"
|
||||
nginx.ingress.kubernetes.io/proxy-next-upstream-timeout: "30"
|
||||
# Location interno que aguarda o backend ficar disponível
|
||||
nginx.ingress.kubernetes.io/server-snippet: |
|
||||
error_page 502 503 504 = @wait_for_backend;
|
||||
|
||||
location @wait_for_backend {
|
||||
internal;
|
||||
content_by_lua_block {
|
||||
local max_wait = 99
|
||||
local interval = 1
|
||||
local start = ngx.now()
|
||||
local backend_host = "node-bugado.default.svc.cluster.local"
|
||||
local backend_port = 3000
|
||||
|
||||
ngx.log(ngx.INFO, "[KeepRequest] Aguardando backend por ate ", max_wait, "s...")
|
||||
|
||||
while (ngx.now() - start) < max_wait do
|
||||
local sock = ngx.socket.tcp()
|
||||
sock:settimeout(1000)
|
||||
|
||||
local ok, err = sock:connect(backend_host, backend_port)
|
||||
if ok then
|
||||
sock:close()
|
||||
local elapsed = math.floor(ngx.now() - start)
|
||||
ngx.log(ngx.INFO, "[KeepRequest] Backend ready apos ", elapsed, "s")
|
||||
-- Redirect interno (não retorna ao cliente)
|
||||
return ngx.exec(ngx.var.request_uri)
|
||||
end
|
||||
|
||||
ngx.log(ngx.WARN, "[KeepRequest] Backend indisponivel: ", err)
|
||||
ngx.sleep(interval)
|
||||
end
|
||||
|
||||
ngx.status = 503
|
||||
ngx.header["Content-Type"] = "text/plain"
|
||||
ngx.say("Servico indisponivel apos ", max_wait, "s de espera")
|
||||
ngx.exit(503)
|
||||
}
|
||||
}
|
||||
# Timeouts curtos para falhar rápido e ir para o handler Lua
|
||||
nginx.ingress.kubernetes.io/proxy-connect-timeout: "2"
|
||||
nginx.ingress.kubernetes.io/proxy-read-timeout: "3"
|
||||
spec:
|
||||
ingressClassName: nginx
|
||||
rules:
|
||||
- http:
|
||||
paths:
|
||||
- path: /
|
||||
pathType: Prefix
|
||||
backend:
|
||||
service:
|
||||
name: node-bugado
|
||||
port:
|
||||
number: 3000
|
||||
Reference in New Issue
Block a user