File size: 8,581 Bytes
edcd2ef | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 | #!/bin/bash
# Final Verification Script for Phase 5
# Verifies all components are properly configured and deployed
#
set -e
# Colors
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m'
echo -e "${BLUE}========================================${NC}"
echo -e "${BLUE}Phase 5 Final Verification${NC}"
echo -e "${BLUE}========================================${NC}"
echo ""
FAILURES=0
WARNINGS=0
# 1. Check Kubernetes cluster connectivity
echo -e "${YELLOW}1. Checking Kubernetes cluster...${NC}"
if kubectl cluster-info > /dev/null 2>&1; then
echo -e "${GREEN}β Kubernetes cluster is accessible${NC}"
echo " Cluster: $(kubectl config current-context)"
else
echo -e "${RED}β Cannot connect to Kubernetes cluster${NC}"
FAILURES=$((FAILURES + 1))
fi
# 2. Check namespace
echo ""
echo -e "${YELLOW}2. Checking namespace...${NC}"
if kubectl get namespace phase-5 > /dev/null 2>&1; then
echo -e "${GREEN}β Namespace 'phase-5' exists${NC}"
else
echo -e "${YELLOW}β Namespace 'phase-5' not found${NC}"
echo " Run: kubectl create namespace phase-5"
WARNINGS=$((WARNINGS + 1))
fi
# 3. Check deployments
echo ""
echo -e "${YELLOW}3. Checking deployments...${NC}"
DEPLOYMENTS=("backend" "notification" "postgres")
for deployment in "${DEPLOYMENTS[@]}"; do
if kubectl get deployment "$deployment" -n phase-5 > /dev/null 2>&1; then
READY_REPLICAS=$(kubectl get deployment "$deployment" -n phase-5 -o jsonpath='{.status.readyReplicas}')
DESIRED_REPLICAS=$(kubectl get deployment "$deployment" -n phase-5 -o jsonpath='{.spec.replicas}')
if [ "$READY_REPLICAS" == "$DESIRED_REPLICAS" ]; then
echo -e "${GREEN}β Deployment '$deployment' is ready (${READY_REPLICAS}/${DESIRED_REPLICAS})${NC}"
else
echo -e "${YELLOW}β Deployment '$deployment' not ready (${READY_REPLICAS}/${DESIRED_REPLICAS})${NC}"
WARNINGS=$((WARNINGS + 1))
fi
else
echo -e "${RED}β Deployment '$deployment' not found${NC}"
FAILURES=$((FAILURES + 1))
fi
done
# 4. Check pods
echo ""
echo -e "${YELLOW}4. Checking pods...${NC}"
PODS=$(kubectl get pods -n phase-5 --no-headers 2>/dev/null | wc -l)
RUNNING=$(kubectl get pods -n phase-5 --no-headers 2>/dev/null | grep "Running" | wc -l)
if [ "$PODS" -gt 0 ]; then
echo -e "${GREEN}β Found ${PODS} pods (${RUNNING} running)${NC}"
# Check for failing pods
FAILED=$(kubectl get pods -n phase-5 --no-headers 2>/dev/null | grep -v "Running\|Completed" | wc -l)
if [ "$FAILED" -gt 0 ]; then
echo -e "${YELLOW}β ${FAILED} pods are not running${NC}"
kubectl get pods -n phase-5 | grep -v "Running\|Completed"
WARNINGS=$((WARNINGS + 1))
fi
else
echo -e "${YELLOW}β No pods found${NC}"
WARNINGS=$((WARNINGS + 1))
fi
# 5. Check services
echo ""
echo -e "${YELLOW}5. Checking services...${NC}"
SERVICES=("backend-service" "notification-service" "postgres")
for service in "${SERVICES[@]}"; do
if kubectl get service "$service" -n phase-5 > /dev/null 2>&1; then
TYPE=$(kubectl get service "$service" -n phase-5 -o jsonpath='{.spec.type}')
echo -e "${GREEN}β Service '$service' exists (${TYPE})${NC}"
else
echo -e "${YELLOW}β Service '$service' not found${NC}"
WARNINGS=$((WARNINGS + 1))
fi
done
# 6. Check ingress
echo ""
echo -e "${YELLOW}6. Checking ingress...${NC}"
INGRESS=$(kubectl get ingress -n phase-5 --no-headers 2>/dev/null | wc -l)
if [ "$INGRESS" -gt 0 ]; then
echo -e "${GREEN}β Found ${INGRESS} ingress resources${NC}"
# Check TLS configuration
TLS_INGRESS=$(kubectl get ingress -n phase-5 -o json | jq '.items[] | select(.spec.tls != null) | .metadata.name' | wc -l)
if [ "$TLS_INGRESS" -gt 0 ]; then
echo -e "${GREEN}β ${TLS_INGRESS} ingress resources have TLS configured${NC}"
else
echo -e "${YELLOW}β No TLS configured on ingress${NC}"
WARNINGS=$((WARNINGS + 1))
fi
else
echo -e "${YELLOW}β No ingress resources found${NC}"
WARNINGS=$((WARNINGS + 1))
fi
# 7. Check certificates
echo ""
echo -e "${YELLOW}7. Checking TLS certificates...${NC}"
if kubectl get certificates -n phase-5 > /dev/null 2>&1; then
CERTS=$(kubectl get certificates -n phase-5 --no-headers | wc -l)
echo -e "${GREEN}β Found ${CERTS} certificates${NC}"
# Check certificate status
READY_CERTS=$(kubectl get certificates -n phase-5 -o json | jq '.items[] | select(.status.conditions[].status == "True") | .metadata.name' | wc -l)
if [ "$READY_CERTS" -eq "$CERTS" ]; then
echo -e "${GREEN}β All certificates are ready${NC}"
else
echo -e "${YELLOW}β Some certificates are not ready${NC}"
kubectl get certificates -n phase-5
WARNINGS=$((WARNINGS + 1))
fi
else
echo -e "${YELLOW}β No certificates found (cert-manager may not be installed)${NC}"
WARNINGS=$((WARNINGS + 1))
fi
# 8. Check HPA
echo ""
echo -e "${YELLOW}8. checking Horizontal Pod Autoscalers...${NC}"
if kubectl get hpa -n phase-5 > /dev/null 2>&1; then
HPA_COUNT=$(kubectl get hpa -n phase-5 --no-headers | wc -l)
echo -e "${GREEN}β Found ${HPA_COUNT} HPA resources${NC}"
kubectl get hpa -n phase-5
else
echo -e "${YELLOW}β No HPA resources found${NC}"
echo " Run: kubectl apply -f k8s/autoscaler.yaml"
WARNINGS=$((WARNINGS + 1))
fi
# 9. Check secrets
echo ""
echo -e "${YELLOW}9. Checking secrets...${NC}"
SECRETS=("db-credentials" "ollama-config")
for secret in "${SECRETS[@]}"; do
if kubectl get secret "$secret" -n phase-5 > /dev/null 2>&1; then
echo -e "${GREEN}β Secret '$secret' exists${NC}"
else
echo -e "${RED}β Secret '$secret' not found${NC}"
echo " Run: kubectl create secret generic $secret --from-literal=..."
FAILURES=$((FAILURES + 1))
fi
done
# 10. Check monitoring
echo ""
echo -e "${YELLOW}10. Checking monitoring stack...${NC}"
# Check Prometheus
if kubectl get svc prometheus-kube-prometheus-prometheus -n monitoring > /dev/null 2>&1; then
echo -e "${GREEN}β Prometheus is running${NC}"
else
echo -e "${YELLOW}β Prometheus not found in monitoring namespace${NC}"
WARNINGS=$((WARNINGS + 1))
fi
# Check Grafana
if kubectl get svc grafana -n monitoring > /dev/null 2>&1; then
echo -e "${GREEN}β Grafana is running${NC}"
else
echo -e "${YELLOW}β Grafana not found in monitoring namespace${NC}"
WARNINGS=$((WARNINGS + 1))
fi
# 11. Check Dapr
echo ""
echo -e "${YELLOW}11. Checking Dapr sidecars...${NC}"
DAPR_PODS=$(kubectl get pods -n phase-5 -o json | jq '.items[] | select(.spec.containers[].name == "daprd") | .metadata.name' | wc -l)
if [ "$DAPR_PODS" -gt 0 ]; then
echo -e "${GREEN}β Dapr sidecars are injected (${DAPR_PODS} pods)${NC}"
else
echo -e "${YELLOW}β Dapr sidecars not found${NC}"
WARNINGS=$((WARNINGS + 1))
fi
# 12. Run health check
echo ""
echo -e "${YELLOW}12. Running health check...${NC}"
# Port forward to backend
BACKEND_POD=$(kubectl get pod -n phase-5 -l app=backend -o jsonpath='{.items[0].metadata.name}' 2>/dev/null)
if [ -n "$BACKEND_POD" ]; then
echo " Forwarding port to pod: ${BACKEND_POD}"
# Start port forward in background
kubectl port-forward -n phase-5 pod/$BACKEND_POD 8000:8000 > /dev/null 2>&1 &
PF_PID=$!
# Wait for port forward to be ready
sleep 3
# Run health check
if curl -s http://localhost:8000/health | grep -q "healthy"; then
echo -e "${GREEN}β Backend health check passed${NC}"
else
echo -e "${RED}β Backend health check failed${NC}"
FAILURES=$((FAILURES + 1))
fi
# Kill port forward
kill $PF_PID 2>/dev/null
else
echo -e "${YELLOW}β Could not find backend pod${NC}"
WARNINGS=$((WARNINGS + 1))
fi
# Summary
echo ""
echo -e "${BLUE}========================================${NC}"
echo -e "${BLUE}Verification Summary${NC}"
echo -e "${BLUE}========================================${NC}"
echo ""
if [ $FAILURES -eq 0 ] && [ $WARNINGS -eq 0 ]; then
echo -e "${GREEN}β All checks passed! System is ready for production.${NC}"
echo ""
echo "Next steps:"
echo " 1. Configure DNS records for your domain"
echo " 2. Verify SSL certificates are issued"
echo " 3. Run security scan: ./scripts/security-scan.sh"
echo " 4. Run performance tests: ./scripts/performance-test.sh"
echo " 5. Monitor Grafana dashboards"
exit 0
elif [ $FAILURES -eq 0 ]; then
echo -e "${YELLOW}β System is operational with ${WARNINGS} warnings${NC}"
echo " Review warnings above and address if needed"
exit 0
else
echo -e "${RED}β Found ${FAILURES} failures and ${WARNINGS} warnings${NC}"
echo " Please address the failures before deploying to production"
exit 1
fi
|