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
-
Click on the
Pipelines
tab for your application -
Click
Configure a new pipeline
-
Enter
deploy to dev
as your pipeline name -
Leave
Create From
set topipeline
-
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.
-
On the
Configuration
section of the pipeline, underAutomated Triggers
, clickAdd Trigger
-
Select
Docker Registry
as the type -
Select
spinnaker
as the organization for your trigger -
Select
spinnaker/workshop-demo
as your image -
Leave the
Tag
field blank. This will trigger on all new tags, but will not trigger on a re-push of an existing tag (likelatest
)
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.
-
Under the green dot labeled "Configuration" at the top of the page, click
Add stage
-
Select
Deploy
as the stage type -
Under Deploy Configuration, click
Add server group
. This is where we configure the container settings. -
Select your
dev
pipeline as the template, then clickUse this template
. We don't want to copy all the options by hand, so we start using our existing deployment. -
Under containers, remove the existing image selected by clicking on the garbage bin.
-
Under containers, select the option with
Images from Triggers (Tag resolved at runtime)
-
Under strategy, select
highlander
(see the Vocabulary Reference at the end of this guide for an explanation of the different strategies) -
Scroll down to the
Container
section-
Set
Pull Policy
toAlways
-
Under
Ports
: make sure theContainer Port
is80
-
Under
Probes
: make sure there is a readiness probe (clickEnable Readiness Probe
) configured with a 10 secondInitial Delay
and a port of80
-
-
Click the blue
Add
button at the bottom of the modal -
Click
Save Changes
at the bottom of the page to save your pipeline
Running the Pipeline
-
Click on the blue arrow next to the name of the pipeline to go return to the
Pipelines
tab, or click on thePipelines
tab in the navigation bar. -
Click on
Start manual execution
on the right side of the blue bar that your new pipeline is in. -
Select a different color, represented by a different tag name, as the Tag in the drop down
-
Click
Run
. This will start the pipeline- 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.
-
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
-
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 inprod.
-
Click
Load Balancers
on the top right navigation bar. -
Click
Create Load Balancer
. SelectLoadBalancer
as theType
under Advanced Options. -
Click
Create
Create a new pipeline
-
Click on the
Pipelines
tab. Click on the+ Create
button and create a new pipeline calleddeploy to prod
-
Leave
Create From
set topipeline
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.
-
Click
Add stage
-
Set stage type to
Find Image from Cluster
-
Select
default
for the Namespaces -
Click
Toggle for list of existing clusters
and select your dev cluster -
Set
Server Group Selection
toNewest
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.
-
Click
Add stage
-
Set stage type to
Deploy
-
Click
Add server group
-
Under
Copy configuration from
, select you dev cluster, then clickUse this template
-
Change the stack of the pipeline from
dev
toprod
-
Next to Containers, Delete the selected image under containers by clicking on the garbage bin.
-
Add the option under
Find Image Results
in from the containers drop down. -
For
Strategy
, selectRed/Black
. In the options for that strategy, setMaximum number of server groups to leave
to2
. Notice that this is a different strategy than thedeploy 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. -
Under the
Load Balancers
heading, remove thedev
load balancer and add theprod
load balancer you created in step 1. -
Under the
Container
heading,-
Pull Policy
set toALWAYS
-
Under
Ports
make sure the container port is set to 80 -
Under
Probes
a readiness probe on port 80 with a 10 secondInitial Delay
, just like before.
-
-
Save your Pipeline
Manually Run your Pipeline
-
Click on the blue arrow next to the name of the pipeline to return to the executions view
-
Click on start pipeline and select
deploy to prod
Check out your "Prod" app
-
Click on the load balancer icon on your prod server group
-
Copy the ingress link to a new tab to view your app
Manually Run your Pipeline a Second Time
-
Observe the difference in the strategy you chose:
Red/Black
leaves the previous server group up but disabled. -
You should have two 'prod' server groups - one should be green (healthy) and one should be greyed out (disabled)
Next Lab: Lab 4
Resources:
- Kubernetes Source to Prod Code lab - https://www.spinnaker.io/guides/tutorials/codelabs/kubernetes-source-to-prod/
- Google Source to Prod video. This shows the pipelines involved in a VM deployment. In particular, there is a bake stage that bakes an virtual image for deployment with a library called Rosco - https://www.spinnaker.io/guides/tutorials/videos/#google-source-to-production-codelab-walk-through