Created
October 6, 2025 13:17
-
-
Save Cali0707/644000f032cc9228b6e7b07da4db9d81 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| set -e | |
| # Function to display usage | |
| usage() { | |
| echo "Usage: $0 <number_of_clusters>" | |
| echo "Example: $0 3" | |
| exit 1 | |
| } | |
| # Check if argument is provided | |
| if [ $# -ne 1 ]; then | |
| usage | |
| fi | |
| # Validate the input is a positive integer | |
| if ! [[ "$1" =~ ^[1-9][0-9]*$ ]]; then | |
| echo "Error: Please provide a positive integer" | |
| usage | |
| fi | |
| N=$1 | |
| echo "Starting $N kind clusters serially..." | |
| cluster_names=() | |
| # Create clusters one at a time | |
| for i in $(seq 1 $N); do | |
| cluster_name="cluster-$i" | |
| cluster_names+=("$cluster_name") | |
| echo "Creating cluster: $cluster_name" | |
| if kind create cluster --name "$cluster_name"; then | |
| echo "✓ Cluster $cluster_name created successfully" | |
| else | |
| echo "✗ Failed to create cluster $cluster_name" | |
| exit 1 | |
| fi | |
| echo "Waiting for $cluster_name to be ready..." | |
| # Wait for cluster to be ready with timeout | |
| timeout=300 # 5 minutes timeout | |
| elapsed=0 | |
| interval=5 | |
| while [ $elapsed -lt $timeout ]; do | |
| if kubectl cluster-info --context "kind-$cluster_name" >/dev/null 2>&1; then | |
| echo "✓ Cluster $cluster_name is ready" | |
| break | |
| fi | |
| sleep $interval | |
| elapsed=$((elapsed + interval)) | |
| if [ $elapsed -ge $timeout ]; then | |
| echo "✗ Timeout waiting for $cluster_name to be ready" | |
| exit 1 | |
| fi | |
| done | |
| echo "" | |
| done | |
| echo "🎉 All $N clusters are ready!" | |
| echo "" | |
| echo "Cluster contexts:" | |
| for cluster_name in "${cluster_names[@]}"; do | |
| echo " kind-$cluster_name" | |
| done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment