diff --git a/create_cluster.sh b/create_cluster.sh index ec7ad88..06130a0 100755 --- a/create_cluster.sh +++ b/create_cluster.sh @@ -1,25 +1,36 @@ #!/bin/bash -# Set the desired configuration -KIND_VERSION="v0.20.0" -CLUSTER_NAME="local-k8s" -NODES=2 +# Define the version of Kind to be used, the name of the cluster to be created, and the number of nodes in the cluster +KIND_VERSION="${KIND_VERSION:-v0.20.0}" +CLUSTER_NAME="${CLUSTER_NAME:-local-k8s}" +NODES="${NODES:-3}" -# Function to delete an existing Kind cluster +# Function to delete the Kind cluster if it is already running delete_cluster() { local cluster_name=$1 + + # Check if the cluster is already running if kind get clusters | grep -q "^$cluster_name$"; then echo "Kind cluster '$cluster_name' is already running. Deleting the cluster..." + + # Delete the running cluster kind delete cluster --name "$cluster_name" fi } -# Function to install Kind if not already installed +# Function to install Kind if it is not already installed install_kind() { + # Check if Kind is installed if ! command -v kind &> /dev/null; then echo "Kind not found. Installing Kind..." + + # Download Kind from the official repository curl -Lo ./kind "https://github.com/kubernetes-sigs/kind/releases/download/${KIND_VERSION}/kind-linux-amd64" + + # Make the downloaded file executable chmod +x ./kind + + # Move the executable file to the local bin directory sudo mv ./kind /usr/local/bin/kind fi } @@ -29,6 +40,8 @@ create_cluster() { local cluster_name=$1 local nodes=$2 echo "Creating Kind cluster: $cluster_name with $nodes nodes..." + + # Create the cluster with the specified configuration cat <