Spot Elastigroup
Currently, Spot Elastigroup support is behind the feature flag SPOT_ELASTIGROUP_NG
. Contact Harness Support to enable the feature.
This topic describes how to deploy AWS ASG deployments using Harness and the Spot Elastigroup management platform.
Requirements and limitations
- Currently, Harness integrates with Spot only for Amazon Web Services (AWS) deployments by using Elastigroups.
- Spot Elastigroup deployments support AMI artifacts only.
- Spot Elastigroup deployments support only Basic, Canary, and Blue Green execution types.
- Your spot account must be connected to the AWS cloud provider. For more information, go to Connect your cloud account to Spot.
- Currently, Harness does not support using Spot Elastigroup with an OIDC-enabled AWS connector.
Connect to a Spot cloud provider
You can connect Harness to a Spot cloud provider by adding a Harness Spot Elastigroup connector or AWS connector.
To connect to a Spot cloud provider using Spot's API, go to Spot API authentication.
To use an AWS connector, your spot account must first be connected to the AWS cloud provider. For more information, go to Connect your cloud account to Spot.
Create the Harness Spot Elastigroup pipeline
You can create a service and environment either when you are building the pipeline or separately in Services and Environments. This topic walks you through building these within a pipeline.
The pipeline models the release process using execution steps, triggers, and other settings. For more information, go to CD pipeline modeling overview.
- Pipeline Studio
- YAML
- In your Harness Project, select Deployments.
- Select Pipelines, and then select Create a Pipeline.
- Enter the name Spot Tutorial for the pipeline, and then select Start.
- Select Add Stage.
- Select Deploy.
- In Stage Name, enter Spot Tutorial.
- In Deployment Type, select Spot Elastigroup, and then select Set Up Stage.
The new stage is created. Next, we'll add a Harness service to represent the application you're deploying, and configure the service with the Spot Elastigroup service definition, artifacts, environment definition, and infrastructure for deployment.
Add a Harness service
Harness services represent your microservices or applications. You can add the same service to as many stages as you need. For more information, go to services and environments overview.
- YAML
- Harness Manager
Here's a sample Spot service YAML:
service:
name: spot-svc
identifier: spotsvc
serviceDefinition:
type: Elastigroup
spec:
artifacts:
primary:
primaryArtifactRef: <+input>
sources:
- identifier: spot_ami
spec:
connectorRef: org.AWSConnectorForAutomationTest
region: us-east-1
version: <+input>.allowedValues(asgAmi-Orderv2,asgAmi-Order)
type: AmazonMachineImage
gitOpsEnabled: false
-
Select the Service tab, then select Add Service.
-
Enter a service name. For example, spot-svc.
Services are persistent and can be used throughout the stages of this pipeline or any other pipeline in the project.
-
In Service Definition, in Deployment Type, verify if Spot Elastigroup is selected.
-
In Artifacts, select Add Artifact Source.
-
In Specify Artifact Repository Type, select Amazon Machine Image, and then select Continue.
importantSpot Elastigroup deployments support AMI artifacts only.
-
In Amazon Machine Image Repository, select New AWS Connector.
-
Enter a name for the connector, and then select Continue.
-
In Credentials, select AWS Access Key.
-
In Authentication, select one of the following options.
- Plaintext - Enter the Access Key and Secret Key. For Secret Key, you can either create a new secret or use an existing one.
- Encrypted - You can create or select a secret for your Access Key and Secret Key.
-
Select Enable cross-account access (STS Role) if you want to use one AWS account for the connection, but want to deploy or build in a different AWS account.
In this scenario, the AWS account used for AWS access in credentials will assume the IAM role you specify in cross-account role ARN setting. This option uses the AWS Security Token Service (STS) feature.
-
In Test Region, select an AWS region to test the credentials for this connector.
-
In Delegates Setup, select Only use Delegate with all of the following tags and enter the name of the delegate created when creating the Harness Spot Elastigroup connector.
-
Select Save and Continue
-
After the connection test succeeds, select Continue.
-
In Artifact Details, enter the following details:
- In Artifact Source Identifier, enter a name for the artifact.
- In Region, select the region where the artifact is located.
- (Optional) In AMI Tags, add the tags used by your AMI.
- (Optional) In AMI Filters, add the AMI ID filters to locate the AMI resource.
- In Version Details, select Value to enter the version number of the package you want to use. You can also select Regex, and then enter a tag regex to filter the package version.
-
Select Submit.
-
Select Save to save the service configuration.
Add a Spot environment
Define the environment where you will deploy your application.
- YAML
- Harness Manager
Here's a sample infrastructure definition YAML:
infrastructureDefinition:
name: spot-infra
identifier: spotinfra
description: ""
tags: {}
orgIdentifier: Ng_Pipelines_K8s_Organisations
projectIdentifier: DoNotDelete_IvanBalan
environmentRef: Spot
deploymentType: Elastigroup
type: Elastigroup
spec:
connectorRef: spotinstconn
configuration:
store:
type: Harness
spec:
files:
- /spot/spot-cfg
allowSimultaneousDeployments: false
- In Environment, select New Environment.
- Enter the name Spot, and the select Production or Pre-Production.
- Select Save.
- In Specify Infrastructure, select New Infrastructure.
- Enter a name, and then verify that the selected deployment type is Spot Elastigroup.
- Select the Spot connector you created earlier.
- In Elastigroup Configuration, select an Elastigroup configuration source file from the Harness file store or create a new file.
Sample Elastigroup configuration source file
{
"group": {
"name": "spotinst__ser__env",
"capacity": {
"minimum": 1,
"maximum": 1,
"target": 1,
"unit": "instance"
},
"strategy": {
"risk": 100,
"availabilityVsCost": "balanced",
"drainingTimeout": 120,
"fallbackToOd": true,
"scalingStrategy": {},
"persistence": {},
"revertToSpot": {
"performAt": "always"
}
},
"compute": {
"instanceTypes": {
"ondemand": "t2.small",
"spot": [
"m3.medium",
"t2.small",
"t3.small",
"t3a.small",
"t2.medium",
"t3.medium",
"t3a.medium"
]
},
"availabilityZones": [
{
"name": "us-east-1a",
"subnetIds": [
"subnet-1f703d78"
]
},
{
"name": "us-east-1b",
"subnetIds": [
"subnet-01bdf52f"
]
},
{
"name": "us-east-1c",
"subnetIds": [
"subnet-33eaf779"
]
},
{
"name": "us-east-1d",
"subnetIds": [
"subnet-c1ce809d"
]
},
{
"name": "us-east-1e",
"subnetIds": [
"subnet-7427b64a"
]
},
{
"name": "us-east-1f",
"subnetIds": [
"subnet-11efe81e"
]
}
],
"product": "Linux/UNIX",
"launchSpecification": {
"loadBalancersConfig": {
"loadBalancers": [
{
"name": "asg-tg6",
"arn": "arn:aws:elasticloadbalancing:us-east-1:1234567890:targetgroup/asg-tg6/3bcd13e204785948",
"type": "TARGET_GROUP"
}
]
},
"securityGroupIds": [
"sg-0cfbf142d42e37b24"
],
"monitoring": false,
"ebsOptimized": false,
"imageId": "ami-0663143d1f1caa3bf",
"keyPair": "satyam-aws-cross",
"tenancy": "default"
}
},
"scaling": {},
"scheduling": {},
"thirdPartiesIntegration": {}
}
}
- Select Save.
Spot Elastigroup pipeline execution strategies
Now you can select a deployment strategy for this stage of the pipeline.
Spot Elastigroup deployments support only Basic, Canary, and Blue Green execution types.
- Basic
- Canary
- Blue Green
Spot Elastigroups perform the functions that Auto Scaling Groups perform in standard AMI deployments. By default, a Harness Spot Elastigroup Basic deployment pre-configures the following steps:
- Elastigroup Setup: Specify how many instances to launch, and their steady state timeout.
- Elastigroup Deploy: Specify how many instances to deploy, as a number or percentage of the Elastigroup parameters you've set up.
-
In Execution Strategies, select Basic, then select Use Strategy.
-
The basic execution steps are added.
-
Select the Elastigroup Setup step to define Step Parameters.
- Name: Enter the deployment step name.
- Timeout: Set how long you want the Harness Delegate to wait for the Spot cloud to respond to API requests before timeout.
- App Name: Enter a name for the Elastigroup app name that Harness will create. For example, you can use Harness expressions, such as
<+project.identifier>_<+service.identifier>_<+env.identifier>_basic2
. You can select a fixed value, runtime input, or expression for this field. - In Instances, select:
- Same as already running instances: Replicate the already running instances.
- Fixed: Enter Min Instances, Max Instances, and Desired Instances.
-
Select the Elastigroup Deploy step to define Step Parameters.
- Name: Enter the deployment step name.
- Timeout: Set how long you want the Harness Delegate to wait for the Spot cloud to respond to API requests before timeout.
- New Service: Select:
- Percent: Specify a percentage of the target instances that you set in the Elastigroup Setup step.
- Count: Specify the exact number of instances. This cannot exceed the Max Instances that you set in the Elastigroup Setup step.
-
In the Advanced settings of all steps, you can use the following options:
-
Select Apply Changes.
-
Select Save.
Spot Elastigroups perform the functions that Auto Scaling Groups perform in standard AMI deployments. By default, Harness Spot Elastigroup Canary deployment pre-configures the following steps:
- Elastigroup Setup: Specify how many instances to launch, and their steady state timeout.
- Elastigroup Canary Deploy: Specify how many instances to deploy in this phase. When you add additional phases, each phase automatically includes a Elastigroup Deploy step, which you must configure with the count or percentage of instances you want deployed in that phase.
- Elastigroup Deploy: Specify how many instances to deploy, as a number or percentage of the Elastigroup parameters you've set up.
-
In Execution Strategies, select Canary, and then click Use Strategy.
-
The canary execution steps are added.
-
Select the Elastigroup Setup step to define Step Parameters.
- Name: Enter the deployment step name.
- Timeout: Set how long you want the Harness Delegate to wait for the Spot cloud to respond to API requests before timeout.
- App Name: Enter a name for the Elastigroup app name that Harness will create. For example,
<+project.identifier>_<+service.identifier>_<+env.identifier>_basic2
. You can select a fixed value, runtime input, or expression for this field. - In Instances, select:
- Same as already running instances: Replicate the already running instances.
- Fixed: Enter Min Instances, Max Instances, and Desired Instances.
-
Select the Elastigroup Canary Deploy step to define Step Parameters.
- Name: Enter the deployment step name.
- Timeout: Set how long you want the Harness Delegate to wait for the Spot cloud to respond to API requests before timeout.
- New Service: Select:
- Percent: Specify a percentage of the target instances that you set in the Elastigroup Setup step.
- Count: Specify the exact number of instances. This cannot exceed the Max Instances that you set in the Elastigroup Setup step.
-
Select the Elastigroup Deploy step to define Step Parameters.
- Name: Enter the deployment step name.
- Timeout: Set how long you want the Harness Delegate to wait for the Spot cloud to respond to API requests before timeout.
- New Service: Select:
- Percent: Specify a percentage of the target instances that you set in the Elastigroup Setup step.
- Count: Specify an exact number of instances. This cannot exceed the Max Instances that you set in the Elastigroup Setup step.
-
In the Advanced settings of all steps, you can use the following options:
-
Select Apply Changes.
-
Select Save.
Spot Elastigroups perform the functions that Auto Scaling Groups perform in standard AMI deployments.
AWS requirements
Make sure the following AWS requirements are met:
- A pair of Target Groups (TG), typically staging (Stage) and production (Prod) both with the instance target type.
- A load balancer with listeners for both your Target Groups' ports.
- AWS ELB setup:
By default, Harness Spot Elastigroup Blue Green deployment pre-configures the following steps:
- Elastigroup Blue Green Stage Setup: Specify the production and stage listener ports and rules to use. The new Spot Elastigroup is deployed to the stage target group.
- Elastigroup Swap Route:
- Harness modifies the Elastic Load Balancer (ELB) prod listener to forward requests to target groups associated with each new Spot Elastigroup version.
- Harness swaps all traffic from stage to production listeners and ports.
- Harness modifies the ELB stage listener to forward requests to target groups associated with old Spot Elastigroup version.
This deployment method lets you add steps to incrementally shift traffic from the Target Group used by the previous Elastigroup to the Target Group used by the new Elastigroup you are deploying.
Traffic shift summary
In this strategy, you specify production and stage listener ports and rules to use in the Spot Elastigroup Blue Green Stage Setup step. Next, the Elastigroup Swap Route step swaps all traffic from stage to production.
A Blue Green deployment reliably deploys your Elastigroups by maintaining new and old versions of the Elastigroup. The Elastigroups run behind an ALB using two listeners, stage and prod. These listeners forward respectively to two target groups, stage and prod, where the new and old ASGs are run.
In the first stage of deployment, the new Elastigroup is attached to the stage TG:
Blue Green deployments are achieved by swapping routes between the TGs always attaching the new Elastigroup first to the stage TG, and then to the prod TG:
With this strategy, you are not shifting traffic from stage and production environments. You are shifting traffic incrementally for a production environment. In this way, it is similar to a Canary strategy.
However, in a Canary deployment, the percentage of traffic that goes to the new Elastigroup is determined by the number of instances or the forwarding policy of the load balancer.
With this incremental traffic shift strategy, you are controlling the percentage of traffic sent to the new Elastigroup.
-
In Execution Strategies, select Blue Green, and then click Use Strategy.
-
The blue green execution steps are added.
-
Select the Elastigroup Blue Green Stage Setup step to define Step Parameters.
- Name: Enter the deployment step name.
- Timeout: Set how long you want the Harness Delegate to wait for the Spot cloud to respond to API requests before timeout.
- App Name: Enter a name for the Elastigroup app name that Harness will create. For example,
<+project.identifier>_<+service.identifier>_<+env.identifier>
. You can select a fixed value, runtime input, or expression for this field. - In Instances, select:
- Same as already running instances: Replicate the already running instances.
- Fixed: Enter Min Instances, Max Instances, and Desired Instances.
- In Connected Cloud Provider, you can override the connector and region you selected in the service configuration.
- In AWS Load Balancer Configuration, select Add to add the ELB configuration:
- AWS Load Balancer: Select the load balancer to use.
- Prod Listener: Select the listener to use for prod traffic.
- Prod Listener Rule ARN: Select the ARN for the prod listener rule.
- Stage Listener: Select the listener to use for stage traffic.
- Stage Listener Rule ARN: Select the ARN for the stage listener rule.
-
Select the Elastigroup Swap Route step to define Step Parameters.
- Name: Enter the deployment step name.
- Timeout: Set how long you want the Harness Delegate to wait for the Spot cloud to respond to API requests before timeout.
- Select Downsize old Elastigroup to downsize the old Elastigroup.
-
In the Advanced settings of all steps, you can use the following options:
-
Select Apply Changes.
-
Select Save.
Here's a YAML sample of a Spot Elastigroup pipeline using the Canary deployment strategy.
pipeline:
name: Spot canary
identifier: Spot_canary
projectIdentifier: DoNotDelete_IvanBalan
orgIdentifier: Ng_Pipelines_K8s_Organizations
tags: {}
stages:
- stage:
name: spot canary
identifier: spot_canary
description: ""
type: Deployment
spec:
deploymentType: Elastigroup
service:
serviceRef: spotsvc
serviceInputs:
serviceDefinition:
type: Elastigroup
spec:
artifacts:
primary:
primaryArtifactRef: <+input>
sources: <+input>
environment:
environmentRef: Spot
deployToAll: false
infrastructureDefinitions:
- identifier: spotinfra
execution:
steps:
- step:
name: Elastigroup Setup
identifier: Elastigroup_Setup
type: ElastigroupSetup
timeout: 10m
spec:
name: <+project.identifier>_<+service.identifier>_<+env.identifier>
instances:
type: Fixed
spec:
min: 1
max: 2
desired: 2
failureStrategies: []
- step:
type: ElastigroupDeploy
name: Elastigroup Canary Deploy
identifier: Elastigroup_Canary_Deploy
spec:
newService:
type: Count
spec:
count: 1
timeout: 15m
- step:
type: ElastigroupDeploy
name: Elastigroup Deploy
identifier: Elastigroup_Deploy
spec:
newService:
type: Percentage
spec:
percentage: 100
timeout: 15m
rollbackSteps:
- step:
name: Elastigroup Rollback
identifier: Elastigroup_Rollback
type: ElastigroupRollback
timeout: 10m
spec: {}
tags: {}
failureStrategies:
- onFailure:
errors:
- AllErrors
action:
type: StageRollback
Now the pipeline stage is complete and can be deployed. Select Run to run the pipeline.
See also
For frequently asked questions about AWS deployments in Harness, go to AWS deployment FAQs.