Cloud service

In this tutorial, we will add a Alibaba Cloud’s RDS service as a new workload type in KubeVela.

Step 1: Install and configure Crossplane

We use Crossplane as the cloud resource operator for Kubernetes. This tutorial has been verified with Crossplane version 0.14. Please follow the Crossplane Documentation, especially the Install & Configure and Compose Infrastructure sections to configure Crossplane with your cloud account.

Note: When installing crossplane helm chart, please don’t set alpha.oam.enabled=true as OAM crds are already installed by KubeVela.

Step 2: Add Workload Definition

First, register the rds workload type to KubeVela.

  1. $ cat << EOF | kubectl apply -f -
  2. apiVersion: core.oam.dev/v1alpha2
  3. kind: WorkloadDefinition
  4. metadata:
  5. name: rds
  6. annotations:
  7. definition.oam.dev/apiVersion: "database.example.org/v1alpha1"
  8. definition.oam.dev/kind: "PostgreSQLInstance"
  9. definition.oam.dev/description: "RDS on Ali Cloud"
  10. spec:
  11. definitionRef:
  12. name: rds.apps
  13. extension:
  14. template: |
  15. output: {
  16. apiVersion: "database.example.org/v1alpha1"
  17. kind: "PostgreSQLInstance"
  18. metadata:
  19. name: context.name
  20. spec: {
  21. parameters:
  22. storageGB: parameter.storage
  23. compositionSelector: {
  24. matchLabels:
  25. provider: parameter.provider
  26. }
  27. writeConnectionSecretToRef:
  28. name: parameter.secretname
  29. }
  30. }
  31. parameter: {
  32. secretname: *"db-conn" | string
  33. provider: *"alibaba" | string
  34. storage: *20 | int
  35. }
  36. EOF

Check if the new workload type is added:

  1. $ vela workloads
  2. Synchronizing capabilities from cluster ...
  3. Sync capabilities successfully Add(1) Update(0) Delete(0)
  4. TYPE CATEGORY DESCRIPTION
  5. +rds workload RDS on Ali Cloud
  6. Listing workload capabilities ...
  7. NAME DESCRIPTION
  8. rds RDS on Ali Cloud
  9. task One-time task/job
  10. webservice Long running service with network routes
  11. worker Backend worker without ports exposed

Step 3: Try out RDS workload to an application

Let’s first create an Appfile. We will claim an RDS instance with workload type of rds. You may need to change the variables of the database service to reflect your configuration.

  1. $ cat << EOF > vela.yaml
  2. name: test-rds
  3. services:
  4. database:
  5. type: rds
  6. name: alibabaRds
  7. storage: 20
  8. checkdb:
  9. type: webservice
  10. image: nginx
  11. name: checkdb
  12. env:
  13. - name: PGDATABASE
  14. value: postgres
  15. - name: PGHOST
  16. valueFrom:
  17. secretKeyRef:
  18. name: db-conn
  19. key: endpoint
  20. - name: PGUSER
  21. valueFrom:
  22. secretKeyRef:
  23. name: db-conn
  24. key: username
  25. - name: PGPASSWORD
  26. valueFrom:
  27. secretKeyRef:
  28. name: db-conn
  29. key: password
  30. - name: PGPORT
  31. valueFrom:
  32. secretKeyRef:
  33. name: db-conn
  34. key: port
  35. EOF

Next, we could deploy the application with $ vela up.

Verify the database status

The database provision will take some time (> 5 min) to be ready. In our Appfile, we created another service called checkdb. The database will write all the connecting credentials in a secret which we put into the checkdb service as environmental variables. To verify the database configuration, we simply print out the environmental variables of the checkdb service:
$ vela exec test-rds -- printenv
After confirming the service is checkdb, we shall see the printout of the database information:

  1. PGUSER=myuser
  2. PGPASSWORD=<password>
  3. PGPORT=1921
  4. PGDATABASE=postgres
  5. PGHOST=<hostname>
  6. ...