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

add network L4 loadbalancer (NLB) to cluster and services for TCP/UDP #317

Merged
merged 1 commit into from
Jun 11, 2024
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
183 changes: 183 additions & 0 deletions eks/eks-blue/nlb.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@
resource "aws_lb" "nlb" {
name = "${var.environment_name}-nlb"
internal = false
load_balancer_type = "network"
subnets = module.eks_cluster.vpc_public_subnets

tags = {
Name = "${var.environment_name}-nlb"
}
}

# Define target groups and listeners for TCP ports
locals {
tcp_ports = [30333, 30433, 30334, 40333, 30533]
}

resource "aws_lb_target_group" "tg_tcp" {
count = length(local.tcp_ports)

name = "${var.environment_name}-tg-tcp-${local.tcp_ports[count.index]}"
port = local.tcp_ports[count.index]
protocol = "TCP"
vpc_id = module.eks_cluster.vpc_id

health_check {
enabled = true
interval = 30
port = local.tcp_ports[count.index] # Use the same port for health checks
protocol = "TCP"
timeout = 5
healthy_threshold = 2
unhealthy_threshold = 2
}

tags = {
Name = "${var.environment_name}-tg-tcp-${local.tcp_ports[count.index]}"
}
}

resource "aws_lb_listener" "nlb_listener_tcp" {
count = length(local.tcp_ports)

load_balancer_arn = aws_lb.nlb.arn
port = local.tcp_ports[count.index]
protocol = "TCP"

default_action {
type = "forward"
target_group_arn = aws_lb_target_group.tg_tcp[count.index].arn
}
}

# Define target groups and listeners for UDP ports
locals {
udp_ports = [30333, 30433, 30334, 30533]
}

resource "aws_lb_target_group" "tg_udp" {
count = length(local.udp_ports)

name = "${var.environment_name}-tg-udp-${local.udp_ports[count.index]}"
port = local.udp_ports[count.index]
protocol = "UDP"
vpc_id = module.eks_cluster.vpc_id

health_check {
enabled = false # UDP health checks are not supported
}

tags = {
Name = "${var.environment_name}-tg-udp-${local.udp_ports[count.index]}"
}
}

resource "aws_lb_listener" "nlb_listener_udp" {
count = length(local.udp_ports)

load_balancer_arn = aws_lb.nlb.arn
port = local.udp_ports[count.index]
protocol = "UDP"

default_action {
type = "forward"
target_group_arn = aws_lb_target_group.tg_udp[count.index].arn
}
}

# Define security group rules for EKS cluster
resource "aws_security_group" "eks_security_group_network" {
name = "${var.environment_name}-eks-sg-network"
description = "Security group for EKS cluster"
vpc_id = module.eks_cluster.vpc_id

ingress {
description = "Node Port 30333 for VPC"
from_port = 30333
to_port = 30333
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
ipv6_cidr_blocks = ["::/0"]
}

ingress {
description = "Node Port 30433 for VPC"
from_port = 30433
to_port = 30433
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
ipv6_cidr_blocks = ["::/0"]
}

ingress {
description = "Node Port 30334 Domain port for VPC"
from_port = 30334
to_port = 30334
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
ipv6_cidr_blocks = ["::/0"]
}

ingress {
description = "Domain Operator Node Port 40333 for VPC"
from_port = 40333
to_port = 40333
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
ipv6_cidr_blocks = ["::/0"]
}

ingress {
description = "Farmer Port 30533 for VPC"
from_port = 30533
to_port = 30533
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
ipv6_cidr_blocks = ["::/0"]
}

ingress {
description = "Node UDP Port 30333 for VPC"
from_port = 30333
to_port = 30333
protocol = "udp"
cidr_blocks = ["0.0.0.0/0"]
ipv6_cidr_blocks = ["::/0"]
}

ingress {
description = "Node UDP Port 30433 for VPC"
from_port = 30433
to_port = 30433
protocol = "udp"
cidr_blocks = ["0.0.0.0/0"]
ipv6_cidr_blocks = ["::/0"]
}

ingress {
description = "Node UDP Port 30334 Domain port for VPC"
from_port = 30334
to_port = 30334
protocol = "udp"
cidr_blocks = ["0.0.0.0/0"]
ipv6_cidr_blocks = ["::/0"]
}

ingress {
description = "Farmer UDP Port 30533 for VPC"
from_port = 30533
to_port = 30533
protocol = "udp"
cidr_blocks = ["0.0.0.0/0"]
ipv6_cidr_blocks = ["::/0"]
}

egress {
description = "egress for VPC"
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
ipv6_cidr_blocks = ["::/0"]
}
}
183 changes: 183 additions & 0 deletions eks/eks-green/nlb.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@
resource "aws_lb" "nlb" {
name = "${var.environment_name}-nlb"
internal = false
load_balancer_type = "network"
subnets = module.eks_cluster.vpc_public_subnets

tags = {
Name = "${var.environment_name}-nlb"
}
}

