Skip to content

Commit

Permalink
Update memoryReservation for consul agents (#30)
Browse files Browse the repository at this point in the history
* 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!
  • Loading branch information
tfhartmann authored Feb 9, 2018
1 parent bb22241 commit 5d7a55e
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 14 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
command: if [ `terraform fmt | wc -c` -ne 0 ]; then echo "Some terraform files need be formatted, run 'terraform fmt' to fix"; exit 1; fi
- run:
name: "get tflint"
command: apk add wget ; wget https://github.com/wata727/tflint/releases/download/v0.4.2/tflint_linux_amd64.zip ; unzip tflint_linux_amd64.zip
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
- run:
name: "install tflint"
command: mkdir -p /usr/local/tflint/bin ; export PATH=/usr/local/tflint/bin:$PATH ; install tflint /usr/local/tflint/bin
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ extra_tags = [

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

Usage
Expand Down
25 changes: 14 additions & 11 deletions consul_agent.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ data "template_file" "consul" {
template = "${file("${path.module}/templates/consul.json")}"

vars {
env = "${aws_ecs_cluster.cluster.name}"
image = "${var.consul_image}"
registrator_image = "${var.registrator_image}"
awslogs_group = "consul-agent-${aws_ecs_cluster.cluster.name}"
awslogs_stream_prefix = "consul-agent-${aws_ecs_cluster.cluster.name}"
awslogs_region = "${var.region}"
env = "${aws_ecs_cluster.cluster.name}"
image = "${var.consul_image}"
registrator_image = "${var.registrator_image}"
consul_memory_reservation = "${var.consul_memory_reservation}"
registrator_memory_reservation = "${var.registrator_memory_reservation}"
awslogs_group = "consul-agent-${aws_ecs_cluster.cluster.name}"
awslogs_stream_prefix = "consul-agent-${aws_ecs_cluster.cluster.name}"
awslogs_region = "${var.region}"
}
}

Expand Down Expand Up @@ -42,11 +44,12 @@ resource "aws_cloudwatch_log_group" "consul" {
}

resource "aws_ecs_service" "consul" {
count = "${var.enable_agents ? 1 : 0}"
name = "consul-agent-${aws_ecs_cluster.cluster.name}"
cluster = "${aws_ecs_cluster.cluster.id}"
task_definition = "${aws_ecs_task_definition.consul.arn}"
desired_count = "${var.servers}"
count = "${var.enable_agents ? 1 : 0}"
name = "consul-agent-${aws_ecs_cluster.cluster.name}"
cluster = "${aws_ecs_cluster.cluster.id}"
task_definition = "${aws_ecs_task_definition.consul.arn}"
desired_count = "${var.servers}"
deployment_minimum_healthy_percent = "60"

placement_constraints {
type = "distinctInstance"
Expand Down
4 changes: 2 additions & 2 deletions templates/consul.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{
"name": "consul_agent-${env}",
"image": "${image}",
"memoryReservation": 512,
"memoryReservation": ${consul_memory_reservation},
"environment": [
{
"name": "CONSUL_BIND_INTERFACE",
Expand Down Expand Up @@ -30,7 +30,7 @@
{
"name": "registrator-${env}",
"image": "${registrator_image}",
"memoryReservation": 256,
"memoryReservation": ${registrator_memory_reservation},
"command": [
"-retry-attempts=10", "-retry-interval=1000", "consul://localhost:8500"
],
Expand Down
10 changes: 10 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ variable "consul_image" {
default = "consul:latest"
}

variable "consul_memory_reservation" {
description = "The soft limit (in MiB) of memory to reserve for the container, defaults 20"
default = "32"
}

variable "docker_storage_size" {
default = "22"
description = "EBS Volume size in Gib that the ECS Instance uses for Docker images and metadata "
Expand Down Expand Up @@ -101,6 +106,11 @@ variable "registrator_image" {
description = "Image to use when deploying registrator agent, defaults to the gliderlabs registrator:latest image"
}

variable "registrator_memory_reservation" {
description = "The soft limit (in MiB) of memory to reserve for the container, defaults 20"
default = "32"
}

variable "security_group_ids" {
type = "list"
description = "A list of Security group IDs to apply to the launch configuration"
Expand Down

0 comments on commit 5d7a55e

Please sign in to comment.