Skip to content

Instantly share code, notes, and snippets.

@RiFi2k
Created August 26, 2020 21:45
Show Gist options
  • Save RiFi2k/9499243b217347cb160bf5c60c2137d4 to your computer and use it in GitHub Desktop.
Save RiFi2k/9499243b217347cb160bf5c60c2137d4 to your computer and use it in GitHub Desktop.
#!/bin/bash
#
# TMBI Kubernetes E2E Test
#
# Author: Reilly Lowery <https://github.com/rifi2k>
# Copyright: 45AIR
# Permission to copy and modify is granted under the MIT license
#===============================================================================
set -eo pipefail
. bin/common.bash
#===============================================================================
# Get the whitelist from the command arg
master_auth_networks="${1}"
function create_cluster() {
# Create cluster if it doesn't exist
if ! gcloud container clusters list | grep "${GCLOUD_K8S_CLUSTER}"; then
txt_echo "Creating ${GCLOUD_K8S_CLUSTER} - GKE in ${GCLOUD_REGION}"
gcloud beta container clusters create ${GCLOUD_K8S_CLUSTER} \
--preemptible \
--region="${GCLOUD_REGION}" \
--cluster-version ${cluster_version} \
--machine-type "n1-standard-8" \
--cluster-ipv4-cidr "10.200.0.0/14" \
--services-ipv4-cidr "10.204.0.0/16" \
--master-ipv4-cidr "10.205.0.0/28" \
--network "projects/${GCLOUD_PROJECT}/global/networks/${GCLOUD_PROJECT}-network" \
--subnetwork "projects/${GCLOUD_PROJECT}/regions/${GCLOUD_REGION}/subnetworks/air-ue4-pub" \
--image-type "COS" \
--disk-type "pd-standard" \
--disk-size "100" \
--autoscaling-profile "optimize-utilization" \
--enable-master-authorized-networks \
--master-authorized-networks ${master_auth_networks} \
--metadata disable-legacy-endpoints=true \
--scopes "https://www.googleapis.com/auth/cloud-platform" \
--addons "HorizontalPodAutoscaling,HttpLoadBalancing,GcePersistentDiskCsiDriver" \
--enable-autorepair \
--max-surge-upgrade "1" \
--max-unavailable-upgrade "0" \
--max-pods-per-node "55" \
--default-max-pods-per-node "110" \
--num-nodes "1" \
--min-nodes "0" \
--max-nodes "9" \
--enable-stackdriver-kubernetes \
--enable-private-nodes \
--enable-ip-alias \
--enable-intra-node-visibility \
--enable-autoscaling \
--no-enable-basic-auth \
--no-enable-autoupgrade \
--enable-shielded-nodes \
--shielded-secure-boot
fi
if kubectl get clusterrolebindings | grep "cluster-admin-binding"; then
kubectl delete clusterrolebinding cluster-admin-binding
fi
# Make user a cluster admin
kubectl create clusterrolebinding cluster-admin-binding \
--clusterrole=cluster-admin \
--user ${GCLOUD_USER}
}
create_cluster
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment