#!/bin/bash # ============================================================================= # Benchmark: eStargz vs Traditional Image Pull # ============================================================================= # # Compara tempo de startup entre: # - postgres:17-alpine (gzip tradicional) # - registry.kube.quest/factory/postgresql:17 (eStargz) # # Este script usa timestamps dos eventos do Kubernetes para medir: # - Tempo de pull (Pulling -> Pulled) # - Tempo total (Scheduled -> Started) # # ============================================================================= set -e NAMESPACE="benchmark-test" ESTARGZ_IMAGE="registry.kube.quest/factory/postgresql:17" TRADITIONAL_IMAGE="postgres:17-alpine" echo "========================================================================" echo "Benchmark: eStargz vs Traditional Image Pull" echo "========================================================================" 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 gitlab-registry \ --docker-server=registry.kube.quest \ --docker-username=root \ --docker-password="${GITLAB_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)" echo "========================================================================" T1_START=$(date +%s) kubectl run pg-traditional --image=$TRADITIONAL_IMAGE --restart=Never \ --env=POSTGRES_PASSWORD=benchmarktest \ -n $NAMESPACE 2>&1 | grep -v "Warning:" kubectl wait --for=condition=Ready pod/pg-traditional -n $NAMESPACE --timeout=180s T1_END=$(date +%s) TIME1=$((T1_END - T1_START)) echo "Tempo total: ${TIME1}s" # Teste 2: Imagem eStargz echo "" echo "========================================================================" echo "[5/6] TESTE 2: Imagem eStargz (lazy pulling)" echo "========================================================================" T2_START=$(date +%s) kubectl run pg-estargz --image=$ESTARGZ_IMAGE --restart=Never \ --env=POSTGRES_PASSWORD=benchmarktest \ --overrides='{"spec":{"imagePullSecrets":[{"name":"gitlab-registry"}]}}' \ -n $NAMESPACE 2>&1 | grep -v "Warning:" kubectl wait --for=condition=Ready pod/pg-estargz -n $NAMESPACE --timeout=180s T2_END=$(date +%s) TIME2=$((T2_END - T2_START)) 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 ou cache hit 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 │" echo "├───────────────────┬─────────────────┬─────────────────────────────┤" echo "│ Métrica │ Tradicional │ eStargz │" echo "├───────────────────┼─────────────────┼─────────────────────────────┤" printf "│ Tempo até Ready │ %12ss │ %12ss │\n" "$TIME1" "$TIME2" echo "├───────────────────┼─────────────────┼─────────────────────────────┤" if [ "$TIME1" -gt 0 ] && [ "$TIME2" -gt 0 ]; then if [ "$TIME1" -gt "$TIME2" ]; then DIFF=$((TIME1 - TIME2)) echo "│ Diferença │ baseline │ -${DIFF}s mais rápido │" elif [ "$TIME2" -gt "$TIME1" ]; then DIFF=$((TIME2 - TIME1)) echo "│ Diferença │ -${DIFF}s mais rápido │ baseline │" else echo "│ Diferença │ igual │ igual │" fi fi echo "└───────────────────┴─────────────────┴─────────────────────────────┘" # Verificar cache hit if echo "$TRAD_PULL" | grep -q "already present"; then TRAD_CACHED="SIM" else TRAD_CACHED="NAO" fi if echo "$ESTARGZ_PULL" | grep -q "already present"; then ESTARGZ_CACHED="SIM" else ESTARGZ_CACHED="NAO" fi echo "" echo "Cache Status:" echo " Tradicional em cache: $TRAD_CACHED" echo " eStargz em cache: $ESTARGZ_CACHED" if [ "$TRAD_CACHED" = "SIM" ] || [ "$ESTARGZ_CACHED" = "SIM" ]; then echo "" echo "AVISO: Imagens em cache - benchmark não reflete tempo real de pull!" echo "" echo "Para benchmark preciso, limpe o cache dos worker nodes com:" echo "" echo " # Via talosctl (para cada worker node):" echo " export TALOSCONFIG=/private/data/app/workshop/aula-08/talosconfig" echo " WORKER_IP=46.224.192.153 # IP do worker" echo " talosctl -n \$WORKER_IP service restart containerd" echo "" echo " # OU escale um novo worker sem cache" fi echo "" echo "Namespace de teste mantido. Para limpar:" echo " kubectl delete namespace $NAMESPACE"