in fargate/eks_cdk/lib/eks_cdk-stack.ts [10:71]
constructor(scope: cdk.Construct, id: string, props?: cdk.StackProps) {
super(scope, id, props);
// define the vpc
const vpc = new ec2.Vpc(this, "quarkus-demo-vpc", {
maxAzs: 2
});
// create EKS cluster
const cluster = new eks.FargateCluster(this, "quarkus-demo-cluster", {
clusterName: "quarkus-demo-cluster",
version: eks.KubernetesVersion.V1_17,
vpc
});
// add ALB ingress controller
const albIngressController = new ALBIngressController(this, "ALB-ingress-controller", {
cluster: cluster,
vpcId: vpc.vpcId,
region: this.region,
version: "1.1.7"
});
albIngressController.node.addDependency(cluster);
// add service account
const sa = cluster.addServiceAccount("quarkus-service-account", {
name: "quarkus-service-account",
namespace: "default"
});
const appLabel = { app: "quarkus-demo" };
const deployment = EksCdkStack.getQuarkusStsDeploymentK8sDefinition(appLabel, sa);
const service = EksCdkStack.getQuarkusServiceK8sDefinition(appLabel);
const ingress = EksCdkStack.getQuarkusAlbIngressK8sDefinition(appLabel);
// deploy manifest
cluster.addManifest("quarkus-demo", deployment, service, ingress)
// query the load balancer address
const loadBalancerDNS = new eks.KubernetesObjectValue(this, "LoadBalancerAttribute", {
cluster: cluster,
objectType: "ingress",
objectName: "quarkus-demo-ingress",
jsonPath: ".status.loadBalancer.ingress[0].hostname", // https://kubernetes.io/docs/reference/kubectl/jsonpath/
});
new CfnOutput(this, "LoadBalancerDNS", {
value: loadBalancerDNS.value
});
// create the application Users dynomodb table
const table = new dynamodb.Table(this, "Users", {
partitionKey: { name: "userId", type: dynamodb.AttributeType.STRING, },
tableName: "Users",
readCapacity: 1,
writeCapacity: 1,
removalPolicy: cdk.RemovalPolicy.DESTROY, // NOT recommended for production code
});
table.grantReadWriteData(sa.role)
}