Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AWS terraform: add zone label and reserved resources for nodes #871

Merged
merged 6 commits into from
Sep 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 31 additions & 3 deletions deploy/modules/aws/tidb-cluster/local.tf
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,24 @@ locals {
placement_group = "" # The name of the placement group into which to launch the instances, if any.
}

# 169.254.169.254 is the authoritative AWS metadata server, see https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-instance-metadata.html
aws_zone_getter = "$(curl -s http://169.254.169.254/latest/meta-data/placement/availability-zone)"

tidb_cluster_worker_groups = [
{
name = "${var.cluster_name}-pd"
key_name = var.ssh_key_name
instance_type = var.pd_instance_type
root_volume_size = "50"
public_ip = false
kubelet_extra_args = "--register-with-taints=dedicated=${var.cluster_name}-pd:NoSchedule --node-labels=dedicated=${var.cluster_name}-pd,pingcap.com/aws-local-ssd=true"
# the space separator is safe when the extra args is empty or prefixed by spaces (the same hereafter)
kubelet_extra_args = join(" ",
[
"--register-with-taints=dedicated=${var.cluster_name}-pd:NoSchedule",
"--node-labels=dedicated=${var.cluster_name}-pd,pingcap.com/aws-local-ssd=true,zone=${local.aws_zone_getter}",
lookup(var.group_kubelet_extra_args, "pd", var.kubelet_extra_args)
]
)
asg_desired_capacity = var.pd_count
asg_max_size = var.pd_count + 2
# additional_userdata = file("userdata.sh")
Expand All @@ -53,7 +63,13 @@ locals {
instance_type = var.tikv_instance_type
root_volume_size = "50"
public_ip = false
kubelet_extra_args = "--register-with-taints=dedicated=${var.cluster_name}-tikv:NoSchedule --node-labels=dedicated=${var.cluster_name}-tikv,pingcap.com/aws-local-ssd=true"
kubelet_extra_args = join(" ",
[
"--register-with-taints=dedicated=${var.cluster_name}-tikv:NoSchedule",
"--node-labels=dedicated=${var.cluster_name}-tikv,pingcap.com/aws-local-ssd=true,zone=${local.aws_zone_getter}",
lookup(var.group_kubelet_extra_args, "tikv", var.kubelet_extra_args)
]
)
asg_desired_capacity = var.tikv_count
asg_max_size = var.tikv_count + 2
pre_userdata = file("${path.module}/pre_userdata")
Expand All @@ -66,7 +82,13 @@ locals {
root_volume_type = "gp2"
root_volume_size = "50"
public_ip = false
kubelet_extra_args = "--register-with-taints=dedicated=${var.cluster_name}-tidb:NoSchedule --node-labels=dedicated=${var.cluster_name}-tidb"
kubelet_extra_args = join(" ",
[
"--register-with-taints=dedicated=${var.cluster_name}-tidb:NoSchedule",
"--node-labels=dedicated=${var.cluster_name}-tidb,zone=${local.aws_zone_getter}",
lookup(var.group_kubelet_extra_args, "tidb", var.kubelet_extra_args)
]
)
asg_desired_capacity = var.tidb_count
asg_max_size = var.tidb_count + 2
},
Expand All @@ -77,6 +99,12 @@ locals {
root_volume_type = "gp2"
root_volume_size = "50"
public_ip = false
kubelet_extra_args = join(" ",
[
"--node-labels=zone=${local.aws_zone_getter}",
lookup(var.group_kubelet_extra_args, "monitor", var.kubelet_extra_args)
]
)
asg_desired_capacity = 1
asg_max_size = 3
}
Expand Down
2 changes: 1 addition & 1 deletion deploy/modules/aws/tidb-cluster/templates/userdata.sh.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ systemctl daemon-reload
systemctl restart docker

# Bootstrap and join the cluster
/etc/eks/bootstrap.sh --b64-cluster-ca '${cluster_auth_base64}' --apiserver-endpoint '${endpoint}' ${bootstrap_extra_args} --kubelet-extra-args '${kubelet_extra_args}' '${cluster_name}'
/etc/eks/bootstrap.sh --b64-cluster-ca "${cluster_auth_base64}" --apiserver-endpoint "${endpoint}" ${bootstrap_extra_args} --kubelet-extra-args "${kubelet_extra_args}" "${cluster_name}"

# Allow user supplied userdata code
${additional_userdata}
11 changes: 11 additions & 0 deletions deploy/modules/aws/tidb-cluster/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -147,3 +147,14 @@ variable "iam_path" {
description = "If provided, all IAM roles will be created on this path."
default = "/"
}

variable "kubelet_extra_args" {
description = "Extra arguments passed to kubelet"
default = "--kube-reserved memory=0.3Gi,ephemeral-storage=1Gi --system-reserved memory=0.2Gi,ephemeral-storage=1Gi"
}

variable "group_kubelet_extra_args" {
description = "If provided, override the kubelet_extra_args for a specific node group which matches the key of map (e.g. tidb, tikv, pd, monitor)"
DanielZhangQD marked this conversation as resolved.
Show resolved Hide resolved
type = map(string)
default = {}
}