#!/bin/bash ## ## Script to automate the Kubernetes CentOS client side pieces ## . .gce_kubernetes.config echo "######################################" echo "Set the gcloud compute region and zone" echo "######################################" gcloud config set compute/region $GCE_REGION gcloud config set compute/zone $GCE_ZONE gcloud config set project $GCE_PROJECT echo "Compute region and zone set" echo "" echo "###################################" echo "Creating the VPC network and subnet" echo "###################################" gcloud compute networks create $KUBE_NETWORK --subnet-mode custom gcloud compute networks subnets create $KUBE_SUBNET --network $KUBE_NETWORK --range $KUBE_SUBNET_CIDR gcloud compute firewall-rules create $KUBE_INT_FW_NAME --allow tcp,udp,icmp --network $KUBE_NETWORK --source-ranges $KUBE_SUBNET_CIDR,$KUBE_POD_CIDR gcloud compute firewall-rules create $KUBE_EXT_FW_NAME --allow tcp:22,tcp:6443,icmp --network $KUBE_NETWORK --source-ranges 0.0.0.0/0 gcloud compute firewall-rules list --filter=”network:$KUBE_NETWORK” echo "Firewall rules have hopefully been created" echo "" echo "################################################" echo "Creating the static public IP address for the LB" echo "################################################" gcloud compute addresses create $KUBE_NETWORK --region $GCE_REGION gcloud compute addresses list --filter="name=('$KUBE_NETWORK')" echo "Public IP address created" echo "" echo "##############################" echo "Creating the compute instances" echo "##############################" KUBE_CONTROLLERS=$((KUBE_CONTROLLERS-1)) for ((i=0; i<=$KUBE_CONTROLLERS; i++)); do echo "Creating controller-${i}" gcloud compute instances create controller-${i} --async --boot-disk-size 200GB --can-ip-forward --image-family centos-7 --image-project centos-cloud --machine-type g1-small --private-network-ip $KUBE_SUBNET_ADDR.1${i} --scopes compute-rw,storage-ro,service-management,service-control,logging-write,monitoring --subnet $KUBE_SUBNET --tags kubernetes,controller done KUBE_WORKERS=$((KUBE_WORKERS-1)) for ((i=0; i<=$KUBE_WORKERS; i++)); do echo "Creating worker-${i}" gcloud compute instances create worker-${i} --async --boot-disk-size 200GB --can-ip-forward --image-family centos-7 --image-project centos-cloud --machine-type g1-small --metadata pod-cidr=$KUBE_POD_ADDR.${i}.0/24 --private-network-ip $KUBE_SUBNET_ADDR.2${i} --scopes compute-rw,storage-ro,service-management,service-control,logging-write,monitoring --subnet $KUBE_SUBNET --tags kubernetes,worker done gcloud compute instances list echo "Hopefully all compute instances have been created" echo "" sleep 20 for ((i=0; i<=$KUBE_CONTROLLERS; i++)); do gcloud compute ssh controller-${i} -- 'sudo yum update -y' done for ((i=0; i<=$KUBE_WORKERS; i++)); do gcloud compute ssh worker-${i} -- 'sudo yum update -y' done