- VPC
- EKS cluster
- EKS nodegroup
- Build and push to ECR
- Deploy
npm install -g [email protected]
# install packages in the root folder
npm install
cdk bootstrapUse the cdk command-line toolkit to interact with your project:
cdk deploy: deploys your app into an AWS accountcdk synth: synthesizes an AWS CloudFormation template for your appcdk diff: compares your app with the deployed stackcdk watch: deployment every time a file change is detected
| Stack | Time | |
|---|---|---|
| 1 | VPC | 3m 30s (optional) |
| 2 | EKS cluster | 13m |
| 3 | EKS nodegroups | 10m |
| 4 | Build image and push to ECR | 4m |
| 5 | Deploy(including ALB) | 4m |
| Total | 31m (34m 30s with a new VPC) |
The VPC ID will be saved into the SSM Parameter Store named /eks-cdk/vpc-id to refer from other stacks.
Create the SSM Parameter if you want to use the existing VPC:
aws ssm put-parameter --name "/eks-cdk/vpc-id" --value "{existing-vpc-id}" --type String cd vpc
cdk deploycd ../eks-cluster-nodegroup
cdk deploy
# or define your VPC id with context parameter
cdk deploy -c vpcId=<vpc-id>02-eks-cluster/lib/cluster-stack.ts
SSM parameter:
- /eks-cdk/vpc-id
Cluster Name: config.ts
cd ../03-eks-nodegroup
cdk deploy SSM parameters:
- /eks-cdk/vpc-id
- /${clusterName}/openid-connect-provider-arn
- /${clusterName}/kubectl-role-arn
clusterName: eks-cluster-local, eks-cluster-dev, eks-cluster-stg03-eks-nodegroup/lib/nodegroup-stack.ts
Build and push to ECR:
cd ../04-ecr
cdk deploy Create a YAML file for K8s Deployment, Service, HorizontalPodAutoscaler, and Ingress using a template file.
cd ../app
sed -e "s|<account-id>|${ACCOUNT_ID}|g" ping-api-template.yaml | sed -e "s|<region>|${REGION}|g" > ping-api.yaml
cat ping-api.yaml
kubectl apply -f ping-api.yamlfind . -name "node_modules" -exec rm -rf {} \;
find . -name "cdk.context.json" -exec rm -f {} \;
find . -name "cdk.out" -exec rm -rf {} \;
find . -name "build" -exec rm -rf {} \;
cd 04-ecr
cdk destroy
cd ../03-eks-nodegroup
cdk destroy
cd ../02-eks-cluster
cdk destroy
cd ../01-vpc
cdk destroy.
├── build.gradle
├── config.ts
├── package-lock.json
├── package.json
├── tsconfig.json
├── 01-vpc
│ ├── bin
│ │ └── index.ts
│ ├── cdk.json
│ ├── jest.config.js
│ └── lib
│ └── vpc-stack.ts
├── 02 eks-cluster
│ ├── bin
│ │ └── index.ts
│ ├── cdk.json
│ ├── jest.config.js
│ └── lib
│ └── cluster-stack.ts
├── 03-eks-nodegroup
│ ├── bin
│ │ └── index.ts
│ ├── cdk.json
│ ├── jest.config.js
│ └── lib
│ └── nodegroup-stack.ts
├── 04-ecr
│ ├── bin
│ │ └── index.ts
│ ├── cdk.json
│ └── lib
│ └── ecr-stack.ts
├── eks-cluster-nodegroup
│ ├── bin
│ │ └── index.ts
│ ├── cdk.json
│ ├── jest.config.js
│ └── lib
│ └── cluster-nodegroup-stack.ts
├── app
│ ├── Dockerfile
│ ├── build.gradle
│ ├── build.sh
│ ├── ping-api-template.yaml
│ └── src
│ └── main
│ ├── java
│ │ └── com
│ │ └── sample
│ │ ├── SampleApplication.java
│ │ └── SampleController.java
│ └── resources
│ └── application.yaml
