mirror of
https://github.com/outbackdingo/alicloud-singapore.git
synced 2026-08-25 07:10:17 +00:00
- Creates VPC with 3 vswitches across availability zones - Creates security group with ports for all production services - Creates ACK managed Kubernetes cluster with 10 worker nodes - Auto-scaling up to 20 worker nodes - Creates SLB for load balancing - Includes deploy.sh script to apply cluster-all.yaml resources
131 lines
5.3 KiB
Bash
Executable File
131 lines
5.3 KiB
Bash
Executable File
#!/bin/bash
|
|
# Lingble Production Cluster Deployment Script
|
|
# This script deploys services from cluster-all.yaml to the new Singapore ACK cluster
|
|
|
|
set -e
|
|
|
|
CLUSTER_ALL_FILE="${CLUSTER_ALL_FILE:-/Users/dingo/cluster-all.yaml}"
|
|
TEMP_DIR="/tmp/lingble-deploy-$$"
|
|
|
|
echo "=== Lingble Production Cluster Deployment ==="
|
|
echo "Cluster All File: $CLUSTER_ALL_FILE"
|
|
echo "Target Region: Singapore (ap-southeast-1)"
|
|
|
|
# Check if kubeconfig exists
|
|
if [ ! -f "./kubeconfig" ]; then
|
|
echo "Error: kubeconfig file not found. Run 'terraform apply' first."
|
|
exit 1
|
|
fi
|
|
|
|
# Check if cluster-all.yaml exists
|
|
if [ ! -f "$CLUSTER_ALL_FILE" ]; then
|
|
echo "Error: cluster-all.yaml not found at $CLUSTER_ALL_FILE"
|
|
exit 1
|
|
fi
|
|
|
|
# Export kubeconfig
|
|
export KUBECONFIG=./kubeconfig
|
|
|
|
# Verify cluster connectivity
|
|
echo "Verifying cluster connectivity..."
|
|
kubectl cluster-info
|
|
|
|
# Create temp directory
|
|
mkdir -p "$TEMP_DIR"
|
|
|
|
# Extract namespaces from cluster-all.yaml
|
|
echo "Extracting namespaces..."
|
|
NAMESPACES=$(grep "namespace:" "$CLUSTER_ALL_FILE" | sed 's/.*namespace: //' | sort -u)
|
|
echo "Found namespaces: $NAMESPACES"
|
|
|
|
# Create namespaces
|
|
echo "Creating namespaces..."
|
|
for ns in $NAMESPACES; do
|
|
kubectl create namespace "$ns" --dry-run=client -o yaml | kubectl apply -f - 2>/dev/null || true
|
|
done
|
|
|
|
# Extract and apply resources
|
|
echo "Extracting resources from cluster-all.yaml..."
|
|
|
|
# Apply ServiceAccounts first
|
|
echo "Applying ServiceAccounts..."
|
|
kubectl get -f "$CLUSTER_ALL_FILE" --dry-run=client -o json 2>/dev/null | \
|
|
jq -r '.items[] | select(.kind == "ServiceAccount") | del(.status, .metadata.resourceVersion, .metadata.uid, .metadata.creationTimestamp, .metadata.generation)' | \
|
|
jq -s '.' | kubectl apply -f - 2>/dev/null || true
|
|
|
|
# Apply RBAC
|
|
echo "Applying RBAC resources..."
|
|
kubectl get -f "$CLUSTER_ALL_FILE" --dry-run=client -o json 2>/dev/null | \
|
|
jq -r '.items[] | select(.kind == "Role" or .kind == "RoleBinding" or .kind == "ClusterRole" or .kind == "ClusterRoleBinding") | del(.status, .metadata.resourceVersion, .metadata.uid, .metadata.creationTimestamp, .metadata.generation)' | \
|
|
jq -s '.' | kubectl apply -f - 2>/dev/null || true
|
|
|
|
# Apply ConfigMaps
|
|
echo "Applying ConfigMaps..."
|
|
kubectl get -f "$CLUSTER_ALL_FILE" --dry-run=client -o json 2>/dev/null | \
|
|
jq -r '.items[] | select(.kind == "ConfigMap") | del(.status, .metadata.resourceVersion, .metadata.uid, .metadata.creationTimestamp, .metadata.generation)' | \
|
|
jq -s '.' | kubectl apply -f - 2>/dev/null || true
|
|
|
|
# Apply Secrets
|
|
echo "Applying Secrets..."
|
|
kubectl get -f "$CLUSTER_ALL_FILE" --dry-run=client -o json 2>/dev/null | \
|
|
jq -r '.items[] | select(.kind == "Secret") | del(.status, .metadata.resourceVersion, .metadata.uid, .metadata.creationTimestamp, .metadata.generation)' | \
|
|
jq -s '.' | kubectl apply -f - 2>/dev/null || true
|
|
|
|
# Apply PersistentVolumeClaims
|
|
echo "Applying PersistentVolumeClaims..."
|
|
kubectl get -f "$CLUSTER_ALL_FILE" --dry-run=client -o json 2>/dev/null | \
|
|
jq -r '.items[] | select(.kind == "PersistentVolumeClaim") | del(.status, .metadata.resourceVersion, .metadata.uid, .metadata.creationTimestamp, .metadata.generation)' | \
|
|
jq -s '.' | kubectl apply -f - 2>/dev/null || true
|
|
|
|
# Apply Services
|
|
echo "Applying Services..."
|
|
kubectl get -f "$CLUSTER_ALL_FILE" --dry-run=client -o json 2>/dev/null | \
|
|
jq -r '.items[] | select(.kind == "Service") | del(.status, .metadata.resourceVersion, .metadata.uid, .metadata.creationTimestamp, .metadata.generation)' | \
|
|
jq -s '.' | kubectl apply -f - 2>/dev/null || true
|
|
|
|
# Apply Deployments
|
|
echo "Applying Deployments..."
|
|
kubectl get -f "$CLUSTER_ALL_FILE" --dry-run=client -o json 2>/dev/null | \
|
|
jq -r '.items[] | select(.kind == "Deployment") | del(.status, .metadata.resourceVersion, .metadata.uid, .metadata.creationTimestamp, .metadata.generation)' | \
|
|
jq -s '.' | kubectl apply -f - 2>/dev/null || true
|
|
|
|
# Apply StatefulSets
|
|
echo "Applying StatefulSets..."
|
|
kubectl get -f "$CLUSTER_ALL_FILE" --dry-run=client -o json 2>/dev/null | \
|
|
jq -r '.items[] | select(.kind == "StatefulSet") | del(.status, .metadata.resourceVersion, .metadata.uid, .metadata.creationTimestamp, .metadata.generation)' | \
|
|
jq -s '.' | kubectl apply -f - 2>/dev/null || true
|
|
|
|
# Apply Ingress
|
|
echo "Applying Ingress resources..."
|
|
kubectl get -f "$CLUSTER_ALL_FILE" --dry-run=client -o json 2>/dev/null | \
|
|
jq -r '.items[] | select(.kind == "Ingress") | del(.status, .metadata.resourceVersion, .metadata.uid, .metadata.creationTimestamp, .metadata.generation)' | \
|
|
jq -s '.' | kubectl apply -f - 2>/dev/null || true
|
|
|
|
# Apply remaining resources (DaemonSet, CronJob, Job, etc.)
|
|
echo "Applying other resources..."
|
|
kubectl get -f "$CLUSTER_ALL_FILE" --dry-run=client -o json 2>/dev/null | \
|
|
jq -r '.items[] | select(.kind == "DaemonSet" or .kind == "CronJob" or .kind == "Job" or .kind == "HorizontalPodAutoscaler") | del(.status, .metadata.resourceVersion, .metadata.uid, .metadata.creationTimestamp, .metadata.generation)' | \
|
|
jq -s '.' | kubectl apply -f - 2>/dev/null || true
|
|
|
|
# Cleanup
|
|
rm -rf "$TEMP_DIR"
|
|
|
|
echo "=== Deployment Complete ==="
|
|
|
|
# Show results
|
|
echo ""
|
|
echo "Namespaces:"
|
|
kubectl get ns
|
|
|
|
echo ""
|
|
echo "Deployments:"
|
|
kubectl get deployments -A 2>/dev/null | head -40
|
|
|
|
echo ""
|
|
echo "StatefulSets:"
|
|
kubectl get statefulsets -A 2>/dev/null | head -20
|
|
|
|
echo ""
|
|
echo "Services:"
|
|
kubectl get svc -A 2>/dev/null | head -40
|