Skip to content

Latest commit

 

History

History
180 lines (90 loc) · 7.25 KB

lab-3.md

File metadata and controls

180 lines (90 loc) · 7.25 KB

Lab 3: Deployment Pipelines

Previous Lab: Lab 2

Jump to TOC


Goal: Understand the different parts of a Spinnaker deployment pipeline, automate deploying a new version of your application.

Creating a dev Deployment pipeline from docker registry

Go to the clusters view and make sure there are no server groups without a load balancer configured. Remove any server group without a load balancer by clicking on it and selecting Destroy on the sidebar. This probably includes your devclone cluster and early versions of your dev cluster.

Creating a Deployment Pipeline

  1. Click on the Pipelines tab for your application

  2. Click Configure a new pipeline

  3. Enter deploy to dev as your pipeline name

  4. Leave Create From set to pipeline

  5. Click create

Adding a Trigger

Triggers allow you to run pipelines off of events. We want our pipeline to run every time a new Docker tag is pushed to the Docker registry, and deploy that new image to our dev cluster, so we will use a Docker trigger.

  1. On the Configuration section of the pipeline, under Automated Triggers, click Add Trigger

  2. Select Docker Registry as the type

  3. Select spinnaker as the organization for your trigger

  4. Select spinnaker/workshop-demo as your image

  5. Leave the Tag field blank. This will trigger on all new tags, but will not trigger on a re-push of an existing tag (like latest)

Adding a Deploy Stage

When the pipeline is run, we want it to deploy a new server group with the new version of the container. We tell Spinnaker what to deploy using the Deploy stage.

  1. Under the green dot labeled "Configuration" at the top of the page, click Add stage

  2. Select Deploy as the stage type

  3. Under Deploy Configuration, click Add server group. This is where we configure the container settings.

  4. Select your dev pipeline as the template, then click Use this template. We don't want to copy all the options by hand, so we start using our existing deployment.

  5. Under containers, remove the existing image selected by clicking on the garbage bin.

  6. Under containers, select the option withImages from Triggers (Tag resolved at runtime)

  7. Under strategy, select highlander (see the Vocabulary Reference at the end of this guide for an explanation of the different strategies)

  8. Scroll down to the Container section

    1. Set Pull Policy to Always

    2. Under Ports: make sure the Container Port is 80

    3. Under Probes: make sure there is a readiness probe (click Enable Readiness Probe ) configured with a 10 second Initial Delay and a port of 80

  9. Click the blue Add button at the bottom of the modal

  10. Click Save Changes at the bottom of the page to save your pipeline

Running the Pipeline

  1. Click on the blue arrow next to the name of the pipeline to go return to the Pipelines tab, or click on the Pipelines tab in the navigation bar.

  2. Click on Start manual execution on the right side of the blue bar that your new pipeline is in.

  3. Select a different color, represented by a different tag name, as the Tag in the drop down

  4. Click Run. This will start the pipeline

    1. You'll see a blue bar appear that shows you what your pipeline is doing. If it doesn't appear, try clicking the arrow next to the pipeline to display it. Click on that blue bar to see the steps in the pipeline.
  5. Click on the clusters view. You should see a spinning ball next to the clusters being worked on

In the next section, we'll create a "deploy to production" pipeline that reads from our development cluster. This captures the typical "promote an image that has been running in dev" flow. This pipeline won't run after every commit.

Creating a Prod load balancer

  1. Before we continue, we need to add a new load balancer. These steps are the same as in Lab 2. Create a Load Balancer, except that instead of putting it in the dev stack, we'll put it in prod.

  2. Click Load Balancers on the top right navigation bar.

  3. Click Create Load Balancer. Select LoadBalancer as the Type under Advanced Options.

  4. Click Create

Create a new pipeline

  1. Click on the Pipelines tab. Click on the + Create button and create a new pipeline called deploy to prod

  2. Leave Create From set to pipeline

Add a Find Image Stage

We want to run this pipeline manually, so we are not going to include a trigger. Instead, the first stage will find the image we want to deploy.

  1. Click Add stage

  2. Set stage type to Find Image from Cluster

  3. Select default for the Namespaces

  4. Click Toggle for list of existing clusters and select your dev cluster

  5. Set Server Group Selection to Newest

Add a Deploy Stage

In this stage, we're going to take the image that we found in the dev cluster and deploy it to a new prod cluster.

  1. Click Add stage

  2. Set stage type to Deploy

  3. Click Add server group

  4. Under Copy configuration from, select you dev cluster, then click Use this template

  5. Change the stack of the pipeline from dev to prod

  6. Next to Containers, Delete the selected image under containers by clicking on the garbage bin.

  7. Add the option under Find Image Results in from the containers drop down.

  8. For Strategy, select Red/Black. In the options for that strategy, set Maximum number of server groups to leave to 2. Notice that this is a different strategy than the deploy to dev pipeline. For our prod pipeline we want the previous server group to hang around in case we need to quickly roll back. We don't want many disabled previous versions hanging around, so we set the max value to leave to equal 2.

  9. Under the Load Balancers heading, remove the dev load balancer and add the prod load balancer you created in step 1.

  10. Under the Container heading,

    1. Pull Policy set to ALWAYS

    2. Under Ports make sure the container port is set to 80

    3. Under Probes a readiness probe on port 80 with a 10 second Initial Delay, just like before.

  11. Save your Pipeline

Manually Run your Pipeline

  1. Click on the blue arrow next to the name of the pipeline to return to the executions view

  2. Click on start pipeline and select deploy to prod

Check out your "Prod" app

  1. Click on the load balancer icon on your prod server group

  2. Copy the ingress link to a new tab to view your app

Manually Run your Pipeline a Second Time

  1. Observe the difference in the strategy you chose: Red/Black leaves the previous server group up but disabled.

  2. You should have two 'prod' server groups - one should be green (healthy) and one should be greyed out (disabled)


Next Lab: Lab 4


Resources: