Skip to content

Latest commit

 

History

History
51 lines (38 loc) · 2.99 KB

README.md

File metadata and controls

51 lines (38 loc) · 2.99 KB

Google Kubernetes Engine - GitHub Actions

An example workflow that uses GitHub Actions to deploy a static website to an existing Google Kubernetes Engine cluster.

Workflow

The example workflow will trigger on every push to this repo.

For pushes to the feature branch, the workflow will:

  1. Build the Docker image
  2. Verify the Google Cloud Platform credentials are correct

For pushes to the default branch (master), in addition to the above Actions, the workflow will:

  1. 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 registers gcloud as a credential helper and uses the 'docker' command within the gcloud action to push the image.
  2. 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 name master may result in successful workflows that don't update the cluster.

Pre-reqs

  1. Google Cloud Platform project
  2. GCP Service Account with write access to GCR and GKE for this project
  3. 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.
  4. Also add Secrets for GKE_PROJECT and GKE_EMAIL. Those can be found in the raw key JSON above.
  5. An existing Kubernetes Engine cluster
    1. Create a Cluster
  6. 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.

Resources

Example Actions

Example Workflows