The Data API Builder is currently on Public Preview and is enabling businesses to quickly expose Data through APIs, to be consumed by Modern Apps. When it comes to how to host it, you can either leverage Static Web Apps to bind UI and API together, or you can get it running as API in containers.
Because I have been exploring the tool I decided to run it on Kubernetes for development purposes.
The Docker image
Microsoft has made it available on https://mcr.microsoft.com/product/azure-databases/data-api-builder/about.
Note that you can run it locally with docker run:
docker run -it -v <host-directory>:/App/<container-directory> -p 5000:5000 mcr.microsoft.com/azure-databases/data-api-builder:<tag> --ConfigFileName <configuration-file>
It requires the
ConfigFileName as a parameter, and this is what I would like to talk about it.
The Config file
This post intends to show how to host the Container on Kubernetes, but we need the Configuration File!
This config file is created when the DAB CLI is used, by running a few commands. Data API Builder can be run against Azure Databases like Azure Database/SQL Server, PostgreSQL, MySQL, CosmosDB.
In my case I am running it against a SQL database:
dab init --database-type mssql --connection-string "Server=localhost;Database=Library;"
This will generate the file
dab-config.json in the directory where you run the command. On Kubernetes, we can mount a volume and use a secret for it.
Using Kubernetes Secret
Hosting the config file as a secret works like a charm, if you notice, there is a connection string on the file. Having it as a secret prevents us from exposing any sensitive information.
It is simple to setup, run the kubectl command:
kubectl create secret generic dab-config --from-file=dab-config.json -n demo
With that, we have the file as a secret on namespace
Now we just need to launch our deployment.
Running a deployment
We need to create a YAML file to do that for us. This will have a Deployment to initialize our replicas by using the container image with the secret that it was just created.
- name: data-api-builder
- containerPort: 5000
- name: config-volume
- name: config-volume
- name: http
NOTE: A volume mount was created with the mountPath:
dab-config.json. If that is not mapped, the file is not attached to the running container, and if you don't specify the subPath, the
/App/dab-config.jsonis created as a folder! So don't forget to specify the subPath to attach the secret as a file.
Run the command:
kubectl apply -f deployment-dab.yaml
Check the number of replicas! You should have 3 pods:
If you reach the public ip address you should see "Healthy" on browser. This means that the Data API is running!
From here there are lots of possibilities. The Data API Builder is a great tool, I hope to write more posts about it soon.
Learn more about the Data API Builder.