Skip to content

Commit 5d7a55e

Browse files
authored
Update memoryReservation for consul agents (#30)
* Fix for apk, this should all be reworked * updates deployment_minimum_healthy_percent Setting deployment_minimum_healthy_percent to 60% allows ECS to roll through the tasks in the service and update each agent as needed * Sets a lower default value for memoryReservation On smaller instances consul reserves to much memory, which is really annoying * Updated version of tflint to 0.5.4 * 32 it is!
1 parent bb22241 commit 5d7a55e

File tree

5 files changed

+29
-14
lines changed

5 files changed

+29
-14
lines changed

Diff for: .circleci/config.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
command: if [ `terraform fmt | wc -c` -ne 0 ]; then echo "Some terraform files need be formatted, run 'terraform fmt' to fix"; exit 1; fi
1616
- run:
1717
name: "get tflint"
18-
command: apk add wget ; wget https://github.com/wata727/tflint/releases/download/v0.4.2/tflint_linux_amd64.zip ; unzip tflint_linux_amd64.zip
18+
command: apk update && apk add wget ; wget https://github.com/wata727/tflint/releases/download/v0.5.4/tflint_linux_amd64.zip ; unzip tflint_linux_amd64.zip
1919
- run:
2020
name: "install tflint"
2121
command: mkdir -p /usr/local/tflint/bin ; export PATH=/usr/local/tflint/bin:$PATH ; install tflint /usr/local/tflint/bin

Diff for: README.md

+2
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ extra_tags = [
5252

5353
- `consul_image` - Image to use when deploying consul, defaults to the hashicorp consul image
5454
- `registrator_image` - Image to use when deploying registrator agent, defaults to the gliderlabs registrator:latest
55+
- `consul_memory_reservation` - The soft limit (in MiB) of memory to reserve for the container, defaults 20
56+
- `registrator_memory_reservation` - The soft limit (in MiB) of memory to reserve for the container, defaults 20
5557
- `enable_agents` - Enable Consul Agent and Registrator tasks on each ECS Instance. Defaults to false
5658

5759
Usage

Diff for: consul_agent.tf

+14-11
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@ data "template_file" "consul" {
22
template = "${file("${path.module}/templates/consul.json")}"
33

44
vars {
5-
env = "${aws_ecs_cluster.cluster.name}"
6-
image = "${var.consul_image}"
7-
registrator_image = "${var.registrator_image}"
8-
awslogs_group = "consul-agent-${aws_ecs_cluster.cluster.name}"
9-
awslogs_stream_prefix = "consul-agent-${aws_ecs_cluster.cluster.name}"
10-
awslogs_region = "${var.region}"
5+
env = "${aws_ecs_cluster.cluster.name}"
6+
image = "${var.consul_image}"
7+
registrator_image = "${var.registrator_image}"
8+
consul_memory_reservation = "${var.consul_memory_reservation}"
9+
registrator_memory_reservation = "${var.registrator_memory_reservation}"
10+
awslogs_group = "consul-agent-${aws_ecs_cluster.cluster.name}"
11+
awslogs_stream_prefix = "consul-agent-${aws_ecs_cluster.cluster.name}"
12+
awslogs_region = "${var.region}"
1113
}
1214
}
1315

@@ -42,11 +44,12 @@ resource "aws_cloudwatch_log_group" "consul" {
4244
}
4345

4446
resource "aws_ecs_service" "consul" {
45-
count = "${var.enable_agents ? 1 : 0}"
46-
name = "consul-agent-${aws_ecs_cluster.cluster.name}"
47-
cluster = "${aws_ecs_cluster.cluster.id}"
48-
task_definition = "${aws_ecs_task_definition.consul.arn}"
49-
desired_count = "${var.servers}"
47+
count = "${var.enable_agents ? 1 : 0}"
48+
name = "consul-agent-${aws_ecs_cluster.cluster.name}"
49+
cluster = "${aws_ecs_cluster.cluster.id}"
50+
task_definition = "${aws_ecs_task_definition.consul.arn}"
51+
desired_count = "${var.servers}"
52+
deployment_minimum_healthy_percent = "60"
5053

5154
placement_constraints {
5255
type = "distinctInstance"

Diff for: templates/consul.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
{
33
"name": "consul_agent-${env}",
44
"image": "${image}",
5-
"memoryReservation": 512,
5+
"memoryReservation": ${consul_memory_reservation},
66
"environment": [
77
{
88
"name": "CONSUL_BIND_INTERFACE",
@@ -30,7 +30,7 @@
3030
{
3131
"name": "registrator-${env}",
3232
"image": "${registrator_image}",
33-
"memoryReservation": 256,
33+
"memoryReservation": ${registrator_memory_reservation},
3434
"command": [
3535
"-retry-attempts=10", "-retry-interval=1000", "consul://localhost:8500"
3636
],

Diff for: variables.tf

+10
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ variable "consul_image" {
2525
default = "consul:latest"
2626
}
2727

28+
variable "consul_memory_reservation" {
29+
description = "The soft limit (in MiB) of memory to reserve for the container, defaults 20"
30+
default = "32"
31+
}
32+
2833
variable "docker_storage_size" {
2934
default = "22"
3035
description = "EBS Volume size in Gib that the ECS Instance uses for Docker images and metadata "
@@ -101,6 +106,11 @@ variable "registrator_image" {
101106
description = "Image to use when deploying registrator agent, defaults to the gliderlabs registrator:latest image"
102107
}
103108

109+
variable "registrator_memory_reservation" {
110+
description = "The soft limit (in MiB) of memory to reserve for the container, defaults 20"
111+
default = "32"
112+
}
113+
104114
variable "security_group_ids" {
105115
type = "list"
106116
description = "A list of Security group IDs to apply to the launch configuration"

0 commit comments

Comments
 (0)