Skip to content

Instantly share code, notes, and snippets.

@mjroeleveld
Last active February 20, 2019 10:13
Show Gist options
  • Save mjroeleveld/11d4af90991857780cf4e77ae2a4cacd to your computer and use it in GitHub Desktop.
Save mjroeleveld/11d4af90991857780cf4e77ae2a4cacd to your computer and use it in GitHub Desktop.

Spinnaker on GKE

This serves as a reference of how I configured a distrubuted installation of Spinnaker running on GKE. It assumes a certain environment although you may pick and choose from this guide.

Specifics:

  • A seperate GCP project for Cloudbuild (useful if you orchestrate across different project)
  • Use GCS for storage
  • Use CloudBuild and PubSub to trigger pipelines
  • Use GCR as container registry
  • Use identity aware proxy for Google authentication
  • Use Helm chart to deploy application called website

Setup

Configure

  • Create pipeline with cloud build trigger using created PubSub subscription (https://www.spinnaker.io/setup/ci/gcb/#configure-your-pipeline-trigger)

    • Specify status SUCCESS as payload constraint

    • Specify buildTriggerId as payload constraint

    • Add tag parameter Allows for manually triggering the pipeline

      • Required
      • Name should be tag
      • Set default value to: ${trigger['payload']['source']['repoSource']['tagName']}
    • Add expected artifacts:

      • Helm chart

        • Specify the object path: gs://[ARTIFACTS_BUCKET]/website/charts/v[0-9.]+.tar.gz
        • Specify the default: gs://[ARTIFACTS_BUCKET]/website/charts/${parameters.tag}.tar.gz
      • Container(s)

        • Specify Docker image:

          gcr.io/[GCR_REPO]/website

        • Specify the default: gcr.io/[GCR_REPO]/website:${parameters.tag}

  • Add bake stage to pipeline

    • Select HELM2 as template renderer
    • Specify name (Helm release name)
    • Add GCS artifact from previous stage as expected artifact
    • Enable “fail stage on failed expressions”
    • Add base64 as produced artifact and give it a name
  • Add deploy stage to pipeline

    • Select account that corresponds to the desired cluster
    • Select base64 artifact from previous stage as expected artifact
    • Add containers as required artifacts to bind This will override the container versions in the Helm chart

Modify app

  • Add Helm chart in infra/helm/{CHART_NAME}
  • Add cloudbuild.yaml with
    • Build Docker image
    • Optionally tag image with version
    • Archive Helm chart to ${TAG_NAME}.tar.gz and upload to the cloudbuild project charts bucket under the correct app folder
    • Add created archive and images as artifact

Example cloudbuild file

steps:
    # Build image
  - name: 'gcr.io/cloud-builders/docker'
  	args: ['build', '-t', 'gcr.io/$PROJECT_ID/website', '.']
  	
    # Tag with version
  - name: 'gcr.io/cloud-builders/docker'
  	args: ['tag', 'gcr.io/$PROJECT_ID/website', 'gcr.io/$PROJECT_ID/website:$TAG_NAME']

    # Create chart archive
  - name: 'gcr.io/cloud-builders/gsutil'
    entrypoint: bash
    args:
      - '-c'
      - |
        tar -czvf ${TAG_NAME}.tar.gz -C infra/helm/website .

# Specify chart archive artifact
artifacts:
  objects:
    location: 'gs://[ARTIFACTS_BUCKET]/website/charts'
    paths: ['$TAG_NAME.tar.gz']

# Specify image artifacts (at least one without tag for Spinnaker to pick it up)
images:
  - gcr.io/$PROJECT_ID/website
  - gcr.io/$PROJECT_ID/website:$TAG_NAME
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment