-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsetup.sh
executable file
·51 lines (44 loc) · 1.66 KB
/
setup.sh
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
49
50
51
#!/bin/bash
source config.sh
create_docker_network() {
local network_name=$1
if docker network inspect $network_name >/dev/null 2>&1; then
echo "Docker network '$network_name' already exists. Skipping creation."
else
echo "Creating Docker network '$network_name'..."
docker network create $network_name || { echo "Failed to create network $network_name"; exit 1; }
fi
}
create_k3d_cluster() {
local cluster_name=$1
local api_port=$2
local network_name=$3
local pod_cidr=$4
if k3d cluster list | grep -q "^$cluster_name "; then
echo "k3d cluster '$cluster_name' already exists. Skipping creation."
else
echo "Creating k3d cluster '$cluster_name'..."
k3d cluster create $cluster_name \
--api-port $api_port \
--network $network_name \
--agents 0 \
--servers 1 \
--k3s-arg "--tls-san=$HOST_IP@server:0" \
--k3s-arg "--cluster-cidr=$pod_cidr@server:0" \
|| { echo "Failed to create cluster '$cluster_name'"; exit 1; }
fi
}
# Create Docker networks
create_docker_network $NETWORK1
create_docker_network $NETWORK2
# Create k3d clusters
create_k3d_cluster $CLUSTER1 $API_PORT1 $NETWORK1 10.31.0.0/16
create_k3d_cluster $CLUSTER2 $API_PORT2 $NETWORK2 10.41.0.0/16
# Verify clusters
echo "Verifying clusters..."
kubectl config set-cluster $CLUSTER1 --server https://$HOST_IP:$API_PORT1
kubectl config set-cluster $CLUSTER2 --server https://$HOST_IP:$API_PORT2
echo "Clusters created successfully."
echo "To access the clusters:"
echo " kubectl config use-context k3d-$CLUSTER1"
echo " kubectl config use-context k3d-$CLUSTER2"