|
|
#!/bin/bash |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
set -e |
|
|
|
|
|
|
|
|
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 |
|
|
|
|
|
|
|
|
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 |
|
|
|
|
|
|
|
|
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 |
|
|
|
|
|
|
|
|
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 |
|
|
|
|
|
|
|
|
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}" |
|
|
|
|
|
|
|
|
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 |
|
|
|
|
|
|
|
|
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 |
|
|
|
|
|
|
|
|
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}" |
|
|
|
|
|
|
|
|
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 |
|
|
|
|
|
|
|
|
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}" |
|
|
|
|
|
|
|
|
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 |
|
|
|
|
|
|
|
|
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 |
|
|
|
|
|
|
|
|
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 |
|
|
|
|
|
|
|
|
echo "" |
|
|
echo -e "${YELLOW}10. Checking monitoring stack...${NC}" |
|
|
|
|
|
|
|
|
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 |
|
|
|
|
|
|
|
|
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 |
|
|
|
|
|
|
|
|
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 |
|
|
|
|
|
|
|
|
echo "" |
|
|
echo -e "${YELLOW}12. Running health check...${NC}" |
|
|
|
|
|
|
|
|
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}" |
|
|
|
|
|
|
|
|
kubectl port-forward -n phase-5 pod/$BACKEND_POD 8000:8000 > /dev/null 2>&1 & |
|
|
PF_PID=$! |
|
|
|
|
|
|
|
|
sleep 3 |
|
|
|
|
|
|
|
|
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 $PF_PID 2>/dev/null |
|
|
else |
|
|
echo -e "${YELLOW}β Could not find backend pod${NC}" |
|
|
WARNINGS=$((WARNINGS + 1)) |
|
|
fi |
|
|
|
|
|
|
|
|
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 |
|
|
|