An example workflow that uses GitHub Actions to deploy a static website to an existing Google Kubernetes Engine cluster.
The example workflow will trigger on every push to this repo.
For pushes to the feature branch, the workflow will:
- Build the Docker image
- Verify the Google Cloud Platform credentials are correct
For pushes to the default branch (master
), in addition to the above Actions, the workflow will:
- Tag and Push the image to Google Container Registry
- The image is available through the following tags:
latest
, the branch name, and first 8 of the commit SHA gcloud
serves as a credential helper for Docker. This workflow registersgcloud
as a credential helper and uses the 'docker' command within thegcloud
action to push the image.
- The image is available through the following tags:
- Use a Kubernetes Deployment to push an image to the Cluster
- Note that a GKE deployment requires a unique Tag to update the pods. Using a constant tag
latest
or a branch namemaster
may result in successful workflows that don't update the cluster.
- Note that a GKE deployment requires a unique Tag to update the pods. Using a constant tag
- Google Cloud Platform project
- GCP Service Account with write access to GCR and GKE for this project
- GCP Service Account credentials stored as a JSON key. Base64 encode the JSON key and paste the entire blob as a secret (Repository Settings --> Secrets) named
GKE_KEY
. - Also add Secrets for
GKE_PROJECT
andGKE_EMAIL
. Those can be found in the raw key JSON above. - An existing Kubernetes Engine cluster
- Edit
deployment.yml
to enter the correct GCR path to your image. Easy to find from GCR section of GCP console after first image push.