TBD
- https://codelabs.developers.google.com/codelabs/cloud-builder-gke-continuous-deploy#1
- https://learn.hashicorp.com/tutorials/terraform/gke?in=terraform/kubernetes
- Google Cloud SDK (install from https://cloud.google.com/sdk/docs/install then run
gcloud init
) - Terraform
TODO - set up to use service account impersonation
gcloud auth application-default login
gcloud services enable container.googleapis.com containerregistry.googleapis.com cloudbuild.googleapis.com sourcerepo.googleapis.com
TODO confirm when the cloudbuild (not) service account was created
export PROJECT_NUMBER="$(gcloud projects describe $(gcloud config get-value core/project -q) --format='get(projectNumber)')"
export PROJECT=$(gcloud info --format='value(config.project)')
gcloud projects add-iam-policy-binding ${PROJECT} --member=serviceAccount:${PROJECT_NUMBER}@cloudbuild.gserviceaccount.com --role=roles/container.developer
It's easiest if we push the code to Cloud Source (i.e. it makes it easier for Cloud Build to access). To set this up, add an SSH key via the menu in Cloud Source. Alternatively, access to GitHub can be setup by installing an app on GitHub (more details TBD).
Get details of cluster
gcloud container clusters describe <cluster name> --region <region>
Set config in kube config (i.e. ~/.kube/config
)
gcloud container clusters get-credentials
kubectl create ns production
kubectl apply -f kubernetes/deployments/prod -n production
kubectl apply -f kubernetes/deployments/canary -n production
kubectl apply -f kubernetes/services -n production
Scale up/down the front end replicas
kubectl -n production scale --replicas=2 deployments/gceme-frontend-production
Run interactive bash shell in the first container found in the first pod of the specified service.
kubectl -n production exec svc/gceme-frontend -it -- bash
The backend pods are fronted by a ClusterIP
service (no type
is specified in backend.yaml
so it defaults to ClusterIP
). This service balances/proxies requests to the endpoints.
kubectl -n production get service gceme-backend --output=yaml
If the service has a selector specified (backend.yaml
does) then an Endpoints
object of the same name is created with the service.
The controller for the Service
selector continuously scans for Pods that match its selector, and then POSTs any updates to an Endpoint object.
kubectl -n production get endpoints gceme-backend --output=yaml