Merk
Tilgang til denne siden krever autorisasjon. Du kan prøve å logge på eller endre kataloger.
Tilgang til denne siden krever autorisasjon. Du kan prøve å endre kataloger.
This guide shows you how to deploy Data API builder (DAB) to Azure Kubernetes Service (AKS) using a custom container image pushed to Azure Container Registry. AKS provides managed Kubernetes with built-in scaling, health probes, and secret management.
Prerequisites
- An Azure account with an active subscription. Create an account for free.
- Azure CLI installed
- kubectl installed
- Docker installed
- Data API builder CLI. Install the CLI
- An existing AKS cluster. Create an AKS cluster
- An existing supported database reachable from AKS
Build the configuration file
Create a local directory for your configuration files.
Initialize a base configuration file using
dab init. Use the@env()function for the connection string so the secret is injected at runtime, not baked into the image.dab init \ --database-type mssql \ --connection-string "@env('DATABASE_CONNECTION_STRING')"Add at least one entity using
dab add. Repeat for each table or view you want to expose.dab add Books \ --source dbo.Books \ --permissions "anonymous:read"Review
dab-config.jsonbefore continuing.
Build and push a custom container image
Build an image that includes dab-config.json at /App/dab-config.json.
Create an Azure Container Registry if you don't already have one.
az acr create \ --resource-group <resource-group> \ --name <registry-name> \ --sku Basic \ --admin-enabled trueCreate a
Dockerfilein the same directory asdab-config.json.FROM mcr.microsoft.com/azure-databases/data-api-builder:latest COPY dab-config.json /App/dab-config.jsonBuild and push the image using ACR Tasks.
az acr build \ --registry <registry-name> \ --image dab:latest \ .Note the full image reference:
<registry-name>.azurecr.io/dab:latest.
Connect AKS to ACR
Grant your AKS cluster pull access to the registry.
az aks update \
--name <cluster-name> \
--resource-group <resource-group> \
--attach-acr <registry-name>
Store the connection string as a Kubernetes secret
Store the database connection string as a Kubernetes secret so it's never in the manifest file.
kubectl create secret generic dab-secrets \
--from-literal=DATABASE_CONNECTION_STRING="<your-connection-string>"
Warning
Never place connection strings directly in Kubernetes manifest files or container images. Use secrets or Azure Key Vault.
Create the Kubernetes manifest
Create a file named dab-deployment.yaml with the following content. Replace <registry-name> with your ACR name.
apiVersion: apps/v1
kind: Deployment
metadata:
name: dab
labels:
app: dab
spec:
replicas: 2
selector:
matchLabels:
app: dab
template:
metadata:
labels:
app: dab
spec:
containers:
- name: dab
image: <registry-name>.azurecr.io/dab:latest
ports:
- containerPort: 5000
env:
- name: DATABASE_CONNECTION_STRING
valueFrom:
secretKeyRef:
name: dab-secrets
key: DATABASE_CONNECTION_STRING
readinessProbe:
httpGet:
path: /health
port: 5000
initialDelaySeconds: 5
periodSeconds: 10
livenessProbe:
httpGet:
path: /health
port: 5000
initialDelaySeconds: 15
periodSeconds: 20
---
apiVersion: v1
kind: Service
metadata:
name: dab-service
spec:
selector:
app: dab
ports:
- protocol: TCP
port: 80
targetPort: 5000
type: LoadBalancer
Note
The readinessProbe and livenessProbe use the DAB /health endpoint. For more information, see Health checks.
Deploy to AKS
Get credentials for your cluster.
az aks get-credentials \ --resource-group <resource-group> \ --name <cluster-name>Apply the manifest.
kubectl apply -f dab-deployment.yamlWatch the rollout until pods are ready.
kubectl rollout status deployment/dabGet the external IP address assigned to the service.
kubectl get service dab-serviceThe
EXTERNAL-IPcolumn shows the public IP address. Allow a minute for the load balancer to provision.
Verify the deployment
Browse to
http://<external-ip>/health. A healthy response looks like:{ "status": "healthy", "version": "2.0.0", "app-name": "dab_oss_2.0.0" }Test an entity endpoint.
curl http://<external-ip>/api/Books
Scale the deployment
Change the replica count to scale horizontally.
kubectl scale deployment/dab --replicas=4
Or update spec.replicas in dab-deployment.yaml and reapply.
Clean up resources
Remove the deployment and service when no longer needed.
kubectl delete -f dab-deployment.yaml
kubectl delete secret dab-secrets
To delete the AKS cluster and registry, remove the resource group.
az group delete \
--name <resource-group> \
--yes --no-wait