Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Google Kubernetes Engine (GKE) Rails deploy script
# gke_deploy.sh
# Make sure we're in the right project and authenticated
gcloud config set project your-project
# Needed this on first run https://github.com/kubernetes/kubernetes/issues/30617
# gcloud config set container/use_client_certificate True
# Regional cheaper than zonal and acceptable for staging
gcloud container clusters get-credentials staging \
--zone northamerica-northeast1-a --project your-project
export TAG=`git rev-parse --short HEAD`
export IMAGE=gcr.io/your-project/your-app
export ARTIFACT=${IMAGE}:${TAG}
printf "ARTIFACT: ${ARTIFACT}\n"
# build container
docker build -t $IMAGE -f Dockerfile .
# tag container version
docker tag $IMAGE $ARTIFACT
# also tag latest in case we push ENV change
docker tag $IMAGE ${IMAGE}:latest
# push both to google container registry
docker push $ARTIFACT
docker push ${IMAGE}:latest
# First time setup only
# Set up the Deployment and Service create new ones
# kubectl apply -f kube/cable-deployment.yaml,\
# kube/cable-service.yaml,\
# kube/sidekiq-deployment.yaml,\
# kube/rails-cloudsqlproxy-deployment.yaml,\
# kube/redis-master-deployment.yaml,\
# kube/redis-master-service.yaml,\
# web-ingress.yaml,\
# web-service.yaml
# Credentials for CloudSQL Proxy (create a GCP credentials file for your service account)
# kubectl create secret generic cloudsql-instance-credentials \
# --from-file=credentials.json=./private/your-project-xxxxxxxx.json
# Cert and TLS
# kubectl create secret tls gkecert --key ./private/example.key --cert ./private/example.crt
# Create the ingress
# kubectl apply -f kube/web-ingress.yaml
# kubectl describe ing gke-ingress
# ROLLOUT -------------------------------------------------------------------- BEGIN
# Web, Cable, Sidekiq rollout
kubectl set image deployment your-app rails=$ARTIFACT --record
kubectl set image deployment cable cable=$ARTIFACT --record
kubectl set image deployment sidekiq sidekiq=$ARTIFACT --record
kubectl rollout status deployment your-app
kubectl rollout status deployment cable
kubectl rollout status deployment sidekiq
# curl --retry 10 --retry-delay 10 -v https://xx.xxx.xxx.xx -k
# ROLLOUT -------------------------------------------------------------------- END
kubectl get pods
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.