You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat(spotfleet): add supports spot fleets for spot instances allowing us to use multiple instance types and AZs (#777)
## Description
The
[fork](https://gitlab.com/cki-project/docker-machine/-/tree/v0.16.2-gitlab.19-cki.2)
of docker-machine used in this module has released a version that
supports [AWS Spot
Fleet](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/spot-fleet.html)
3 months ago.
In our case, spot fleets are useful when using spot instances because it
fixes the issue when there is no capacity available for a certain
instance type in a certain AZ. With spot fleets, we can use multiple
instance types and AZ so when there is no capacity on one instance type,
AWS will take the next instance type and so on.
This fixes issues
[#76](#76)
[#435](#435)
[#77](#77)
and
[#474](#474)
## Migrations required
NO our solution is backward compatible so if you don't plan to use spot
fleets, no migration is required.
YES if you want to use spot fleets you will have to do the following
changes:
`docker_machine_instance_type` to `docker_machine_instance_types`
`subnet_id` to `subnet_ids`
You also have to put these 2 new parameters:
`use_fleet` and `key_pair_name`
### Important
We have seen that the
[fork](https://gitlab.com/cki-project/docker-machine/-/tree/v0.16.2-gitlab.19-cki.2)
of docker-machine this module is using consume more RAM using spot
fleets.
For comparison, if you launch 50 machines in the same time, it consumes
~1.2GB of RAM. In our case, we had to change the `instance_type` of the
runner from `t3.micro` to `t3.small`.
## Verification
```hcl
docker_machine_instance_types = ["r5a.xlarge", "r5.xlarge", "r5ad.xlarge", "r5d.xlarge", "m5a.2xlarge"]
use_fleet = true
key_pair_name = "<key-pair-name>"
```
We are using this solution in production for a week now with 150+
developers and over 20 000 jobs a day without any issue for now.
---------
Signed-off-by: François Bibron <[email protected]>
Co-authored-by: François Bibron <[email protected]>
Co-authored-by: Marvin Wichmann <[email protected]>
Co-authored-by: Matthias Kay <[email protected]>
Co-authored-by: kayma <[email protected]>
Copy file name to clipboardExpand all lines: README.md
+51
Original file line number
Diff line number
Diff line change
@@ -371,6 +371,48 @@ module "runner" {
371
371
}
372
372
```
373
373
374
+
### Scenario: Use of Spot Fleet
375
+
376
+
Since spot instances can be taken over by AWS depending on the instance type and AZ you are using, you may want multiple instances types in multiple AZs. This is where spot fleets come in, when there is no capacity on one instance type and one AZ, AWS will take the next instance type and so on. This update has been possible since the [fork](https://gitlab.com/cki-project/docker-machine/-/tree/v0.16.2-gitlab.19-cki.2) of docker-machine supports spot fleets.
377
+
378
+
We have seen that the [fork](https://gitlab.com/cki-project/docker-machine/-/tree/v0.16.2-gitlab.19-cki.2) of docker-machine this module is using consume more RAM using spot fleets.
379
+
For comparison, if you launch 50 machines in the same time, it consumes ~1.2GB of RAM. In our case, we had to change the `instance_type` of the runner from `t3.micro` to `t3.small`.
|[aws_ami.docker-machine](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/ami)| data source |
499
546
|[aws_ami.runner](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/ami)| data source |
500
547
|[aws_availability_zone.runners](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/availability_zone)| data source |
@@ -537,6 +584,7 @@ Made with [contributors-img](https://contrib.rocks).
537
584
| <aname="input_docker_machine_iam_policy_arns"></a> [docker\_machine\_iam\_policy\_arns](#input\_docker\_machine\_iam\_policy\_arns)| List of policy ARNs to be added to the instance profile of the docker machine runners. |`list(string)`|`[]`| no |
538
585
| <aname="input_docker_machine_instance_metadata_options"></a> [docker\_machine\_instance\_metadata\_options](#input\_docker\_machine\_instance\_metadata\_options)| Enable the docker machine instances metadata service. Requires you use GitLab maintained docker machines. | <pre>object({<br> http_tokens = string<br> http_put_response_hop_limit = number<br> })</pre> | <pre>{<br> "http_put_response_hop_limit": 2,<br> "http_tokens": "required"<br>}</pre> | no |
539
586
| <aname="input_docker_machine_instance_type"></a> [docker\_machine\_instance\_type](#input\_docker\_machine\_instance\_type)| Instance type used for the instances hosting docker-machine. |`string`|`"m5.large"`| no |
587
+
| <aname="input_docker_machine_instance_types"></a> [docker\_machine\_instance\_types](#input\_docker\_machine\_instance\_types)| Instance types used for the instances hosting docker-machine. This variable is only supported when use\_fleet is set to true. |`list(string)`|`[]`| no |
540
588
| <aname="input_docker_machine_options"></a> [docker\_machine\_options](#input\_docker\_machine\_options)| List of additional options for the docker machine config. Each element of this list must be a key=value pair. E.g. '["amazonec2-zone=a"]' |`list(string)`|`[]`| no |
541
589
| <aname="input_docker_machine_role_json"></a> [docker\_machine\_role\_json](#input\_docker\_machine\_role\_json)| Docker machine runner instance override policy, expected to be in JSON format. |`string`|`""`| no |
542
590
| <aname="input_docker_machine_security_group_description"></a> [docker\_machine\_security\_group\_description](#input\_docker\_machine\_security\_group\_description)| A description for the docker-machine security group |`string`|`"A security group containing docker-machine instances"`| no |
@@ -554,13 +602,15 @@ Made with [contributors-img](https://contrib.rocks).
554
602
| <aname="input_enable_schedule"></a> [enable\_schedule](#input\_enable\_schedule)| Flag used to enable/disable auto scaling group schedule for the runner instance. |`bool`|`false`| no |
555
603
| <aname="input_environment"></a> [environment](#input\_environment)| A name that identifies the environment, used as prefix and for tagging. |`string`| n/a | yes |
556
604
| <aname="input_extra_security_group_ids_runner_agent"></a> [extra\_security\_group\_ids\_runner\_agent](#input\_extra\_security\_group\_ids\_runner\_agent)| Optional IDs of extra security groups to apply to the runner agent. This will not apply to the runners spun up when using the docker+machine executor, which is the default. |`list(string)`|`[]`| no |
605
+
| <aname="input_fleet_executor_subnet_ids"></a> [fleet\_executor\_subnet\_ids](#input\_fleet\_executor\_subnet\_ids)| List of subnets used for executors when the fleet mode is enabled. Must belong to the VPC specified above. |`list(string)`|`[]`| no |
| <aname="input_gitlab_runner_registration_config"></a> [gitlab\_runner\_registration\_config](#input\_gitlab\_runner\_registration\_config)| Configuration used to register the runner. See the README for an example, or reference the examples in the examples directory of this repo. |`map(string)`| <pre>{<br> "access_level": "",<br> "description": "",<br> "locked_to_project": "",<br> "maximum_timeout": "",<br> "registration_token": "",<br> "run_untagged": "",<br> "tag_list": ""<br>}</pre> | no |
559
608
| <aname="input_gitlab_runner_security_group_description"></a> [gitlab\_runner\_security\_group\_description](#input\_gitlab\_runner\_security\_group\_description)| A description for the gitlab-runner security group |`string`|`"A security group containing gitlab-runner agent instances"`| no |
560
609
| <aname="input_gitlab_runner_security_group_ids"></a> [gitlab\_runner\_security\_group\_ids](#input\_gitlab\_runner\_security\_group\_ids)| A list of security group ids that are allowed to access the gitlab runner agent |`list(string)`|`[]`| no |
561
610
| <aname="input_gitlab_runner_version"></a> [gitlab\_runner\_version](#input\_gitlab\_runner\_version)| Version of the [GitLab runner](https://gitlab.com/gitlab-org/gitlab-runner/-/releases). |`string`|`"15.8.2"`| no |
562
611
| <aname="input_instance_role_json"></a> [instance\_role\_json](#input\_instance\_role\_json)| Default runner instance override policy, expected to be in JSON format. |`string`|`""`| no |
563
612
| <aname="input_instance_type"></a> [instance\_type](#input\_instance\_type)| Instance type used for the GitLab runner. |`string`|`"t3.micro"`| no |
613
+
| <aname="input_key_pair_name"></a> [key\_pair\_name](#input\_key\_pair\_name)| The name of the key pair used by the runner to connect to the docker-machine executors. |`string`|`"fleet-key"`| no |
564
614
| <aname="input_kms_alias_name"></a> [kms\_alias\_name](#input\_kms\_alias\_name)| Alias added to the kms\_key (if created and not provided by kms\_key\_id) |`string`|`""`| no |
565
615
| <aname="input_kms_deletion_window_in_days"></a> [kms\_deletion\_window\_in\_days](#input\_kms\_deletion\_window\_in\_days)| Key rotation window, set to 0 for no rotation. Only used when `enable_kms` is set to `true`. |`number`|`7`| no |
566
616
| <aname="input_kms_key_id"></a> [kms\_key\_id](#input\_kms\_key\_id)| KMS key id to encrypted the resources. Ensure CloudWatch and Runner/Executor have access to the provided KMS key. |`string`|`""`| no |
@@ -637,6 +687,7 @@ Made with [contributors-img](https://contrib.rocks).
637
687
| <aname="input_subnet_ids_gitlab_runner"></a> [subnet\_ids\_gitlab\_runner](#input\_subnet\_ids\_gitlab\_runner)| Deprecated! Use subnet\_id instead. Subnet used for hosting the GitLab runner. |`list(string)`|`[]`| no |
638
688
| <aname="input_suppressed_tags"></a> [suppressed\_tags](#input\_suppressed\_tags)| List of tag keys which are removed from tags, agent\_tags and runner\_tags and never added as default tag by the module. |`list(string)`|`[]`| no |
639
689
| <aname="input_tags"></a> [tags](#input\_tags)| Map of tags that will be added to created resources. By default resources will be tagged with name and environment. |`map(string)`|`{}`| no |
690
+
| <aname="input_use_fleet"></a> [use\_fleet](#input\_use\_fleet)| Use the fleet mode for agents. https://gitlab.com/cki-project/docker-machine/-/blob/v0.16.2-gitlab.19-cki.2/docs/drivers/aws.md#fleet-mode|`bool`|`false`| no |
640
691
| <aname="input_userdata_post_install"></a> [userdata\_post\_install](#input\_userdata\_post\_install)| User-data script snippet to insert after GitLab runner install |`string`|`""`| no |
641
692
| <aname="input_userdata_pre_install"></a> [userdata\_pre\_install](#input\_userdata\_pre\_install)| User-data script snippet to insert before GitLab runner install |`string`|`""`| no |
642
693
| <aname="input_vpc_id"></a> [vpc\_id](#input\_vpc\_id)| The target VPC for the docker-machine and runner instances. |`string`| n/a | yes |
Copy file name to clipboardExpand all lines: variables.tf
+24
Original file line number
Diff line number
Diff line change
@@ -31,6 +31,12 @@ variable "subnet_id" {
31
31
default=""# TODO remove as soon as subnet_id_runners and subnet_ids_gitlab_runner are gone. Variable is mandatory now.
32
32
}
33
33
34
+
variable"fleet_executor_subnet_ids" {
35
+
description="List of subnets used for executors when the fleet mode is enabled. Must belong to the VPC specified above."
36
+
type=list(string)
37
+
default=[]
38
+
}
39
+
34
40
variable"extra_security_group_ids_runner_agent" {
35
41
description="Optional IDs of extra security groups to apply to the runner agent. This will not apply to the runners spun up when using the docker+machine executor, which is the default."
description="Instance types used for the instances hosting docker-machine. This variable is only supported when use_fleet is set to true."
118
+
type=list(string)
119
+
default=[]
120
+
}
121
+
104
122
variable"docker_machine_spot_price_bid" {
105
123
description="Spot price bid. The maximum price willing to pay. By default the price is limited by the current on demand price for the instance type chosen."
description="Use the fleet mode for agents. https://gitlab.com/cki-project/docker-machine/-/blob/v0.16.2-gitlab.19-cki.2/docs/drivers/aws.md#fleet-mode"
786
+
type=bool
787
+
default=false
788
+
}
789
+
766
790
variable"enable_eip" {
767
791
description="Enable the assignment of an EIP to the gitlab runner instance"
0 commit comments