Skip to content

Instantly share code, notes, and snippets.

@tioxy
Last active September 5, 2019 01:20
Show Gist options
  • Save tioxy/1a4140933a8a93022c9990f292ffd7e2 to your computer and use it in GitHub Desktop.
Save tioxy/1a4140933a8a93022c9990f292ffd7e2 to your computer and use it in GitHub Desktop.
Create simple GKE cluster using gcloud CLI
#!/usr/bin/env bash
# Simple GKE Cluster creation
# Complete reference on https://cloud.google.com/sdk/gcloud/reference/container/clusters/create
# VARIABLES
CREATOR_NAME="tioxy"
CLUSTER_NAME="tioxy-cicd"
CLUSTER_ADDONS="NetworkPolicy,HorizontalPodAutoscaling,HttpLoadBalancing"
CLUSTER_VERSION="1.13.7-gke.24"
DISK_SIZE="30GB"
DISK_TYPE="pd-ssd"
IMAGE_TYPE="COS"
MACHINE_TYPE="n1-standard-4"
CLUSTER_MAINTENANCE_WINDOW="23:59"
NODES_AMOUNT=1
NODES_MAX_PER_POOL=100
GCP_REGION="us-east4"
GCP_ZONE_LOCATIONS="us-east4-a"
GCP_LABELS="created_by=$CREATOR_NAME,created_at=$(date +%s)"
GCP_NETWORK="default"
# Google Cloud - Create cluster command
gcloud container clusters create $CLUSTER_NAME \
--addons $CLUSTER_ADDONS \
--cluster-version $CLUSTER_VERSION \
--disk-size $DISK_SIZE \
--disk-type $DISK_TYPE \
--enable-autorepair \
--enable-cloud-logging \
--enable-cloud-monitoring \
--enable-network-policy \
--image-type $IMAGE_TYPE \
--labels $GCP_LABELS \
--machine-type $MACHINE_TYPE \
--maintenance-window $CLUSTER_MAINTENANCE_WINDOW \
--max-nodes-per-pool $NODES_MAX_PER_POOL \
--metadata disable-legacy-endpoints=true \
--network $GCP_NETWORK \
--no-enable-basic-auth \
--no-enable-ip-alias \
--no-issue-client-certificate \
--node-locations $GCP_ZONE_LOCATIONS \
--node-version $CLUSTER_VERSION \
--num-nodes $NODES_AMOUNT \
--region $GCP_REGION \
--async
# Google Cloud - Import kubeconfig
gcloud container clusters get-credentials $CLUSTER_NAME --region $GCP_REGION
# Fixing RBAC Admin for your account
# https://cloud.google.com/kubernetes-engine/docs/how-to/role-based-access-control
kubectl create clusterrolebinding cluster-admin-binding \
--clusterrole cluster-admin \
--user $(gcloud config get-value account)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment