-
Notifications
You must be signed in to change notification settings - Fork 1
/
gke1.sh
executable file
·76 lines (63 loc) · 2.26 KB
/
gke1.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
66
67
68
69
70
71
72
73
74
75
76
#!/bin/bash
# set -e
if [ -z "${GCP_PROJECT_ID}" ]; then
GCP_PROJECT_ID=$(gcloud config get-value project)
echo using default GCP project $GCP_PROJECT_ID
fi
CLUSTER_NAME=gke1
function create_cluster {
gcloud beta container clusters create "${CLUSTER_NAME}" \
--project "${GCP_PROJECT_ID}" --zone "us-east1-b" \
--no-enable-basic-auth \
--release-channel "regular" \
--machine-type "n1-standard-2" --image-type "COS" \
--disk-type "pd-standard" --disk-size "50" \
--metadata disable-legacy-endpoints=true \
--num-nodes "3" \
--default-max-pods-per-node "110" \
--scopes \
"https://www.googleapis.com/auth/devstorage.read_only",\
"https://www.googleapis.com/auth/logging.write",\
"https://www.googleapis.com/auth/monitoring",\
"https://www.googleapis.com/auth/servicecontrol",\
"https://www.googleapis.com/auth/service.management.readonly",\
"https://www.googleapis.com/auth/trace.append" \
--enable-stackdriver-kubernetes \
--enable-ip-alias \
--network "projects/${GCP_PROJECT_ID}/global/networks/default" \
--subnetwork "projects/${GCP_PROJECT_ID}/regions/us-east1/subnetworks/default" \
--no-enable-master-authorized-networks \
--addons HorizontalPodAutoscaling,HttpLoadBalancing,Istio,ApplicationManager \
--istio-config auth=MTLS_STRICT \
--enable-autoupgrade \
--enable-autorepair \
--max-surge-upgrade 1 \
--max-unavailable-upgrade 0 \
--labels project=bank-demo
sleep 5
}
function deploy_tools {
if [ -f "gcloud-config.json" ]; then
kubectl create secret generic gcloud-config --from-file=gcloud-config.json -n default
kubectl apply -f ext-dns.yaml -n default
else
echo ext-dns not deployed
echo did you get a service account key file?
fi
}
if [ "$1" = "--create" ]; then
echo creating cluster $CLUSTER_NAME
create_cluster
deploy_tools
fi
# delete existing gke1 context before retrieving a new one
kubectl config delete-context ${CLUSTER_NAME}
gcloud container clusters get-credentials ${CLUSTER_NAME}
OUTPUT=$(kubectl config get-contexts -o name | grep ${CLUSTER_NAME} | sort | head -1)
if [ -z "$OUTPUT" ]; then
echo Unable to get kubectl contexts, something is wrong...
echo to create a new cluster, use --create option
exit 1
fi
kubectl config rename-context ${OUTPUT} ${CLUSTER_NAME}
kubectl config get-contexts