This content originally appeared on DEV Community and was authored by π Vu Dao π
Abstract
- There is question, How does ACK relate to cdk8s?
- Answer: All of the ACK controllers watch for specific CRs and you can generate those resources using cdk8s. The two projects complement each other. cdk8s can create the Kubernetes resources and ACK uses those resources to create the AWS infrastructure.
- This post gives example of generating kubernetes manifest of ACK using cdk8s typescript
Table Of Contents
- Pre-requisite
- Init cdk8s-app projen
- Import ACK CRDS As CDK8S API
- Get your hands dirty with code now
- Build manifest
- Conclusion
π Pre-requisite
- This post expects you have knowledge of ACK and cdk8s.
- You can base on the AWS Controllers for Kubernetes Hands-on to test the generated manifests by cdk8s
- projen is a plus
π Init cdk8s-app projen
- You can just init cdk8s project using
cdk8s init typescript-app
but following is used projen to mange configuration through code - Init
cdk8s-app-ts
with projen in typescript.
β‘ $ projen new cdk8s-app-ts --projenrc-ts
- cdk8s import
β‘ $ cdk8s import --language typescript --output src/imports
Importing k8s v1.22.0...
Importing resources, this may take a few moments...
k8s
π Import ACK CRDS As CDK8S API
β‘ $ cdk8s import https://raw.githubusercontent.com/aws-controllers-k8s/s3-controller/main/helm/crds/s3.services.k8s.aws_buckets.yaml --output src/imports/
Importing resources, this may take a few moments...
s3.services.k8s.aws
s3.services.k8s.aws/bucket
-
rds-controller crds, rename file from
rds.services.k8s.aws.ts
tords.services.db.instance.k8s.aws.ts
after import due to that name is assigned for all CRDS with in therds-controller
crds
β‘ $ cdk8s import https://raw.githubusercontent.com/aws-controllers-k8s/rds-controller/main/helm/crds/rds.services.k8s.aws_dbinstances.yaml --output src/imports/
Importing resources, this may take a few moments...
rds.services.k8s.aws
rds.services.k8s.aws/dbinstance
β‘ $ mv src/imports/rds.services.k8s.aws.ts src/imports/rds.services.db.instance.k8s.aws.ts
- RDS subnet group, rename file from
rds.services.k8s.aws.ts
tords.services.subnet.group.k8s.aws.ts
β‘ $ cdk8s import https://raw.githubusercontent.com/aws-controllers-k8s/rds-controller/main/helm/crds/rds.services.k8s.aws_dbsubnetgroups.yaml --output src/imports/
Importing resources, this may take a few moments...
rds.services.k8s.aws
rds.services.k8s.aws/dbsubnetgroup
β‘ $ mv src/imports/rds.services.k8s.aws.ts src/imports/rds.services.subnet.group.k8s.aws.ts
π Get your hands dirty with code now
rds
βββ constants.ts
βββ db-instance.ts
βββ subnet-group.ts
- DBInstance requires subnet group which contains private subnets in EKS VPC (
subnet-group.ts
) and secret keys to hold user credential. The k8s secret is not generated through code here. -
db-instance.ts
defines specs ofDbInstance
s3
βββ constants.ts
βββ s3.ts
π Build manifest
- Just run
yarn build
β‘ $ yarn build
yarn run v1.22.15
warning ../../../package.json: No license field
$ npx projen build
πΎ build Β» default | ts-node --project tsconfig.dev.json .projenrc.ts
πΎ build Β» compile | tsc --build
πΎ build Β» post-compile Β» synth | cdk8s synth
No manifests synthesized
πΎ build Β» test | jest --passWithNoTests --all --updateSnapshot
No tests found, exiting with code 0
----------|---------|----------|---------|---------|-------------------
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
----------|---------|----------|---------|---------|-------------------
All files | 0 | 0 | 0 | 0 |
----------|---------|----------|---------|---------|-------------------
πΎ build Β» test Β» eslint | eslint --ext .ts,.tsx --fix --no-error-on-unmatched-pattern src test build-tools .projenrc.js
Done in 25.90s.
- Output directory
dist
βββ rds
β βββ rds-db-instance.yaml
β βββ rds-subnet-group.yaml
βββ s3
βββ s3-test-bucket.yaml
- We can now use the
yaml
files to create the AWS infrastructure through ACK
π Conclusion
- Although we have to import ACK CRDS resources for cdk8s API, we can manage k8s manifests through code
.ltag__user__id__512906 .follow-action-button {
background-color: #0a6392 !important;
color: #62df88 !important;
border-color: #0a6392 !important;
}
This content originally appeared on DEV Community and was authored by π Vu Dao π
Print
Share
Comment
Cite
Upload
Translate
Updates
There are no updates yet.
Click the Upload button above to add an update.
APA
MLA
π Vu Dao π | Sciencx (2022-03-31T15:46:28+00:00) Use CDK8S To Create AWS Controllers for Kubernetes Custom Resources. Retrieved from https://www.scien.cx/2022/03/31/use-cdk8s-to-create-aws-controllers-for-kubernetes-custom-resources/
" » Use CDK8S To Create AWS Controllers for Kubernetes Custom Resources." π Vu Dao π | Sciencx - Thursday March 31, 2022, https://www.scien.cx/2022/03/31/use-cdk8s-to-create-aws-controllers-for-kubernetes-custom-resources/
HARVARDπ Vu Dao π | Sciencx Thursday March 31, 2022 » Use CDK8S To Create AWS Controllers for Kubernetes Custom Resources., viewed ,<https://www.scien.cx/2022/03/31/use-cdk8s-to-create-aws-controllers-for-kubernetes-custom-resources/>
VANCOUVERπ Vu Dao π | Sciencx - » Use CDK8S To Create AWS Controllers for Kubernetes Custom Resources. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2022/03/31/use-cdk8s-to-create-aws-controllers-for-kubernetes-custom-resources/
CHICAGO" » Use CDK8S To Create AWS Controllers for Kubernetes Custom Resources." π Vu Dao π | Sciencx - Accessed . https://www.scien.cx/2022/03/31/use-cdk8s-to-create-aws-controllers-for-kubernetes-custom-resources/
IEEE" » Use CDK8S To Create AWS Controllers for Kubernetes Custom Resources." π Vu Dao π | Sciencx [Online]. Available: https://www.scien.cx/2022/03/31/use-cdk8s-to-create-aws-controllers-for-kubernetes-custom-resources/. [Accessed: ]
rf:citation » Use CDK8S To Create AWS Controllers for Kubernetes Custom Resources | π Vu Dao π | Sciencx | https://www.scien.cx/2022/03/31/use-cdk8s-to-create-aws-controllers-for-kubernetes-custom-resources/ |
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.