-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathasg_traefik.tf
90 lines (78 loc) · 3.86 KB
/
asg_traefik.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
####### MODULES ########
locals {
eks-traefik-userdata = <<USERDATA
#!/bin/bash -xe
CA_CERTIFICATE_DIRECTORY=/etc/kubernetes/pki
CA_CERTIFICATE_FILE_PATH=$CA_CERTIFICATE_DIRECTORY/ca.crt
mkdir -p $CA_CERTIFICATE_DIRECTORY
echo "${aws_eks_cluster.eks-cluster.certificate_authority.0.data}" | base64 -d > $CA_CERTIFICATE_FILE_PATH
INTERNAL_IP=$(curl -s http://169.254.169.254/latest/meta-data/local-ipv4)
sed -i s,MASTER_ENDPOINT,${aws_eks_cluster.eks-cluster.endpoint},g /var/lib/kubelet/kubeconfig
sed -i s,CLUSTER_NAME,${var.cluster_defaults["name"]},g /var/lib/kubelet/kubeconfig
sed -i s,REGION,${var.aws_region},g /etc/systemd/system/kubelet.service
sed -i s,MAX_PODS,20,g /etc/systemd/system/kubelet.service
sed -i s,MASTER_ENDPOINT,${aws_eks_cluster.eks-cluster.endpoint},g /etc/systemd/system/kubelet.service
sed -i s,INTERNAL_IP,$INTERNAL_IP,g /etc/systemd/system/kubelet.service
DNS_CLUSTER_IP=10.100.0.10
if [[ $INTERNAL_IP == 10.* ]] ; then DNS_CLUSTER_IP=172.20.0.10; fi
sed -i s,DNS_CLUSTER_IP,$DNS_CLUSTER_IP,g /etc/systemd/system/kubelet.service
sed -i '/--node-ip/ a \ \ --node-labels group=traefik \\' /etc/systemd/system/kubelet.service
sed -i s,CERTIFICATE_AUTHORITY_FILE,$CA_CERTIFICATE_FILE_PATH,g /var/lib/kubelet/kubeconfig
sed -i s,CLIENT_CA_FILE,$CA_CERTIFICATE_FILE_PATH,g /etc/systemd/system/kubelet.service
systemctl daemon-reload
systemctl restart kubelet kube-proxy
USERDATA
}
###### ASG_TRAEFIK ######
variable "group_traefik" {
description = "Default values for target groups as defined by the list of maps."
type = "map"
default = {
name = "eks-nodes" # Name for the eks workers.
ami_id = "ami-dea4d5a1" # AMI ID for the eks workers. If none is provided, Terraform will searchfor the latest version of their EKS optimized worker AMI.
asg_desired_capacity = "2" # Desired worker capacity in the autoscaling group.
asg_max_size = "3" # Maximum worker capacity in the autoscaling group.
asg_min_size = "2" # Minimum worker capacity in the autoscaling group.
instance_type = "t2.small" # Size of the workers instances.
key_name = "virginia-kubernetes" # The key name that should be used for the instances in the autoscaling group
ebs_optimized = false # sets whether to use ebs optimization on supported types.
public_ip = false # Associate a public ip address with a worker
}
}
resource "aws_launch_configuration" "traefik" {
associate_public_ip_address = false
iam_instance_profile = "${aws_iam_instance_profile.eks-nodes.name}"
image_id = "${var.group_traefik["ami_id"]}"
instance_type = "${var.group_traefik["instance_type"]}"
key_name = "${var.group_traefik["key_name"]}"
name_prefix = "eks-traefik"
security_groups = ["${module.eks_nodes.id}"]
user_data_base64 = "${base64encode(local.eks-traefik-userdata)}"
ebs_optimized = "${var.group_traefik["ebs_optimized"]}"
lifecycle {
create_before_destroy = true
}
root_block_device {
delete_on_termination = true
}
}
resource "aws_autoscaling_group" "traefik" {
desired_capacity = "${var.group_traefik["asg_desired_capacity"]}"
launch_configuration = "${aws_launch_configuration.traefik.id}"
max_size = "${var.group_traefik["asg_max_size"]}"
min_size = "${var.group_traefik["asg_min_size"]}"
name = "eks-traefik-asg"
vpc_zone_identifier = [
"${module.traefik_aws_prv.ids}"
]
tag {
key = "Name"
value = "eks-traefik"
propagate_at_launch = true
}
tag {
key = "kubernetes.io/cluster/${var.cluster_defaults["name"]}"
value = "owned"
propagate_at_launch = true
}
}