I have an ECS service that exposes port 8080. I want to have the load balancer, target groups and target use that port as opposed to port 80. Here is a snippet of my code:
const servicePort = 8888;
const metricsPort = 8888;
const taskDefinition = new ecs.FargateTaskDefinition(this, 'TaskDef');
const repository = ecr.Repository.fromRepositoryName(this, 'cloud-config-server', 'cloud-config-server');
taskDefinition.addContainer('Config', {
image: ecs.ContainerImage.fromEcrRepository(repository),
portMappings: [{containerPort : servicePort, hostPort: servicePort}],
});
const albFargateService = new ecsPatterns.ApplicationLoadBalancedFargateService(this, 'AlbConfigService', {
cluster,
publicLoadBalancer : false,
taskDefinition: taskDefinition,
desiredCount: 1,
});
const applicationTargetGroup = new elbv2.ApplicationTargetGroup(this, 'AlbConfigServiceTargetGroup', {
targetType: elbv2.TargetType.IP,
protocol: elbv2.ApplicationProtocol.HTTP,
port: servicePort,
vpc,
healthCheck: {path: "/CloudConfigServer/actuator/env/profile", port: String(servicePort)}
});
const addApplicationTargetGroupsProps: elbv2.AddApplicationTargetGroupsProps = {
targetGroups: [applicationTargetGroup],
};
albFargateService.loadBalancer.addListener('alb-listener', {
protocol: elbv2.ApplicationProtocol.HTTP, port: servicePort, defaultTargetGroups: [applicationTargetGroup]}
);
}
}
This does not work. The health check is taking place on port 80 with the default URL of "/" which fails, and the tasks are constantly recycled. A target group on port 8080, with the appropriate health check, is added, but it has no targets.
What is the recommended way to achieve load balancing on a port other than 80?
thanks
thanks, i'll give that a try