Provision Instance and Database Separately

In the guide Provision and Binding Cloud Resources and Provision a Database and Import a SQL File for initialization, We create an RDS instance and a database together. However, you can create an RDS instance and more than one database on it. This pattern is useful when you want to save costs of creating multiple instances.

This guide will take Alibaba Cloud RDS as an example to show how to create an RDS instance more than one database separately.

  1. terraform addon has been enabled
  2. terraform-alibaba addon has been enabled, version >= 1.0.3
  3. Credentials have been configured using vela provider add terraform-alibaba If you have problems, you can follow to this instruction to setup.

Using the following Application to create an RDS instance.

  1. apiVersion: core.oam.dev/v1beta1
  2. kind: Application
  3. metadata:
  4. name: app-rds-instance
  5. spec:
  6. components:
  7. - name: rds-instance
  8. type: alibaba-rds-instance
  9. properties:
  10. instance_name: test_single_instance

Now you can get the RDS instance ID by running the following command:

  1. kubectl get configuration -n default rds-instance -ojson | jq -r .status.apply.outputs.instance_id.value

The result will be like

  1. rm-bp1du0wif7kXXXXX

Using the following Application to create an RDS database. Remember to replace <your-region> and <your-instance-id> with the real values.

  1. apiVersion: core.oam.dev/v1beta1
  2. kind: Application
  3. metadata:
  4. name: app-db-1
  5. spec:
  6. components:
  7. - name: demo-database-1
  8. type: alibaba-rds-database
  9. properties:
  10. region: <your-region>
  11. existing_instance_id: <your-instance-id>
  12. database_name: first_database
  13. password: fake_password
  14. account_name: first_db_account

About 2 minutes later, you can check the app status by running vela status:

  1. vela status app-db-1 -n default

You have learnt how to create an RDS instance and a database with different applications. As a platform engineer, you can use this pattern to provide database sharing the same instance to your users. When the business is growing, you can migrate database to an exclusive instance.

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