Provision and Binding Database

Provision and Binding Database - 图1tip

This section requires your platform engineers have already enabled terraform addon.

This tutorial will talk about how to provision and consume Alibaba Cloud RDS (and OSS) by Terraform.

Let’s deploy the application below to provision Alibaba Cloud OSS and RDS cloud resources, and consume them by the web component.

  1. apiVersion: core.oam.dev/v1beta1
  2. kind: Application
  3. metadata:
  4. name: webapp
  5. spec:
  6. components:
  7. - name: express-server
  8. type: webservice
  9. properties:
  10. image: zzxwill/flask-web-application:v0.3.1-crossplane
  11. port: 80
  12. traits:
  13. - type: service-binding
  14. properties:
  15. envMappings:
  16. # environments refer to db-conn secret
  17. DB_PASSWORD:
  18. secret: db-conn # 1) If the env name is the same as the secret key, secret key can be omitted.
  19. endpoint:
  20. secret: db-conn
  21. key: DB_PUBLIC_HOS # 2) If the env name is different from secret key, secret key has to be set.
  22. username:
  23. secret: db-conn
  24. key: DB_USER
  25. # environments refer to oss-conn secret
  26. BUCKET_NAME:
  27. secret: oss-conn
  28. - name: sample-db
  29. type: alibaba-rds
  30. properties:
  31. instance_name: sample-db
  32. account_name: oamtest
  33. password: U34rfwefwefffaked
  34. writeConnectionSecretToRef:
  35. name: db-conn
  36. - name: sample-oss
  37. type: alibaba-oss
  38. properties:
  39. bucket: vela-website-0911
  40. acl: private
  41. writeConnectionSecretToRef:
  42. name: oss-conn

The component sample-db will generate secret db-conn with these keys, and the component sample-oss will generate secret oss-conn. These secrets are binded to the Envs of component express-server by trait Service Binding. Then the component can consume instances of OSS and RDS.

Deploy and verify the application.

  1. $ vela ls
  2. APP COMPONENT TYPE TRAITS PHASE HEALTHY STATUS CREATED-TIME
  3. webapp express-server webservice service-binding running healthy 2021-09-08 16:50:41 +0800 CST
  4. ├─ sample-db alibaba-rds running healthy 2021-09-08 16:50:41 +0800 CST
  5. └─ sample-oss alibaba-oss running healthy 2021-09-08 16:50:41 +0800 CST
  1. $ vela port-forward webapp
  2. Forwarding from 127.0.0.1:8080 -> 80
  3. Forwarding from [::1]:8080 -> 80
  4. Forward successfully! Opening browser ...

Provision and Binding Database - 图2

Last updated on Feb 9, 2023 by dependabot[bot]