# Define target groups and listeners for TCP ports
locals {
tcp_ports = [30333, 30433, 30334, 40333, 30533]
}

resource "aws_lb_target_group" "tg_tcp" {
count = length(local.tcp_ports)

name = "${var.environment_name}-tg-tcp-${local.tcp_ports[count.index]}"
port = local.tcp_ports[count.index]
protocol = "TCP"
vpc_id = module.eks_cluster.vpc_id

health_check {
enabled = true
interval = 30
port = local.tcp_ports[count.index] # Use the same port for health checks
protocol = "TCP"
timeout = 5
healthy_threshold = 2
unhealthy_threshold = 2
}

tags = {
Name = "${var.environment_name}-tg-tcp-${local.tcp_ports[count.index]}"
}
}

resource "aws_lb_listener" "nlb_listener_tcp" {
count = length(local.tcp_ports)

load_balancer_arn = aws_lb.nlb.arn
port = local.tcp_ports[count.index]
protocol = "TCP"

default_action {
type = "forward"
target_group_arn = aws_lb_target_group.tg_tcp[count.index].arn
}
}

# Define target groups and listeners for UDP ports
locals {
udp_ports = [30333, 30433, 30334, 30533]
}

resource "aws_lb_target_group" "tg_udp" {
count = length(local.udp_ports)

name = "${var.environment_name}-tg-udp-${local.udp_ports[count.index]}"
port = local.udp_ports[count.index]
protocol = "UDP"
vpc_id = module.eks_cluster.vpc_id

health_check {
enabled = false # UDP health checks are not supported
}

tags = {
Name = "${var.environment_name}-tg-udp-${local.udp_ports[count.index]}"
}
}

resource "aws_lb_listener" "nlb_listener_udp" {
count = length(local.udp_ports)

load_balancer_arn = aws_lb.nlb.arn
port = local.udp_ports[count.index]
protocol = "UDP"

default_action {
type = "forward"
target_group_arn = aws_lb_target_group.tg_udp[count.index].arn
}
}

# Define security group rules for EKS cluster
resource "aws_security_group" "eks_security_group_network" {
name = "${var.environment_name}-eks-sg-network"
description = "Security group for EKS cluster"
vpc_id = module.eks_cluster.vpc_id

ingress {
description = "Node Port 30333 for VPC"
from_port = 30333
to_port = 30333
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
ipv6_cidr_blocks = ["::/0"]
}

ingress {
description = "Node Port 30433 for VPC"
from_port = 30433
to_port = 30433
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
ipv6_cidr_blocks = ["::/0"]
}

ingress {
description = "Node Port 30334 Domain port for VPC"
from_port = 30334
to_port = 30334
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
ipv6_cidr_blocks = ["::/0"]
}

ingress {
description = "Domain Operator Node Port 40333 for VPC"
from_port = 40333
to_port = 40333
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
ipv6_cidr_blocks = ["::/0"]
}

ingress {
description = "Farmer Port 30533 for VPC"
from_port = 30533
to_port = 30533
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
ipv6_cidr_blocks = ["::/0"]
}

ingress {
description = "Node UDP Port 30333 for VPC"
from_port = 30333
to_port = 30333
protocol = "udp"
cidr_blocks = ["0.0.0.0/0"]
ipv6_cidr_blocks = ["::/0"]
}

ingress {
description = "Node UDP Port 30433 for VPC"
from_port = 30433
to_port = 30433
protocol = "udp"
cidr_blocks = ["0.0.0.0/0"]
ipv6_cidr_blocks = ["::/0"]
}

ingress {
description = "Node UDP Port 30334 Domain port for VPC"
from_port = 30334
to_port = 30334
protocol = "udp"
cidr_blocks = ["0.0.0.0/0"]
ipv6_cidr_blocks = ["::/0"]
}

ingress {
description = "Farmer UDP Port 30533 for VPC"
from_port = 30533
to_port = 30533
protocol = "udp"
cidr_blocks = ["0.0.0.0/0"]
ipv6_cidr_blocks = ["::/0"]
}

egress {
description = "egress for VPC"
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
ipv6_cidr_blocks = ["::/0"]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ kind: Service
metadata:
name: boostrap-domain-node-service
namespace: bootstrap-domain
annotations:
service.beta.kubernetes.io/aws-load-balancer-type: "nlb"
service.beta.kubernetes.io/aws-load-balancer-nlb-target-type: "instance"
spec:
selector:
app: domain-node
Expand Down Expand Up @@ -44,4 +47,4 @@ spec:
protocol: TCP
port: 9616
targetPort: 9616
type: ClusterIP
type: LoadBalancer
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ apiVersion: v1
kind: ConfigMap
metadata:
name: bootstrap-node-config
namespace: bootstrap-node
data:
NETWORK_NAME: "network-name"
EXTERNAL_IP: "external-ip"
Expand Down
Loading