-
Notifications
You must be signed in to change notification settings - Fork 2
/
kubectl-kind
executable file
·48 lines (39 loc) · 1.08 KB
/
kubectl-kind
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/usr/bin/env bash
# kubectl-kind - Kubernetes wrapper for creating a kind cluster
set -euo pipefail
CLUSTER_NAME="local"
# Function to print messages with formatting
print_message() {
printf "\n== %s ==\n\n" "$1"
}
# Function to handle errors
error_exit() {
echo "Error: $1" >&2
exit 1
}
print_message "Deleting existing kind cluster (if it exists)"
if kind delete cluster -n "$CLUSTER_NAME"; then
echo "Cluster deleted successfully."
else
echo "No existing cluster to delete or deletion failed. Proceeding with cluster creation..."
fi
print_message "Creating new kind cluster"
# Define the cluster configuration and apply it using ctlptl
cat <<HEREDOC | ctlptl apply -f - || error_exit "Failed to create kind cluster"
apiVersion: ctlptl.dev/v1alpha1
kind: Registry
name: ctlptl-registry
port: 20021
---
apiVersion: ctlptl.dev/v1alpha1
kind: Cluster
product: kind
registry: ctlptl-registry
kindV1Alpha4Cluster:
name: $CLUSTER_NAME
networking:
apiServerPort: 20022
nodes:
- role: control-plane
HEREDOC
echo "Kind cluster '$CLUSTER_NAME' created successfully."