Files
workshop/aula-13/benchmarks/benchmark-clean.sh
ArgoCD Setup e8c793058c refactor: remover todas as dependências do GitLab no workshop
- Aula 08: nginx-ingress TCP passthrough gitlab→gitea, comments
- Aula 09: add-client.sh API GitLab→Gitea
- Aula 11: node-bugado deployment image registry.kube.quest→gitea.kube.quest
- Aula 12: setup.sh/cleanup.sh API GitLab→Gitea, ArgoCD repoURL
- Aula 13: k8s manifests, benchmarks: registry.kube.quest→gitea.kube.quest,
           gitlab-registry→gitea-registry, GITLAB_TOKEN→GITEA_TOKEN
- Aula 14: comments GitLab→Gitea
- README raiz: arquitetura, tabela, DNS
2026-03-14 02:02:01 -03:00

189 lines
6.8 KiB
Bash
Executable File

#!/bin/bash
# =============================================================================
# Benchmark LIMPO: eStargz vs Traditional Image Pull
# =============================================================================
#
# Este benchmark força execução em um node SEM cache das imagens
# para medir tempo REAL de pull.
#
# =============================================================================
set -e
NAMESPACE="benchmark-clean"
ESTARGZ_IMAGE="gitea.kube.quest/factory/postgresql:17"
TRADITIONAL_IMAGE="postgres:17-alpine"
TARGET_NODE="talos-msadg4-worker-0" # Node sem cache
echo "========================================================================"
echo "Benchmark LIMPO: eStargz vs Traditional Image Pull"
echo "========================================================================"
echo ""
echo "Target node: $TARGET_NODE (sem cache de imagens)"
echo ""
echo "Comparando:"
echo " Tradicional: $TRADITIONAL_IMAGE"
echo " eStargz: $ESTARGZ_IMAGE"
echo ""
# Verificar cluster
echo "[1/6] Verificando cluster..."
kubectl cluster-info >/dev/null || { echo "ERRO: Cluster inacessível"; exit 1; }
echo " Cluster OK"
# Limpar ambiente anterior
echo "[2/6] Limpando ambiente anterior..."
kubectl delete namespace $NAMESPACE --ignore-not-found=true --wait=true 2>/dev/null || true
echo " Ambiente limpo"
# Criar namespace
echo "[3/6] Criando namespace de teste..."
kubectl create namespace $NAMESPACE
kubectl create secret docker-registry gitea-registry \
--docker-server=gitea.kube.quest \
--docker-username=root \
--docker-password="${GITEA_TOKEN:-glpat-dummy}" \
-n $NAMESPACE 2>/dev/null || true
echo " Namespace criado"
# Teste 1: Imagem tradicional
echo ""
echo "========================================================================"
echo "[4/6] TESTE 1: Imagem Tradicional (gzip) - PULL REAL"
echo "========================================================================"
echo "Iniciando em $(date)"
T1_START=$(date +%s)
cat <<EOF | kubectl apply -f -
apiVersion: v1
kind: Pod
metadata:
name: pg-traditional
namespace: $NAMESPACE
spec:
nodeName: $TARGET_NODE
restartPolicy: Never
containers:
- name: postgres
image: $TRADITIONAL_IMAGE
imagePullPolicy: Always
env:
- name: POSTGRES_PASSWORD
value: benchmarktest
securityContext:
allowPrivilegeEscalation: false
capabilities:
drop: ["ALL"]
seccompProfile:
type: RuntimeDefault
EOF
kubectl wait --for=condition=Ready pod/pg-traditional -n $NAMESPACE --timeout=300s
T1_END=$(date +%s)
TIME1=$((T1_END - T1_START))
echo "Finalizado em $(date)"
echo ">>> Tempo total: ${TIME1}s <<<"
# Teste 2: Imagem eStargz
echo ""
echo "========================================================================"
echo "[5/6] TESTE 2: Imagem eStargz (lazy pulling) - PULL REAL"
echo "========================================================================"
echo "Iniciando em $(date)"
T2_START=$(date +%s)
cat <<EOF | kubectl apply -f -
apiVersion: v1
kind: Pod
metadata:
name: pg-estargz
namespace: $NAMESPACE
spec:
nodeName: $TARGET_NODE
restartPolicy: Never
imagePullSecrets:
- name: gitea-registry
containers:
- name: postgres
image: $ESTARGZ_IMAGE
imagePullPolicy: Always
env:
- name: POSTGRES_PASSWORD
value: benchmarktest
securityContext:
allowPrivilegeEscalation: false
capabilities:
drop: ["ALL"]
seccompProfile:
type: RuntimeDefault
EOF
kubectl wait --for=condition=Ready pod/pg-estargz -n $NAMESPACE --timeout=300s
T2_END=$(date +%s)
TIME2=$((T2_END - T2_START))
echo "Finalizado em $(date)"
echo ">>> Tempo total: ${TIME2}s <<<"
# Resultados
echo ""
echo "========================================================================"
echo "[6/6] RESULTADOS"
echo "========================================================================"
echo ""
# Status dos pods
echo "Status dos Pods:"
kubectl get pods -n $NAMESPACE -o wide
echo ""
# Eventos completos
echo "Todos os Eventos (ordenados por tempo):"
kubectl get events -n $NAMESPACE --sort-by='.lastTimestamp' \
-o custom-columns='TIMESTAMP:.lastTimestamp,REASON:.reason,POD:.involvedObject.name,MESSAGE:.message'
echo ""
# Verificar se houve pull real
echo "Análise de Pull:"
TRAD_PULL=$(kubectl get events -n $NAMESPACE --field-selector involvedObject.name=pg-traditional,reason=Pulled -o jsonpath='{.items[0].message}' 2>/dev/null)
ESTARGZ_PULL=$(kubectl get events -n $NAMESPACE --field-selector involvedObject.name=pg-estargz,reason=Pulled -o jsonpath='{.items[0].message}' 2>/dev/null)
echo " Tradicional: $TRAD_PULL"
echo " eStargz: $ESTARGZ_PULL"
echo ""
# Tabela de resultados
echo "┌─────────────────────────────────────────────────────────────────┐"
echo "│ RESULTADOS DO BENCHMARK (PULL REAL) │"
echo "├───────────────────┬─────────────────┬─────────────────────────────┤"
echo "│ Métrica │ Tradicional │ eStargz │"
echo "├───────────────────┼─────────────────┼─────────────────────────────┤"
printf "│ Tempo até Ready │ %12ss │ %12ss │\n" "$TIME1" "$TIME2"
echo "├───────────────────┼─────────────────┼─────────────────────────────┤"
if [ "$TIME1" -gt "$TIME2" ]; then
DIFF=$((TIME1 - TIME2))
PERCENT=$(( (DIFF * 100) / TIME1 ))
echo "│ Diferença │ baseline │ -${DIFF}s (${PERCENT}% mais rápido) │"
elif [ "$TIME2" -gt "$TIME1" ]; then
DIFF=$((TIME2 - TIME1))
PERCENT=$(( (DIFF * 100) / TIME2 ))
echo "│ Diferença │ +${DIFF}s mais rápido │ baseline │"
else
echo "│ Diferença │ igual │ igual │"
fi
echo "└───────────────────┴─────────────────┴─────────────────────────────┘"
echo ""
echo "Nota: Este benchmark usou imagePullPolicy: Always no node '$TARGET_NODE'"
echo " que não tinha as imagens em cache, forçando pull real."
echo ""
echo "O benefício do eStargz (lazy pulling) é mais significativo em:"
echo " - Imagens maiores (1GB+)"
echo " - Scale-out events (novos nodes)"
echo " - Cold starts"
echo ""
echo "Para limpar: kubectl delete namespace $NAMESPACE"