Last active
March 6, 2023 09:25
-
-
Save fadur/363dd16371d00b2cac981f8645c16f05 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import * as cdk from '@aws-cdk/core'; | |
| import * as ecs from '@aws-cdk/aws-ecs'; | |
| import * as ec2 from '@aws-cdk/aws-ec2'; | |
| export class CdkEksFargateStack extends cdk.Stack { | |
| constructor(scope: cdk.Construct, id: string, props?: cdk.StackProps) { | |
| super(scope, id, props); | |
| // Create a VPC for the cluster | |
| const vpc = new ec2.Vpc(this, 'Vpc', { maxAzs: 2 }); | |
| // Create an ECS cluster | |
| const cluster = new ecs.Cluster(this, 'Cluster', { vpc }); | |
| // Create a Fargate task definition | |
| const taskDefinition = new ecs.FargateTaskDefinition(this, 'TaskDef'); | |
| // Add Jaeger agent container | |
| const jaegerAgent = taskDefinition.addContainer('JaegerAgent', { | |
| image: ecs.ContainerImage.fromRegistry('jaegertracing/jaeger-agent'), | |
| logging: new ecs.AwsLogDriver({ streamPrefix: 'jaeger-agent' }), | |
| environment: { | |
| REPORTER_GRPC_HOST_PORT: 'localhost:14250', | |
| REPORTER_TYPE: 'grpc', | |
| LOG_LEVEL: 'debug' | |
| } | |
| }); | |
| // Add Jaeger collector container | |
| const jaegerCollector = taskDefinition.addContainer('JaegerCollector', { | |
| image: ecs.ContainerImage.fromRegistry('jaegertracing/jaeger-collector'), | |
| logging: new ecs.AwsLogDriver({ streamPrefix: 'jaeger-collector' }), | |
| environment: { | |
| SPAN_STORAGE_TYPE: 'elasticsearch', | |
| ES_SERVER_URLS: '<your-elasticsearch-url>', | |
| COLLECTOR_ZIPKIN_HTTP_PORT: '9411', | |
| LOG_LEVEL:'debug' | |
| } | |
| }); | |
| // Add port mappings for Jaeger containers | |
| jaegerAgent.addPortMappings({ | |
| containerPort: 5775, | |
| protocol: ecs.Protocol.UDP | |
| }, { | |
| containerPort: 6831, | |
| protocol: ecs.Protocol.UDP | |
| }, { | |
| containerPort: 6832, | |
| protocol: ecs.Protocol.UDP | |
| }, { | |
| containerPort: 5778, | |
| protocol: ecs.Protocol.TCP | |
| }); | |
| jaegerCollector.addPortMappings({ | |
| containerPort :14250, | |
| protocol :ecs.Protocol.TCP | |
| },{ | |
| containerPort :14268, | |
| protocol :ecs.Protocol.TCP | |
| },{ | |
| containerPort :16686, | |
| protocol :ecs.Protocol.TCP | |
| },{ | |
| containerPort :9411, | |
| protocol :ecs.Protocol.TCP | |
| }); | |
| // Create a Fargate service with the task definition | |
| const service = new ecs.FargateService(this, "Service", { | |
| cluster, | |
| taskDefinition, | |
| }); | |
| // Allow external access to the collector port (optional) | |
| service.connections.allowFromAnyIpv4(ec2.Port.tcp(16686)); | |
| } | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment