为什么我的aws上的spring-cloud-config服务器间歇性地没有响应?

问题描述 投票:1回答:1

我正在aws上运行spring cloud config服务器,这只是一个运行spring boot应用程序的docker容器。它正在从git repo读取属性。我们的客户端应用程序在启动时间歇性地从服务器读取配置,并在运行时间歇性地读取。大约三分之一的时间,客户端应用在启动时提取配置时将超时,从而导致应用崩溃。在运行时,这些应用程序似乎成功5次成功4次,但是如果请求失败,它们将仅使用现有配置。

我正在处理ssl终止的alb后面使用ec2实例。我原本使用的是t3.micro,但是升级到了m5.large,以为t3类可能不支持连续可用性。

alb需要2个子网,因此最初创建了第二个子网。我不确定alb是否会在某个时候尝试路由到第二个子网,这可能会导致故障。目标组正在使用运行状况检查,该检查可以正确返回,但是对于alb来说足够了解,可以排除循环到空子网的可能性。我试图创建第二个ec2实例,以与第二个子网中的第一个配置服务器并行。但是,即使它使用与第一个实例相同的安全组和配置,我也无法进入第二个实例。我不确定为什么失败了,但是我猜我的设置还有其他问题。

[所有基础结构都已部署在terraform中,下面已包括在内。

resource "aws_vpc" "config-vpc" {
  cidr_block           = "10.0.0.0/16"
  enable_dns_hostnames = true
  enable_dns_support   = true
}

resource "aws_subnet" "subnet-alpha" {
  cidr_block        = cidrsubnet(aws_vpc.onfig-vpc.cidr_block, 3, 1)
  vpc_id            = aws_vpc.config-vpc.id
  availability_zone = "us-east-2a"
}

resource "aws_subnet" "subnet-beta" {
  cidr_block        = cidrsubnet(aws_vpc.config-vpc.cidr_block, 3, 2)
  vpc_id            = aws_vpc.config-vpc.id
  availability_zone = "us-east-2b"
}
resource "aws_internet_gateway" "config-vpc-ig" {
  vpc_id = aws_vpc.config-vpc.id
}

resource "aws_route_table" "config-vpc-rt" {
  vpc_id = aws_vpc.config-vpc.id
  route {
    cidr_block = "0.0.0.0/0"
    gateway_id = aws_internet_gateway.config-vpc-ig.id
  }
}

resource "aws_route_table_association" "subnet-association" {
  subnet_id      = aws_subnet.subnet-alpha.id
  route_table_id = aws_route_table.config-vpc-rt.id
}

resource "aws_alb" "alb" {
  name            = "config-alb"
  subnets         = [aws_subnet.subnet-alpha.id, aws_subnet.subnet-beta.id]
  security_groups = [aws_security_group.config_sg.id]
}

resource "aws_alb_target_group" "alb_target_group" {
  name     = "config-tg"
  port     = 9000
  protocol = "HTTP"
  vpc_id   = aws_vpc.config-vpc.id
  health_check {
    enabled  = true
    path     = "/actuator/health"
    port     = 9000
    protocol = "HTTP"
  }
}

resource "aws_alb_target_group_attachment" "config-target-alpha" {
  target_group_arn = aws_alb_target_group.alb_target_group.arn
  target_id        = aws_instance.config_server_alpha.id
  port             = 9000
}

resource "aws_alb_target_group_attachment" "config-target-beta" {
  target_group_arn = aws_alb_target_group.alb_target_group.arn
  target_id        = aws_instance.config_server_beta.id
  port             = 9000
}


resource "aws_alb_listener" "alb_listener_80" {
  load_balancer_arn = aws_alb.alb.arn
  port              = 80
  default_action {
    type = "redirect"
    redirect {
      port        = 443
      protocol    = "HTTPS"
      status_code = "HTTP_301"
    }
  }
}

resource "aws_alb_listener" "alb_listener_8080" {
  load_balancer_arn = aws_alb.alb.arn
  port              = 8080
  default_action {
    type = "redirect"
    redirect {
      port        = 443
      protocol    = "HTTPS"
      status_code = "HTTP_301"
    }
  }
}

resource "aws_alb_listener" "alb_listener_https" {
  load_balancer_arn = aws_alb.alb.arn
  port              = 443
  protocol          = "HTTPS"
  ssl_policy        = "ELBSecurityPolicy-2016-08"
  certificate_arn   = "arn:..."
  default_action {
    target_group_arn = aws_alb_target_group.alb_target_group.arn
    type             = "forward"
  }
}
resource "aws_vpc" "config-vpc" {
  cidr_block           = "10.0.0.0/16"
  enable_dns_hostnames = true
  enable_dns_support   = true
}

resource "aws_subnet" "subnet-alpha" {
  cidr_block        = cidrsubnet(aws_vpc.config-vpc.cidr_block, 3, 1)
  vpc_id            = aws_vpc.config-vpc.id
  availability_zone = "us-east-2a"
}

resource "aws_subnet" "subnet-beta" {
  cidr_block        = cidrsubnet(aws_vpc.config-vpc.cidr_block, 3, 2)
  vpc_id            = aws_vpc.config-vpc.id
  availability_zone = "us-east-2b"
}

resource "aws_internet_gateway" "config-vpc-ig" {
  vpc_id = aws_vpc.config-vpc.id
}

resource "aws_route_table" "config-vpc-rt" {
  vpc_id = aws_vpc.config-vpc.id
  route {
    cidr_block = "0.0.0.0/0"
    gateway_id = aws_internet_gateway.config-vpc-ig.id
  }
}

resource "aws_route_table_association" "subnet-association" {
  subnet_id      = aws_subnet.subnet-alpha.id
  route_table_id = aws_route_table.config-vpc-rt.id
}


amazon-web-services terraform spring-cloud-config aws-load-balancer
1个回答
© www.soinside.com 2019 - 2024. All rights reserved.