Part 1: Spinnaker & GKE /w Canary Deployments

  • Download a sample application, create a Git repository then upload it to a Google Cloud Source Repository.
  • Build the container image.
  • Create triggers to re-build container images on application changes.
  • Configure a Spinnaker pipeline to reliably and continuously deploy the application to Kubernetes Engine.
  • Deploy a code change, triggering the pipeline, and roll out to production.

Part 2: Github & Cloud Run /w Pull Requests

  • Set up a Github source code repository.
  • Create the service to run the application in Cloud Run
  • Allow Github to Cloud Build communication
  • Introduce a code change, perform a pull request and deploy a new version

Part 3: Cloud Deploy

Coming in the future!

Part 4: ???

Part 1: Spinnaker & GKE /w Canary Deployments

Task 1. Study the Spinnaker deployment

Your tools team have deployed Spinnaker for you on GKE in the us-central1 region, and us-central1-c zone. Perform the following command to set up port forwarding to the user interface from Cloud Shell:

Get the credentials for the GKE cluster with:

export PROJECT=$(gcloud config get-value project)
gcloud container clusters get-credentials spinnaker-tutorial --zone us-central1-c


export DECK_POD=$(kubectl get pods --namespace default -l "cluster=spin-deck" \
    -o jsonpath="{.items[0]}")


kubectl port-forward --namespace default $DECK_POD 8080:9000 >> /dev/null &


To open the Spinnaker user interface, click the Web Preview icon at the top of the Cloud Shell window and select Preview on port 8080.

Task 3. Create the source code repository

In this section, you create the repository for your code, configure Cloud Build to detect changes to it which then builds the container, and pushes it to Container Registry.

  1. In Cloud Shell tab, download the sample application source code:
gsutil -m cp -r gs://accelerate2022/tc003/sample-app.tar .


  1. Unpack the source code:
mkdir sample-app
tar xvf sample-app.tar -C ./sample-app


  1. Change directories to the source code:
cd sample-app


  1. Set the correct project ID in the code:
sed -i s/PROJECT/$PROJECT/g k8s/deployments/*


  1. Set the username and email address for your Git commits in this repository. Replace 
     with a username you create:
git config --global "$(gcloud config get-value core/account)"


git config --global "[USERNAME]"


  1. Make the initial local commit to your source code:
git init


git add .


git commit -m "Initial commit"


  1. Create the repository in Google Cloud:
gcloud source repos create sample-app


git config credential.helper


  1. Add your newly created repository as remote:
git remote add origin$PROJECT/r/sample-app


  1. Push your code to the new repository’s master branch:
git push origin master



  1. Check that you can see your source code in the Console by clicking Navigation Menu > Source Repositories.

In the Cloud Platform Console, click Navigation menu > Cloud Build > Triggers.

  1. Set the following trigger settings:
  • Name
  • Event: Push new tag
  • Select your newly created 
  • Tag
  • Configuration / Type
    Cloud Build configuration file (yaml or json)
  • Configuration / Location
  • Configuration / Cloud Build configuration file location

Task 5. Prepare the Kubernetes Manifests for use in Spinnaker

Spinnaker needs access to your Kubernetes manifests in order to deploy them to your clusters. This section creates a Cloud Storage bucket that will be populated with your manifests during the CI process in Cloud Build. After your manifests are in Cloud Storage, Spinnaker can download and apply them during your pipeline’s execution.

  1. Create the bucket:
gsutil mb -l us-central1 gs://$PROJECT-kubernetes-manifests


  1. Enable versioning on the bucket so that you have a history of your manifests:
gsutil versioning set on gs://$PROJECT-kubernetes-manifests

Task 6. Start a build
Make a small code change
Add a file to the directory to make a change to the application

touch testfile.txt
git add testfile.txt
git commit -a -m "Make a feature change!"
Push your first image using the following steps:

In Cloud Shell, still in the sample-app directory, create a Git tag:

git tag v1.0.0
Push the tag:

git push --tags

Task 7. Configure a pipeline in Spinnaker
Install the spin CLI for managing Spinnaker
spin is a command-line utility for managing Spinnaker's applications and pipelines.

Download the 1.22.0 version of spin, make it executable, and place it in the bin directory:

wget -O ~/spin
chmod +x ~/spin
sudo mv ~/spin /usr/bin/spin
Create the deployment pipeline
Use spin to create an app called sample in Spinnaker. Note that this requires you run the previous port-forwarding command to reach the Spinnaker endpoint.

Set up the app in Spinnaker:

spin application save --application-name sample \
                        --owner-email "$(gcloud config get-value core/account)" \
                        --cloud-providers kubernetes \
                        --gate-endpoint http://localhost:8080/gate
Next, you create the continuous delivery pipeline. In this tutorial, the pipeline is configured to detect when a Docker image with a tag prefixed with "v" has arrived in your Container Registry.

From your sample-app source code directory, run the following command to upload an example pipeline to your Spinnaker instance:

sed s/PROJECT/$PROJECT/g spinnaker/pipeline-deploy.json > pipeline.json
spin pipeline save --gate-endpoint http://localhost:8080/gate -f pipeline.json

Task 9. Triggering your pipeline from code changes
Now test the pipeline end to end by making a code change, pushing a Git tag, and watching the pipeline run in response. By pushing a Git tag that starts with "v", you trigger Container Builder to build a new Docker image and push it to Container Registry. Spinnaker detects that the new image tag begins with "v" and triggers a pipeline to deploy the image to canaries, run tests, and roll out the same image to all pods in the deployment.

From your sample-app directory, change the color of the app from orange to blue:

sed -i 's/orange/blue/g' cmd/gke-info/common-service.go
Tag your change and push it to the source code repository:

git commit -a -m "Change color to blue"
git tag v1.0.1
git push --tags
In the Console, in Cloud Build > History, wait a couple of moments for the new build to appear. You may need to refresh your page. Wait for the new build to complete, before going to the next step.

Return to the Spinnaker UI and click Pipelines to watch the pipeline start to deploy the image. The automatically triggered pipeline will take a few minutes to appear. You may need to refresh your page.

Task 10. Observe the canary deployments
When the deployment is paused, waiting to roll out to production, return to the web page displaying your running application and start refreshing the tab that contains your app. Four of your backends are running the previous version of your app, while only one backend is running the canary. You should see the new, blue version of your app appear about every fifth time you refresh.

When the pipeline completes, your app looks like the following screenshot. Note that the color has changed to blue because of your code change, and that the Version field now reads canary.
Optionally, you can rollback this change by reverting your previous commit. Rolling back adds a new tag (v1.0.2), and pushes the tag back through the same pipeline you used to deploy v1.0.1:

git revert v1.0.1

git tag v1.0.2
git push --tags
When the build and then the pipeline completes, verify the rollback by clicking Load Balancers, then click the service sample-frontend-production Default and copy the Ingress IP address into a new tab.
Previous ArticleNext Article

Leave a Reply

Your email address will not be published. Required fields are marked *