|
| 1 | +# DBaaS Quick Start Guide |
| 2 | + |
| 3 | +This document describes how to provision NuoDB databases in multi-tenancy model by using NuoDB Control Plane (CP). |
| 4 | +NuoDB Control Plane works with [Kubernetes][1] locally or in the cloud. |
| 5 | +The steps in this guide can be followed regardless of the selected Kubernetes platform provider. |
| 6 | + |
| 7 | +## Prerequisites |
| 8 | + |
| 9 | +- A running [Kubernetes cluster][2] |
| 10 | +- [kubectl][3] installed and able to access the cluster. |
| 11 | +- [Helm 3.x][4] installed. |
| 12 | + |
| 13 | +## Installing Dependencies |
| 14 | + |
| 15 | +### Install Cert Manager |
| 16 | + |
| 17 | +To enable [admission webhooks][7] in the NuoDB operator, [cert-manager](https://github.com/cert-manager/cert-manager) must be installed to automatically generate certificates for the webhook server. |
| 18 | + |
| 19 | +Add the official Helm repositories. |
| 20 | + |
| 21 | +```sh |
| 22 | +helm repo add jetstack https://charts.jetstack.io |
| 23 | +helm repo update |
| 24 | +``` |
| 25 | + |
| 26 | +Install Cert Manager Helm chart. |
| 27 | + |
| 28 | +```sh |
| 29 | +helm upgrade --install cert-manager jetstack/cert-manager \ |
| 30 | + --namespace cert-manager \ |
| 31 | + --set installCRDs=true \ |
| 32 | + --create-namespace |
| 33 | +``` |
| 34 | + |
| 35 | +Wait for Cert Manager to become available. |
| 36 | + |
| 37 | +```sh |
| 38 | +kubectl -n cert-manager wait pod --all --for=condition=Ready |
| 39 | +``` |
| 40 | + |
| 41 | +## Installing NuoDB Control Plane |
| 42 | + |
| 43 | +The NuoDB Control Plane consists of [Custom Resource Definitions][5] and the following workloads: |
| 44 | + |
| 45 | +- *NuoDB CP Operator*, which enforces the desired state of the NuoDB [custom resources][6]. |
| 46 | +- *NuoDB CP REST service*, that exposes a REST API allowing users to manipulate and inspect DBaaS entities. |
| 47 | + |
| 48 | +By default the NuoDB CP will operate in a single namespace only which will be used for NuoDB CP and all databases created by it. |
| 49 | +The databases are grouped into *projects*, which are themselves grouped into *organizations*. |
| 50 | + |
| 51 | +Add the official Helm repositories. |
| 52 | + |
| 53 | +```sh |
| 54 | +helm repo add nuodb-cp https://nuodb.github.io/nuodb-cp-releases/charts |
| 55 | +helm repo update |
| 56 | +``` |
| 57 | + |
| 58 | +Install NuoDB CP Helm charts. |
| 59 | + |
| 60 | +```sh |
| 61 | +helm upgrade --install nuodb-cp-crd nuodb-cp/nuodb-cp-crd \ |
| 62 | + --namespace nuodb-cp-system \ |
| 63 | + --create-namespace |
| 64 | + |
| 65 | +helm upgrade --install nuodb-cp-operator nuodb-cp/nuodb-cp-operator \ |
| 66 | + --namespace nuodb-cp-system \ |
| 67 | + --set cpOperator.webhooks.enabled=true \ |
| 68 | + --set 'cpOperator.extraArgs[0]=--ingress-https-port=48006' # Enables connecting to databases with port-forwarding |
| 69 | + |
| 70 | +helm upgrade --install nuodb-cp-rest nuodb-cp/nuodb-cp-rest \ |
| 71 | + --namespace nuodb-cp-system \ |
| 72 | + --set cpRest.authentication.enabled=true \ |
| 73 | + --set cpRest.authentication.admin.create=true \ |
| 74 | + --set cpRest.baseDomainName=dbaas.localtest.me # Enables connecting to databases with port-forwarding |
| 75 | +``` |
| 76 | + |
| 77 | +Wait for NuoDB Control Plane to become available. |
| 78 | + |
| 79 | +```sh |
| 80 | +kubectl -n nuodb-cp-system -l app=nuodb-cp-operator wait pod --all --for=condition=Ready |
| 81 | +kubectl -n nuodb-cp-system -l app=nuodb-cp-rest wait pod --all --for=condition=Ready |
| 82 | +``` |
| 83 | + |
| 84 | +## Creating NuoDB Database |
| 85 | + |
| 86 | +Once the Control Plane is deployed, projects and databases can now be created. |
| 87 | + |
| 88 | +### Access and Authentication |
| 89 | + |
| 90 | +This guide will use port forwarding and [cURL][9] to demonstrate how to create projects and databases through the REST service. |
| 91 | + |
| 92 | +```sh |
| 93 | +kubectl port-forward -n nuodb-cp-system svc/nuodb-cp-rest 8080 2>&1 >/dev/null & |
| 94 | +``` |
| 95 | + |
| 96 | +To successfully authenticate with the REST API, get the *system/admin* user's password from the cluster: |
| 97 | + |
| 98 | +```sh |
| 99 | +PASS=$(kubectl get secret dbaas-user-system-admin -n nuodb-cp-system -o jsonpath='{.data.password}' | base64 -d) |
| 100 | +BASE_URL="http://localhost:8080" |
| 101 | +``` |
| 102 | + |
| 103 | +### Create Project |
| 104 | + |
| 105 | +Create a new project *messaging* in organization *acme*: |
| 106 | + |
| 107 | +```sh |
| 108 | +curl -u "system/admin:$PASS" -X PUT -H 'Content-Type: application/json' \ |
| 109 | + $BASE_URL/projects/acme/messaging \ |
| 110 | + -d '{"sla": "dev", "tier": "n0.small"}' |
| 111 | +``` |
| 112 | + |
| 113 | +>**Note** |
| 114 | +> Creating project and database with `n0.small` service tier will require 3 vCPU and 5Gi RAM allocatable resources from your cluster. If your setup is resource constrained, consider using `n0.nano` service tier. |
| 115 | +
|
| 116 | +Wait for the project to become available. |
| 117 | + |
| 118 | +```sh |
| 119 | +while [ "$(curl -s -u "system/admin:$PASS" $BASE_URL/projects/acme/messaging | jq '.status.ready')" != "true" ]; do echo "Waiting ..."; sleep 5; done; echo "Domain is available" |
| 120 | +``` |
| 121 | + |
| 122 | +### Create database |
| 123 | + |
| 124 | +Create a new database *demo* in project *messaging*: |
| 125 | + |
| 126 | +```sh |
| 127 | +curl -u "system/admin:$PASS" -X PUT -H 'Content-Type: application/json' \ |
| 128 | + $BASE_URL/databases/acme/messaging/demo \ |
| 129 | + -d '{"dbaPassword": "secret"}' |
| 130 | +``` |
| 131 | + |
| 132 | +Wait for the database to become available. |
| 133 | + |
| 134 | +```sh |
| 135 | +while [ "$(curl -s -u "system/admin:$PASS" $BASE_URL/databases/acme/messaging/demo | jq '.status.ready')" != "true" ]; do echo "Waiting ..."; sleep 5; done; echo "Database is available" |
| 136 | +``` |
| 137 | + |
| 138 | +### Connect to Database |
| 139 | + |
| 140 | +This guide will use port forwarding to connect to the NuoDB database. |
| 141 | + |
| 142 | +```sh |
| 143 | +ADMIN_SVC=$(kubectl get svc -n nuodb-cp-system \ |
| 144 | + -l 'cp.nuodb.com/organization=acme,cp.nuodb.com/project=messaging,!cp.nuodb.com/database' -oname | grep "clusterip") |
| 145 | +DB_SVC=$(kubectl get svc -n nuodb-cp-system \ |
| 146 | + -l "cp.nuodb.com/organization=acme,cp.nuodb.com/project=messaging,cp.nuodb.com/database" -oname) |
| 147 | +kubectl port-forward -n nuodb-cp-system $ADMIN_SVC 48004 2>&1 >/dev/null & |
| 148 | +kubectl port-forward -n nuodb-cp-system $DB_SVC 48006 2>&1 >/dev/null & |
| 149 | +``` |
| 150 | + |
| 151 | +Connect to the NuoDB database via `nuosql` (requires [nuodb-client][8] package v20230228 or later). |
| 152 | + |
| 153 | +```sh |
| 154 | +CA_CERT="$(curl -s -u "system/admin:$PASS" $BASE_URL/databases/acme/messaging/demo | jq -r '.status.caPem')" |
| 155 | +DB_URL="$(curl -s -u "system/admin:$PASS" $BASE_URL/databases/acme/messaging/demo | jq -r '.status.sqlEndpoint')" |
| 156 | +nuosql "demo@${DB_URL}" --user dba --password secret --connection-property trustedCertificates="$CA_CERT" |
| 157 | +``` |
| 158 | + |
| 159 | +### Cleanup |
| 160 | + |
| 161 | +- Delete all custom resources that have been created in `nuodb-cp-system` namespace. |
| 162 | + |
| 163 | +```sh |
| 164 | +kubectl config set-context --current --namespace=nuodb-cp-system |
| 165 | +kubectl get databases.cp.nuodb.com -o name | xargs kubectl delete |
| 166 | +kubectl get domains.cp.nuodb.com -o name | xargs kubectl delete |
| 167 | +kubectl get servicetiers.cp.nuodb.com -o name | xargs kubectl delete |
| 168 | +kubectl get helmfeatures.cp.nuodb.com -o name | xargs kubectl delete |
| 169 | +kubectl get databasequotas.cp.nuodb.com -o name | xargs -r kubectl delete |
| 170 | +kubectl get secrets -o name --selector=cp.nuodb.com/organization | xargs -r kubectl delete |
| 171 | +kubectl get pvc -o name --selector=group=nuodb | xargs -r kubectl delete |
| 172 | +``` |
| 173 | + |
| 174 | +- Cleanup the installed resources in the following order: |
| 175 | + |
| 176 | +```sh |
| 177 | +helm uninstall nuodb-cp-rest --namespace nuodb-cp-system |
| 178 | +helm uninstall nuodb-cp-operator --namespace nuodb-cp-system |
| 179 | +helm uninstall nuodb-cp-crd --namespace nuodb-cp-system |
| 180 | +helm uninstall cert-manager --namespace cert-manager |
| 181 | +``` |
| 182 | + |
| 183 | +- Delete the provisioned namespace: |
| 184 | + |
| 185 | +```sh |
| 186 | +kubectl delete namespace nuodb-cp-system |
| 187 | +kubectl delete namespace cert-manager |
| 188 | +``` |
| 189 | + |
| 190 | +[1]: https://kubernetes.io/docs/home/ |
| 191 | +[2]: https://kubernetes.io/docs/concepts/overview/components/ |
| 192 | +[3]: https://kubernetes.io/docs/tasks/tools/ |
| 193 | +[4]: https://helm.sh/ |
| 194 | +[5]: https://kubernetes.io/docs/concepts/extend-kubernetes/api-extension/custom-resources/#customresourcedefinitions |
| 195 | +[6]: https://kubernetes.io/docs/concepts/extend-kubernetes/api-extension/custom-resources/#custom-resources |
| 196 | +[7]: https://kubernetes.io/docs/reference/access-authn-authz/extensible-admission-controllers/ |
| 197 | +[8]: https://github.com/nuodb/nuodb-client/releases |
| 198 | +[9]: https://curl.se/ |
0 commit comments