
EC2 Auto-Scaling 그룹이 지원하는 ECS 클러스터를 생성하고 NFS 스토리지에 EFS를 사용하는 서비스를 시작했습니다. 서비스가 awsvpc
네트워크 모드에서 실행 중이므로 서비스로 들어오고 나가는 트래픽을 제어할 수 있습니다. 자체적으로 그리고 (문제 해결을 위해) 0.0.0.0/0에서 TCP2049/NFS4에 대한 액세스를 허용하는 보안 그룹이 있으며 이는 EFS 마운트 지점과 ECS 서비스 모두에 연결되어 있습니다. EFS와 ECS/EC2 머신은 모두 동일한 VPC와 동일한 3개의 서브넷에 있습니다.
그러나 서비스가 ECS에 작업을 배포하지 못합니다. 작업이 다음 오류로 인해 충돌합니다.
Error response from daemon: create ecs-service-1-images-d6b491fbece8ddc34b00: VolumeDriver.Create: mounting volume failed:
Mount attempt 1/3 failed due to timeout after 15 sec, wait 0 sec before next attempt.
Mount attempt 2/3 failed due to timeout after 15 sec, wait 0 sec before next attempt.
'mount.nfs4: Connection reset by peer'
EC2 ECS 호스트 자체에 EFS 볼륨을 마운트하는 것은 다음과 같이 작동합니다.
[ec2-user@ip-100-xxx ~]$ sudo mount -t efs fs-05dexxxxxxxx /mnt/efs
[ec2-user@ip-100-xxx ~]$ mount | grep fs-05de
fs-05dexxxxxxx.efs.eu-central-1.amazonaws.com:/ on /mnt/efs type nfs4
이 동작의 원인은 무엇입니까? 모든 리소스는 Terraform에 있습니다.
resource "aws_autoscaling_group" "ecs-infrastructure-asg" {
name = "ecs-infrastructure-asg"
vpc_zone_identifier = [
data.aws_subnet.PrivateA.id,
data.aws_subnet.PrivateB.id,
data.aws_subnet.PrivateC.id
]
}
resource "aws_ecs_capacity_provider" "ecs-infrastructure-cp" {
name = "infrastructure-cp"
auto_scaling_group_provider {
auto_scaling_group_arn = aws_autoscaling_group.ecs-infrastructure-asg.arn
}
}
resource "aws_ecs_cluster" "infrastructure" {
name = "infrastructure"
}
resource "aws_ecs_cluster_capacity_providers" "infrastructure-ccp" {
cluster_name = aws_ecs_cluster.infrastructure.name
capacity_providers = [aws_ecs_capacity_provider.ecs-infrastructure-cp.name]
default_capacity_provider_strategy {
capacity_provider = aws_ecs_capacity_provider.ecs-infrastructure-cp.name
}
}
resource "aws_security_group" "passbolt-allow-nfs-inbound" {
name = "passbolt-allow-nfs-inbound"
vpc_id = data.aws_vpc.VPC01.id
ingress {
from_port = 2049
to_port = 2049
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
ipv6_cidr_blocks = ["::/0"]
}
ingress {
from_port = 2049
to_port = 2049
protocol = "tcp"
self = true
}
}
resource "aws_efs_file_system" "passbolt-efs-fs" {
}
resource "aws_efs_mount_target" "passbolt-efs-mt-priva" {
file_system_id = aws_efs_file_system.passbolt-efs-fs.id
subnet_id = data.aws_subnet.PrivateA.id
security_groups = [aws_security_group.passbolt-allow-nfs-inbound.id]
}
resource "aws_ecs_task_definition" "passbolt-task" {
family = "service"
network_mode = "awsvpc"
container_definitions = jsonencode([
{
name = "passbolt-app"
mountPoints = [
{
sourceVolume = "images"
containerPath = "/usr/share/php/passbolt/webroot/img/public"
readOnly = false
} ]
},
])
volume {
name = "images"
efs_volume_configuration {
file_system_id = aws_efs_file_system.passbolt-efs-fs.id
root_directory = "/images"
}
}
}
resource "aws_ecs_service" "infrastructure-passbolt" {
name = "infrastructure-passbolt"
cluster = aws_ecs_cluster.infrastructure.id
task_definition = aws_ecs_task_definition.passbolt-task.arn
desired_count = 1
capacity_provider_strategy {
capacity_provider = aws_ecs_capacity_provider.ecs-infrastructure-cp.name
weight = 100
}
network_configuration {
subnets = [
data.aws_subnet.PrivateA.id,
data.aws_subnet.PrivateB.id,
data.aws_subnet.PrivateC.id
]
security_groups = [
aws_security_group.passbolt-allow-nfs-inbound.id,
]
}
}
답변1
원인을 찾았습니다. 보안 그룹이 Terraform에 의해 생성되었으므로 송신 규칙이 없습니다. 0.0.0.0/0
연결을 수정 하기 위해 송신을 허용하는 항목을 추가합니다 .