Skip to content

Instantly share code, notes, and snippets.

@allenhurff
Created August 23, 2018 00:41
Show Gist options
  • Save allenhurff/d25535dff572965439c0da21c6295808 to your computer and use it in GitHub Desktop.
Save allenhurff/d25535dff572965439c0da21c6295808 to your computer and use it in GitHub Desktop.
#!/bin/bash
set -e
set -v
# this paste contains the commands run during the "setup GitLab in GKE" video at https://www.youtube.com/watch?v=8vM374-H0zE
# additional information can be found at https://docs.gitlab.com/ee/install/kubernetes/gitlab_chart.html
# once configured, you will be able to access your cluster at
# https://gitlab.$CLUSTERNAME.$DOMAINNAME
# PROJECTNAME should be your GKE project
# DNSZONE is the name of the zone configuration in Google Cloud DNS
export CLUSTERNAME=hurffcraft-gitlab-shop
export PROJECTNAME=hurffcraft-gitlab-shop
export DNSZONE=hurffcraft-shop-zone
export DOMAINNAME=hurffcraft.shop
echo $CLUSTERNAME
echo $PROJECTNAME
echo $DNSZONE
echo $DOMAINNAME
echo https://gitlab.$PROJECTNAME.$DOMAINNAME
# create cluster
echo '# create cluster ' $CLUSTERNAME '--machine-type "n1-standard-2" --num-nodes "3" --zone "us-west2-b"'
gcloud container clusters create $CLUSTERNAME --machine-type "n1-standard-2" --num-nodes "3" --zone "us-west2-b"
# create static ip
echo '# create static ip'
gcloud beta compute --project=$PROJECTNAME addresses create $CLUSTERNAME --region=us-west2 --network-tier=PREMIUM
# switch to admin
echo '# switch to admin'
export ADMINPASS=`gcloud container clusters describe $CLUSTERNAME |grep password: |cut -d ":" -f 2|sed 's/ //'`
kubectl config set-credentials admin/$CLUSTERNAME --username=admin --password=$ADMINPASS
echo '# kubectl config set-credentials'
kubectl config set-context gke_${PROJECTNAME}_us-west2-b_$CLUSTERNAME --user=admin/$CLUSTERNAME
kubectl config use-context gke_${PROJECTNAME}_us-west2-b_$CLUSTERNAME
echo 'kubectl config use-context gke_' ${PROJECTNAME}_us-west2-b_$CLUSTERNAME
# make your account an admin
echo 'kubectl create clusterrolebinding'
kubectl create clusterrolebinding cluster-admin-binding --clusterrole cluster-admin --user $(gcloud config get-value account)
# switch back to self
gcloud beta container clusters get-credentials $CLUSTERNAME --region=us-west2-b
echo 'gcloud beta container clusters get-credentials ' $CLUSTERNAME
# make tiller service account
echo '# make tiller service account'
echo 'kubectl create serviceaccount --namespace kube-system tiller'
kubectl create serviceaccount --namespace kube-system tiller
kubectl create clusterrolebinding tiller-clusterrolebinding --clusterrole cluster-admin --serviceaccount kube-system:tiller
# setup helm
echo '# setup helm'
helm init --service-account tiller --wait
helm repo add gitlab https://charts.gitlab.io/
helm repo update
# get static IP
echo '# get static IP'
export STATICIP=`gcloud compute addresses describe $CLUSTERNAME --region us-west2 |grep address: |cut -d ":" -f 2|sed 's/ //'`
echo 'STATICIP' $STATICIP
# setup DNS
echo '# setup DNS'
gcloud dns --project=$PROJECTNAME record-sets transaction start --zone=$DNSZONE
gcloud dns --project=$PROJECTNAME record-sets transaction add $STATICIP --name=gitlab.$CLUSTERNAME.$DOMAINNAME. --ttl=300 --type=A --zone=$DNSZONE
gcloud dns --project=$PROJECTNAME record-sets transaction execute --zone=$DNSZONE
# helm upgrade --install gitlab gitlab/gitlab --timeout 600 --set global.hosts.domain=$CLUSTERNAME.$DOMAINNAME --set global.hosts.externalIP=$STATICIP --set certmanager-issuer.email=$(gcloud config get-value account)
echo 'helm upgrade --install gitlab gitlab/gitlab \'
echo ' --timeout 600 \'
echo ' --set global.hosts.domain=$CLUSTERNAME.$DOMAINNAME \'
echo ' --set global.hosts.externalIP=$STATICIP \'
echo ' --set certmanager-issuer.email=$(gcloud config get-value account)'
helm upgrade --install gitlab gitlab/gitlab \
--timeout 600 \
--set global.hosts.domain=$CLUSTERNAME.$DOMAINNAME \
--set global.hosts.externalIP=$STATICIP \
--set certmanager-issuer.email=$(gcloud config get-value account)
## Source/Humanoid=(ATHII)[/mailto:[email protected]]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment