feat: Setup KIND cluster for local Kubernetes development
- Created 5-node KIND cluster (1 control-plane + 4 workers) - Configured NodePort mappings for console access (30080, 30081) - Created namespace separation (site11-console, site11-pipeline) - Deployed MongoDB and Redis in KIND cluster - Deployed Console backend and frontend with NodePort services - All 4 pods running successfully and verified with browser test Infrastructure: - k8s/kind-dev-cluster.yaml: 5-node cluster configuration - k8s/kind/console-mongodb-redis.yaml: Database deployments - k8s/kind/console-backend.yaml: Backend with NodePort - k8s/kind/console-frontend.yaml: Frontend with NodePort Management Tools: - scripts/kind-setup.sh: Comprehensive cluster management script - docker-compose.kubernetes.yml: Monitoring helper services Documentation: - KUBERNETES.md: Complete usage guide for developers - docs/KIND_SETUP.md: Detailed KIND setup documentation - docs/PROGRESS.md: Updated with KIND cluster completion Console Services Access: - Frontend: http://localhost:3000 (NodePort 30080) - Backend: http://localhost:8000 (NodePort 30081) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
225
scripts/kind-setup.sh
Executable file
225
scripts/kind-setup.sh
Executable file
@ -0,0 +1,225 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Site11 KIND Cluster Setup Script
|
||||
# This script manages the KIND (Kubernetes IN Docker) development cluster
|
||||
|
||||
set -e
|
||||
|
||||
CLUSTER_NAME="site11-dev"
|
||||
CONFIG_FILE="k8s/kind-dev-cluster.yaml"
|
||||
K8S_DIR="k8s/kind"
|
||||
|
||||
# Colors for output
|
||||
RED='\033[0;31m'
|
||||
GREEN='\033[0;32m'
|
||||
YELLOW='\033[1;33m'
|
||||
NC='\033[0m' # No Color
|
||||
|
||||
echo -e "${GREEN}=====================================${NC}"
|
||||
echo -e "${GREEN}Site11 KIND Cluster Manager${NC}"
|
||||
echo -e "${GREEN}=====================================${NC}"
|
||||
echo ""
|
||||
|
||||
# Check if KIND is installed
|
||||
if ! command -v kind &> /dev/null; then
|
||||
echo -e "${RED}ERROR: kind is not installed${NC}"
|
||||
echo "Please install KIND: https://kind.sigs.k8s.io/docs/user/quick-start/#installation"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Check if kubectl is installed
|
||||
if ! command -v kubectl &> /dev/null; then
|
||||
echo -e "${RED}ERROR: kubectl is not installed${NC}"
|
||||
echo "Please install kubectl: https://kubernetes.io/docs/tasks/tools/"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Function to create cluster
|
||||
create_cluster() {
|
||||
echo -e "${YELLOW}Creating KIND cluster: $CLUSTER_NAME${NC}"
|
||||
|
||||
if kind get clusters | grep -q "^$CLUSTER_NAME$"; then
|
||||
echo -e "${YELLOW}Cluster $CLUSTER_NAME already exists${NC}"
|
||||
read -p "Do you want to delete and recreate? (y/N): " -n 1 -r
|
||||
echo
|
||||
if [[ $REPLY =~ ^[Yy]$ ]]; then
|
||||
delete_cluster
|
||||
else
|
||||
echo "Skipping cluster creation"
|
||||
return
|
||||
fi
|
||||
fi
|
||||
|
||||
kind create cluster --config "$CONFIG_FILE"
|
||||
echo -e "${GREEN}✅ Cluster created successfully${NC}"
|
||||
|
||||
# Wait for cluster to be ready
|
||||
echo "Waiting for cluster to be ready..."
|
||||
kubectl wait --for=condition=Ready nodes --all --timeout=120s
|
||||
|
||||
echo -e "${GREEN}✅ All nodes are ready${NC}"
|
||||
}
|
||||
|
||||
# Function to delete cluster
|
||||
delete_cluster() {
|
||||
echo -e "${YELLOW}Deleting KIND cluster: $CLUSTER_NAME${NC}"
|
||||
kind delete cluster --name "$CLUSTER_NAME"
|
||||
echo -e "${GREEN}✅ Cluster deleted${NC}"
|
||||
}
|
||||
|
||||
# Function to deploy namespaces
|
||||
deploy_namespaces() {
|
||||
echo -e "${YELLOW}Creating namespaces${NC}"
|
||||
kubectl create namespace site11-console --dry-run=client -o yaml | kubectl apply -f -
|
||||
kubectl create namespace site11-pipeline --dry-run=client -o yaml | kubectl apply -f -
|
||||
echo -e "${GREEN}✅ Namespaces created${NC}"
|
||||
}
|
||||
|
||||
# Function to load images
|
||||
load_images() {
|
||||
echo -e "${YELLOW}Loading Docker images into KIND cluster${NC}"
|
||||
|
||||
images=(
|
||||
"yakenator/site11-console-backend:latest"
|
||||
"yakenator/site11-console-frontend:latest"
|
||||
)
|
||||
|
||||
for image in "${images[@]}"; do
|
||||
echo "Loading $image..."
|
||||
if docker image inspect "$image" &> /dev/null; then
|
||||
kind load docker-image "$image" --name "$CLUSTER_NAME"
|
||||
else
|
||||
echo -e "${YELLOW}Warning: Image $image not found locally, skipping${NC}"
|
||||
fi
|
||||
done
|
||||
|
||||
echo -e "${GREEN}✅ Images loaded${NC}"
|
||||
}
|
||||
|
||||
# Function to deploy console services
|
||||
deploy_console() {
|
||||
echo -e "${YELLOW}Deploying Console services${NC}"
|
||||
|
||||
# Deploy in order: databases first, then applications
|
||||
kubectl apply -f "$K8S_DIR/console-mongodb-redis.yaml"
|
||||
echo "Waiting for databases to be ready..."
|
||||
sleep 5
|
||||
|
||||
kubectl apply -f "$K8S_DIR/console-backend.yaml"
|
||||
kubectl apply -f "$K8S_DIR/console-frontend.yaml"
|
||||
|
||||
echo -e "${GREEN}✅ Console services deployed${NC}"
|
||||
}
|
||||
|
||||
# Function to check cluster status
|
||||
status() {
|
||||
echo -e "${YELLOW}Cluster Status${NC}"
|
||||
echo ""
|
||||
|
||||
if ! kind get clusters | grep -q "^$CLUSTER_NAME$"; then
|
||||
echo -e "${RED}Cluster $CLUSTER_NAME does not exist${NC}"
|
||||
return 1
|
||||
fi
|
||||
|
||||
echo "=== Nodes ==="
|
||||
kubectl get nodes
|
||||
echo ""
|
||||
|
||||
echo "=== Console Namespace Pods ==="
|
||||
kubectl get pods -n site11-console -o wide
|
||||
echo ""
|
||||
|
||||
echo "=== Console Services ==="
|
||||
kubectl get svc -n site11-console
|
||||
echo ""
|
||||
|
||||
echo "=== Pipeline Namespace Pods ==="
|
||||
kubectl get pods -n site11-pipeline -o wide 2>/dev/null || echo "No pods found"
|
||||
echo ""
|
||||
}
|
||||
|
||||
# Function to show logs
|
||||
logs() {
|
||||
namespace=${1:-site11-console}
|
||||
pod_name=${2:-}
|
||||
|
||||
if [ -z "$pod_name" ]; then
|
||||
echo "Available pods in namespace $namespace:"
|
||||
kubectl get pods -n "$namespace" --no-headers | awk '{print $1}'
|
||||
echo ""
|
||||
echo "Usage: $0 logs [namespace] [pod-name]"
|
||||
return
|
||||
fi
|
||||
|
||||
kubectl logs -n "$namespace" "$pod_name" -f
|
||||
}
|
||||
|
||||
# Function to access services
|
||||
access() {
|
||||
echo -e "${GREEN}Console Services Access Information${NC}"
|
||||
echo ""
|
||||
echo "Frontend: http://localhost:3000 (NodePort 30080)"
|
||||
echo "Backend: http://localhost:8000 (NodePort 30081)"
|
||||
echo ""
|
||||
echo "These services are accessible because they use NodePort type"
|
||||
echo "and are mapped in the KIND cluster configuration."
|
||||
}
|
||||
|
||||
# Function to setup everything
|
||||
setup() {
|
||||
echo -e "${GREEN}Setting up complete KIND development environment${NC}"
|
||||
create_cluster
|
||||
deploy_namespaces
|
||||
load_images
|
||||
deploy_console
|
||||
status
|
||||
access
|
||||
echo -e "${GREEN}✅ Setup complete!${NC}"
|
||||
}
|
||||
|
||||
# Main script logic
|
||||
case "${1:-}" in
|
||||
create)
|
||||
create_cluster
|
||||
;;
|
||||
delete)
|
||||
delete_cluster
|
||||
;;
|
||||
deploy-namespaces)
|
||||
deploy_namespaces
|
||||
;;
|
||||
load-images)
|
||||
load_images
|
||||
;;
|
||||
deploy-console)
|
||||
deploy_console
|
||||
;;
|
||||
status)
|
||||
status
|
||||
;;
|
||||
logs)
|
||||
logs "$2" "$3"
|
||||
;;
|
||||
access)
|
||||
access
|
||||
;;
|
||||
setup)
|
||||
setup
|
||||
;;
|
||||
*)
|
||||
echo "Usage: $0 {create|delete|deploy-namespaces|load-images|deploy-console|status|logs|access|setup}"
|
||||
echo ""
|
||||
echo "Commands:"
|
||||
echo " create - Create KIND cluster"
|
||||
echo " delete - Delete KIND cluster"
|
||||
echo " deploy-namespaces - Create namespaces"
|
||||
echo " load-images - Load Docker images into cluster"
|
||||
echo " deploy-console - Deploy console services"
|
||||
echo " status - Show cluster status"
|
||||
echo " logs [ns] [pod] - Show pod logs"
|
||||
echo " access - Show service access information"
|
||||
echo " setup - Complete setup (create + deploy everything)"
|
||||
echo ""
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
Reference in New Issue
Block a user