zkt26/sk1/pause-app.sh
2026-05-12 19:27:18 +02:00

55 lines
2.0 KiB
Bash
Executable File
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
# ==========================================
# pause-app.sh — Shuts down the AKS cluster, preserves the disk and data
#
# What this script does:
# 1. Deletes Kubernetes objects (pods removed cleanly)
# 2. Stops the entire AKS cluster → all VMs deallocated → compute billing ~$0
# 3. The PVC disk remains intact → data is preserved
# 4. ACR continues to exist (small cost: ~$5/month)
#
# Cost during pause: ~$25/month (disk + ACR + public IP + LB)
# vs. ~$183/month when fully running
# ==========================================
set -euo pipefail
# ==========================================
# LOGGER — source the shared library
# ==========================================
# shellcheck source=lib/logger.sh
source "$(dirname "$0")/lib/logger.sh" "pause"
trap 'log_error "Failure at line $LINENO. See $LOG_FILE"' ERR
RESOURCE_GROUP="ExamApp-RG"
AKS_NAME="ExamApp-AKS"
log_info "========================================"
log_info " Vigimeteo Pause (cost saving)"
log_info " Log: $LOG_FILE"
log_info "========================================"
# Step 1: Remove Kubernetes objects (cleanly releases resources)
if kubectl get namespace vigimeteo &>/dev/null; then
log_info "Deleting namespace vigimeteo..."
kubectl delete namespace vigimeteo
log_info "Namespace deleted."
else
log_warn "Namespace vigimeteo already absent."
fi
# Step 2: Stop the AKS cluster (deallocates all VMs — works on system node pools)
# az aks stop is preferred over nodepool scale --node-count 0 because system node
# pools cannot be scaled below minCount:1 and would return InvalidParameter.
log_info "Stopping AKS cluster '$AKS_NAME' (deallocating all VMs)..."
az aks stop \
--resource-group "$RESOURCE_GROUP" \
--name "$AKS_NAME"
log_info "AKS cluster stopped — all VMs deallocated."
log_info "========================================"
log_info "App paused."
log_info "PostgreSQL disk (PVC) is preserved."
log_info "Estimated cost: ~25 USD/month (disk + ACR + IP)"
log_info "To resume: ./resume-app.sh"
log_info "========================================"