Deploying to AKS with Dapr Extension
Table of contents
Setup
-
Install Helm
-
Login to azure:
az login
-
Create a resource group:
-
Create Resource Group (if not already created):
az group create --name rg-dapr-workshop-java --location eastus
-
Set Resource Group as default:
az configure --defaults group=rg-dapr-workshop-java
-
-
Azure Container Registry is a private registry for hosting container images. Using the Azure Container Registry, you can store Docker images for all types of container deployments. This registry needs to be gloablly unique. Use the following command to generate a unique name:
-
Linux/Unix shell:
UNIQUE_IDENTIFIER=$(LC_ALL=C tr -dc a-z0-9 </dev/urandom | head -c 5) CONTAINER_REGISTRY="crdaprworkshopjava$UNIQUE_IDENTIFIER" echo $CONTAINER_REGISTRY
-
Powershell:
$ACCEPTED_CHAR = [Char[]]'abcdefghijklmnopqrstuvwxyz0123456789' $UNIQUE_IDENTIFIER = (Get-Random -Count 5 -InputObject $ACCEPTED_CHAR) -join '' $CONTAINER_REGISTRY = "crdaprworkshopjava$UNIQUE_IDENTIFIER" $CONTAINER_REGISTRY
-
-
Create an Azure Container Registry (ACR) resource:
az acr create --name "$CONTAINER_REGISTRY" --sku Basic
-
Create an AKS cluster with the ACR attached:
az aks create \ --name aks-dapr-workshop-java \ --generate-ssh-keys \ --attach-acr "$CONTAINER_REGISTRY" \ --enable-managed-identity
-
Update AKS with Dapr extension:
az k8s-extension create --cluster-type managedClusters \ --cluster-name aks-dapr-workshop-java \ --name myDaprExtension \ --extension-type Microsoft.Dapr
-
Download AKS cluster kubecofig file, and install kubectl CLI:
az aks install-cli az aks get-credentials -n aks-dapr-workshop-java -g rg-dapr-workshop-java
Step 1 - Deploy kafka to AKS, and configure Dapr
-
Deploy kafka to kubernetes using helm chart:
helm repo add bitnami https://charts.bitnami.com/bitnami helm install my-release bitnami/kafka
-
Configure Dapr to use kafka for pubsub:
cd deploy kubectl apply -f kafka-pubsub.yaml
Step 2 - Generate Docker images for applications, and push them to ACR
-
Login to your ACR repository:
az acr login --name "$CONTAINER_REGISTRY"
-
In the root folder of TravelRegistrationService microservice, run the following command:
mvn spring-boot:build-image docker tag vehicle-registration-service:1.0-SNAPSHOT "$CONTAINER_REGISTRY".azurecr.io/vehicle-registration-service:latest docker push "$CONTAINER_REGISTRY".azurecr.io/vehicle-registration-service:latest
-
In the root folder of FineCollectionService microservice, run the following command:
mvn spring-boot:build-image docker tag fine-collection-service:1.0-SNAPSHOT "$CONTAINER_REGISTRY".azurecr.io/fine-collection-service:latest docker push "$CONTAINER_REGISTRY".azurecr.io/fine-collection-service:latest
-
In the root folder of TrafficControlService microservice, run the following command:
mvn spring-boot:build-image docker tag traffic-control-service:1.0-SNAPSHOT "$CONTAINER_REGISTRY".azurecr.io/traffic-control-service:latest docker push "$CONTAINER_REGISTRY".azurecr.io/traffic-control-service:latest
-
In the root folder of the simulation (
Simulation
), run the following command:mvn spring-boot:build-image docker tag simulation:1.0-SNAPSHOT "$CONTAINER_REGISTRY".azurecr.io/simulation:latest docker push "$CONTAINER_REGISTRY".azurecr.io/simulation:latest
Step 3 - Deploy Kubernetes manifest files for applications to AKS
-
In the
deploy
folder, update all<service-name>-deployment.yaml
files to use the correct container registry: replace<REPLACE_WITH_CONTAINER_REGISTRY_NAME>
with the name of the container registry ($CONTAINER_REGISTRY
). -
From the root folder of the repo, run the following command:
kubectl apply -k deploy
Please note below the
kubectl apply
is with -k option, which is applyingkustomize.yaml
file in thedeploy
folder.
Step 4 - Test the applications running in AKS
-
Run the following command to identify the name of each microservice pod:
kubectl get pods
-
Look at the log file of each application pod to see the same output as seen when running on your laptop. For example:
kubectl logs trafficcontrolservice-7d8f48b778-rx8l8 -c traffic-control-service
-
Delete all application deployments:
kubectl delete -k deploy
Next Steps
Well done, you have successfully completed the workshop!
- You can follow the Optional execices for Azure Kubernetes Service (AKS) to learn more about observability and GitOps:
- You can read the additional topics:
- You can continue the workshop with the bonus assignments to learn more about other Dapr building blocks:
Cleanup
When the workshop is done, please follow the cleanup instructions to delete the resources created in this workshop.
< Dapr Sidecar in k8’s (Optional) Observability >