-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathup-cluster.sh
executable file
·67 lines (50 loc) · 1.88 KB
/
up-cluster.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/bin/bash
set -e
# parameters
if [ $# -ne 1 ]; then
echo "Usage: $0 <project-id>"
echo "Example: $0 my-gcp-project"
exit 1
fi
# create GCS bucket
terraform apply -auto-approve
# Configuration variables
CLUSTER_NAME="oxn.dev.com" # If you want to change the cluster name, you need to update the variable in down-cluster.sh
PROJECT_ID=$1 # GCP project ID
ZONE="europe-west1-b" # Single zone since HA is not needed
NODE_COUNT=3
CONTROL_PLANE_SIZE="e2-standard-2"
NODE_SIZE="e2-standard-2"
# Get the state store bucket name from Terraform output
export KOPS_STATE_STORE="gs://$(terraform output -raw kops_state_store_bucket_name)"
# Create the cluster configuration
echo "Creating cluster configuration..."
kops create cluster \
--name="${CLUSTER_NAME}" \
--state="${KOPS_STATE_STORE}" \
--zones="${ZONE}" \
--control-plane-zones="${ZONE}" \
--node-count="${NODE_COUNT}" \
--control-plane-size="${CONTROL_PLANE_SIZE}" \
--node-size="${NODE_SIZE}" \
--control-plane-count=1 \
--networking=cilium \
--cloud=gce \
--project="${PROJECT_ID}" \
# Get the instance group specs
echo "Modifying instance groups to use spot instances..."
kops get ig --name "${CLUSTER_NAME}" -o yaml > ig_specs.yaml
# Use sed to modify the instance group specs to use spot instances
# This adds the gcpProvisioningModel: SPOT to both node and control-plane specs
sed -i '/spec:/a\ gcpProvisioningModel: SPOT' ig_specs.yaml
# Apply the modified instance group specs
echo "Applying modified instance group configurations..."
kops replace -f ig_specs.yaml
# Create the cluster
echo "Creating the cluster..."
kops update cluster --name="${CLUSTER_NAME}" --yes
# Update your kubeconfig
kops export kubeconfig --admin
# Wait for the cluster to be ready
echo "Waiting for cluster to be ready..."
kops validate cluster --wait 10m