setup-gcloud/example-workflows/gke
2020-01-14 11:10:55 -08:00
..
.github/workflows Fix file in readme 2020-01-14 11:10:55 -08:00
site Imported gke example workflow into repo 2019-11-08 14:17:03 -08:00
deployment.yml Fix file in readme 2020-01-14 11:10:55 -08:00
Dockerfile Imported gke example workflow into repo 2019-11-08 14:17:03 -08:00
kustomization.yml Fix license and update readmes 2020-01-14 10:56:09 -08:00
nginx.conf Fix license and update readmes 2020-01-14 10:56:09 -08:00
package-lock.json Imported gke example workflow into repo 2019-11-08 14:17:03 -08:00
README.md Fix file in readme 2020-01-14 11:10:55 -08:00
service.yml Fix license and update readmes 2020-01-14 10:56:09 -08:00

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

For pushes to the default branch, master, the workflow will:

  1. Verify the Google Cloud Platform credentials are correct.

  2. Build, tag, and push the image to Google Container Registry.

    • 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.

    • The image is available through the following tags: latest, the branch name, and first 8 of the commit SHA.

  3. Use a Kubernetes Deployment to push the 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.

Setup

  1. Create or reuse a Github repository for the example workflow:

  2. Create a repository.

  3. Move into your repository directory.

  4. Copy the example into the repository:

cp -r <path_to>/github-actions/example-workflows/gke/ ./
  1. Add your Project Id to the repository's secret, named GKE_PROJECT.

  2. Create a GKE cluster or select an existing GKE cluster.

  3. Update gke.yml with the following values:

  • GKE_CLUSTER: the name of your cluster.

  • GKE_ZONE: the zone your cluster resides.

  • IMAGE: your preferred Docker image name.

You can find the names of your clusters using the command: gcloud container clusters list, and the zone using the command: gcloud container clusters describe <CLUSTER_NAME>.

  1. Add the the following roles to your service account:
  • Kubernetes Engine Developer
  • Storage Admin

Run the workflow

  1. Add and commit your changes:
git add .
git commit -m "Set up Github workflow"
  1. Push to the master branch:
git push origin master
  1. View the workflow by selecting the Actions tab at the top of your repository. Then click on the Build and Deploy to GKE workflow to see the details.