11 software delivery problems solved by intelligence software delivery platform  Download
Select Page

Continuous Deployment to Kubernetes using GitHub triggered Spinnaker pipelines

Vijayendar Reddy Donooru May 3, 2020
Share

This blog explains how to configure Spinnaker v1.19.1 to trigger pipelines based on commits to a GitHub repository and inject changed GitHub files as artifacts into the Spinnaker pipeline for Continuous Deployment on Kubernetes.

  1. Prerequisites
  2. Configure GitHub webhooks
  3. Configure a GitHub artifact account
  4. Configure Spinnaker Pipeline Trigger
  5. Verification

1.   Prerequisites

  1. A GitHub repository either under your user or in an organization or user’s account that you have permission to publish commits to Prepare a GitHub repository with some source code to build and it must contain some source code to build artifact.
  2. A running Spinnaker instance

Success of Manifest deploy in Spinnaker

2. Configure GitHub Webhook for Spinnaker

Under the GitHub repository, navigate to Settings -> Webhooks -> Add Webhook. Here, provide the following values to the form shown below: Payload URL: The Payload URL should be $ENDPOINT/webhooks/git/github We need Spinnaker’s API running on an endpoint that is publicly reachable. This is required to allow GitHub’s webhooks to reach Spinnaker. If you’re unsure of what your Spinnaker API endpoint is, check the value of services.gate.baseUrl in ~/.hal/$DEPLOYMENT/staging/spinnaker.yml. The value of $DEPLOYMENT is typically default.

Example:

Content-type: The value should be application/json’

Secret: The value is up to you, and must be provided to any GitHub webhooks triggers that you configure within Spinnaker. It’s used to ensure that only GitHub can trigger your pipelines, not an imposter.

3. Configure a GitHub Artifact Account for Spinnaker

Spinnaker can be configured to listen to changes to a repository in GitHub. These steps show you how to configure a GitHub artifact account so that Spinnaker can download files from GitHub.

  1. Downloading Credentials Start by generating an access token for GitHub. The token requires the repo scope. Here Create an access token for GitHub by following the below link: https://help.github.com/en/articles/creating-a-personal-access-token-for-the-command-line Generate an Access token for GitHub account and downloaded credentials are saved in ‘github_token_file‘. TOKEN_FILE=/home/opsmxuser/dvrs/github/github_token_file
  2. Editing Artifact Settings in Spinnaker Config Enable GitHub artifact support and add an artifact account:

    TOKEN_FILE=/home/opsmxuser/dvrs/github/github_token_file ARTIFACT_ACCOUNT_NAME=dvr-github-artifact-act $ hal config features edit –artifacts true $ hal config artifact github enable $ hal config artifact github account add $ARTIFACT_ACCOUNT_NAME –token-file $TOKEN_FILE $ hal deploy apply

4. Configure Spinnaker Pipeline Trigger deployments on Kubernetes

Configure Spinnaker pipeline to be triggered by a GitHub commit:

4.1 Configure Spinnaker pipeline to trigger with changes in GitHub and make deployments on Kubernetes 

  1. In Pipeline configuration, click the Configuration stage on the far left of the pipeline diagram.
  2. Click on Add Artifact under the Expected Artifacts section.
  3. Select an artifact account that was added earlier (3.2) from the Account drop-down list and enter the File Path field.
  4. Select ‘Use Default Artifact’ and specify the artifact account that was added earlier (3.2) from the Account drop-down list and the ‘Content URL’. Here the ‘Content URL’ is used as: https://api.github.com/repos/opsmxorg/samplerepo/contents/manifest.yaml
    Add expected artifacts in Spinnaker CD Pipeline for deployments on Kubernetes

    Add expected artifacts in Spinnaker pipeline for deployments on Kubernetes

  5. Add one more Artifact Account for Docker-Registry as an account and the Docker image name that we want to trigger on changes to.
    Add artifact account in Spinnaker CD Pipeline for deployments on Kubernetes

    Add artifact account in Spinnaker pipeline for deployments on Kubernetes

  6. Update Automated Triggers details
  1. Click Automated Triggers.
  2. In the Type field, select Git.
  3. In the Repo Type field, select Github.
  4. In the Organization or User field, enter the organization value of your Git repository.
  5. In the Project field, enter the Github repository name.
  6. Specify the appropriate branch details for the Branch.
  7. Provide the Secret value that was entered during GitHub Webhook configuration at Section #2.
  8. Select the Display name for Artifact Constraints which was generated in the Expected Artifacts section.
    Automated Trigger in Spinnaker CD Pipeline for deployments on Kubernetes

    Automated Trigger in Spinnaker pipeline for deployments on Kubernetes

4.2 Configure Deploy Manifest in Spinnaker pipeline for deployments on Kubernetes

Select the Deploy (Manifest) stage by specifying the manifests statistically.

Configure Deploy Manifest in Spinnaker pipeline for deployments on Kubernetes

Configure Deploy Manifest in Spinnaker pipeline for deployments on Kubernetes

5. Verification of the Spinnaker deployments on Kubernetes

Make a change into the repository (https://github.com/opsmxorg/samplerepo.git) for specified Filepath(example: manifest.yaml) and ensure Spinnaker’s pipeline is auto-triggered. This can also be verified under Manage Webhook -> Recent Deliveries by checking the Response for 200, which means the Github event (commit) has been processed successfully.

Verification of the Spinnaker deployments on Kubernetes - Check Manage WebHooks

Verification of the Spinnaker deployments on Kubernetes – Check Manage WebHooks

Verification of the Spinnaker deployments on Kubernetes -Recent Deliveries

Verification of the Spinnaker deployments on Kubernetes -Recent Deliveries

Ensure the Deploy(manifest) stage is executed successfully as shown below:

Spinnaker Deploy Manifest executed successfully

Spinnaker Deploy Manifest executed successfully

And see the subsequent result in the Kubernetes cluster as below:

Spinnaker deployments on Kubernetes cluster

Spinnaker deployments on Kubernetes cluster


OpsMx is a leading provider of Continuous Delivery solutions that help enterprises safely deliver software at scale and without any human intervention. We help engineering teams take the risk and manual effort out of releasing innovations at the speed of modern business. For additional information, contact OpsMx Support.

You May Like