From a84344c11f2069436850dd4eeeb2560d7aa605e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dag=20K=C3=B6nig?= Date: Fri, 3 Dec 2021 13:13:36 +0100 Subject: [PATCH 1/9] devops --- .vscode/settings.json | 3 ++ deployment/bicep/main.bicep | 37 +++++++++++++ deployment/bicep/modules/aks.bicep | 48 +++++++++++++++++ deployment/deploy.ps1 | 84 ++++++++++++++++++++++++++++++ 4 files changed, 172 insertions(+) create mode 100644 .vscode/settings.json create mode 100644 deployment/bicep/main.bicep create mode 100644 deployment/bicep/modules/aks.bicep create mode 100644 deployment/deploy.ps1 diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..681b0cd --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "workbench.colorTheme": "Tomorrow Night Blue" +} \ No newline at end of file diff --git a/deployment/bicep/main.bicep b/deployment/bicep/main.bicep new file mode 100644 index 0000000..fa9f2c4 --- /dev/null +++ b/deployment/bicep/main.bicep @@ -0,0 +1,37 @@ +// ------------------------------------------------------------ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License (MIT). See License.txt in the repo root for license information. +// ------------------------------------------------------------ +targetScope = 'subscription' + +@description('The common name for this application') +param applicationName string + +@description('Location of resources') +@allowed([ + 'westeurope' + 'northeurope' + 'westus' + 'swedencentral' +]) +param location string = 'westeurope' + +var applicationNameWithoutDashes = '${replace(applicationName,'-','')}' +var resourceGroupName = 'rg-${applicationNameWithoutDashes}' +var aksName = '${take('aks-${applicationNameWithoutDashes}',20)}' + +resource rg 'Microsoft.Resources/resourceGroups@2020-10-01' = { + name: resourceGroupName + location: location +} + +module aks 'modules/aks.bicep' = { + name: 'aksDeployment' + scope: resourceGroup(rg.name) + params: { + aksName: aksName + } +} + +output aksName string = aks.outputs.aksName +output resourceGroupName string = resourceGroupName diff --git a/deployment/bicep/modules/aks.bicep b/deployment/bicep/modules/aks.bicep new file mode 100644 index 0000000..e6edc1f --- /dev/null +++ b/deployment/bicep/modules/aks.bicep @@ -0,0 +1,48 @@ +// ------------------------------------------------------------ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License (MIT). See License.txt in the repo root for license information. +// ------------------------------------------------------------ +@maxLength(20) +@description('AKS Name') +param aksName string + +// optional params +@minValue(0) +@maxValue(1023) +param osDiskSizeGB int = 0 + +@minValue(1) +@maxValue(50) +param agentCount int = 1 + +param agentVMSize string = 'Standard_DS2_v2' + +resource aks 'Microsoft.ContainerService/managedClusters@2020-09-01' = { + name: aksName + location: resourceGroup().location + identity: { + type: 'SystemAssigned' + } + properties: { + enableRBAC: true + dnsPrefix: uniqueString(aksName) + agentPoolProfiles: [ + { + name: 'agentpool' + enableAutoScaling: false + osDiskSizeGB: osDiskSizeGB + count: agentCount + vmSize: agentVMSize + osType: 'Linux' + mode: 'System' + } + ] + servicePrincipalProfile: { + clientId: 'msi' + } + } +} + +output controlPlaneFQDN string = aks.properties.fqdn +output aksName string = aks.name +output clusterPrincipalID string = aks.properties.identityProfile.kubeletidentity.objectId diff --git a/deployment/deploy.ps1 b/deployment/deploy.ps1 new file mode 100644 index 0000000..717098c --- /dev/null +++ b/deployment/deploy.ps1 @@ -0,0 +1,84 @@ +# ------------------------------------------------------------ +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License (MIT). See License.txt in the repo root for license information. +# ------------------------------------------------------------ + +Param( + [string] + [Parameter(mandatory=$true)] + $ApplicationName, + [string] + $Location = 'westeurope', + [switch] + $DeleteResourceGroup +) + +Function Write-Title ($text) { + $width = (Get-Host).UI.RawUI.WindowSize.Width + $title = "" + if($text.length -ne 0) + { + $title = "=[ " + $text + " ]=" + } + + Write-Host $title.PadRight($width, "=") -ForegroundColor green +} + +$deploymentId = Get-Random + +Write-Title("Start Deploying") +$startTime = Get-Date + +# ----- Deploy Bicep +Write-Title("Deploy Bicep files") +$r = (az deployment sub create --location $Location ` + --template-file .\bicep\main.bicep --parameters applicationName=$ApplicationName ` + --name "dep-$deploymentId" -o json) | ConvertFrom-Json + +$aksName = $r.properties.outputs.aksName.value +$resourceGroupName = $r.properties.outputs.resourceGroupName.value + +# ----- Get Cluster Credentials +Write-Title("Get AKS Credentials") +az aks get-credentials --admin --name $aksName --resource-group $resourceGroupName --overwrite-existing + +# ----- Enable Arc +Write-Title("Enable ARC") +az extension add --name connectedk8s +az provider register --namespace Microsoft.Kubernetes --wait +az provider register --namespace Microsoft.KubernetesConfiguration --wait +az provider register --namespace Microsoft.ExtendedLocation --wait + +# ----- Setup GitOps +Write-Title("Setup Gitops") +$gitUrl = (git config remote.origin.url) +az extension add --name k8s-configuration +az connectedk8s connect --name $aksName --resource-group $resourceGroupName +az k8s-configuration flux create -g $resourceGroupName ` + -c $aksName -t connectedClusters ` + -n edge-framework-ci-config --namespace edge-framework-ci-ns --scope cluster ` + -u $gitUrl --branch main ` + --kustomization name=flux-kustomization prune=true path=/deployment/flux + +# ----- Dapr +Write-Title("Install Dapr") +helm repo add dapr https://dapr.github.io/helm-charts/ +helm repo update +helm upgrade --install dapr dapr/dapr ` + --version=1.5 ` + --namespace dapr-system ` + --create-namespace ` + --wait + +# ----- Clean up +if($DeleteResourceGroup) +{ + Write-Title("Delete Resources") + if(Remove-AzResourceGroup -Name $resourceGroupName -Force) + { + Write-Host "All resources deleted" -ForegroundColor Yellow + } +} + +$runningTime = New-TimeSpan -Start $startTime +Write-Host "Running time:" $runningTime.ToString() -ForegroundColor Yellow \ No newline at end of file From 787a14d55353f651e30af4d8aa83c37b783edb9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dag=20K=C3=B6nig?= Date: Tue, 7 Dec 2021 11:19:58 +0100 Subject: [PATCH 2/9] containers built and pushed to private acr --- deployment/bicep/main.bicep | 15 ++++++++ deployment/bicep/modules/aks.bicep | 4 +- deployment/bicep/modules/arc.bicep | 38 +++++++++++++++++++ .../{deploy.ps1 => deploy-aks-dapr.ps1} | 29 +++++--------- 4 files changed, 65 insertions(+), 21 deletions(-) create mode 100644 deployment/bicep/modules/arc.bicep rename deployment/{deploy.ps1 => deploy-aks-dapr.ps1} (70%) diff --git a/deployment/bicep/main.bicep b/deployment/bicep/main.bicep index fa9f2c4..29d2ed9 100644 --- a/deployment/bicep/main.bicep +++ b/deployment/bicep/main.bicep @@ -19,6 +19,7 @@ param location string = 'westeurope' var applicationNameWithoutDashes = '${replace(applicationName,'-','')}' var resourceGroupName = 'rg-${applicationNameWithoutDashes}' var aksName = '${take('aks-${applicationNameWithoutDashes}',20)}' +var acrName = 'acr${applicationNameWithoutDashes}' resource rg 'Microsoft.Resources/resourceGroups@2020-10-01' = { name: resourceGroupName @@ -33,5 +34,19 @@ module aks 'modules/aks.bicep' = { } } +module acr 'modules/arc.bicep' = { + scope: resourceGroup(rg.name) + name: 'acrDeployment' + params: { + acrName: acrName + aksPrincipalId: aks.outputs.clusterPrincipalID + } + + dependsOn: [ + aks + ] +} + +output acrName string = acrName output aksName string = aks.outputs.aksName output resourceGroupName string = resourceGroupName diff --git a/deployment/bicep/modules/aks.bicep b/deployment/bicep/modules/aks.bicep index e6edc1f..c5311a1 100644 --- a/deployment/bicep/modules/aks.bicep +++ b/deployment/bicep/modules/aks.bicep @@ -13,9 +13,9 @@ param osDiskSizeGB int = 0 @minValue(1) @maxValue(50) -param agentCount int = 1 +param agentCount int = 3 -param agentVMSize string = 'Standard_DS2_v2' +param agentVMSize string = 'Standard_B4ms' resource aks 'Microsoft.ContainerService/managedClusters@2020-09-01' = { name: aksName diff --git a/deployment/bicep/modules/arc.bicep b/deployment/bicep/modules/arc.bicep new file mode 100644 index 0000000..c250721 --- /dev/null +++ b/deployment/bicep/modules/arc.bicep @@ -0,0 +1,38 @@ +// ------------------------------------------------------------ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License (MIT). See License.txt in the repo root for license information. +// ------------------------------------------------------------ +@description('ACR Name') +@maxLength(20) +param acrName string + +@description('The principal ID of the AKS cluster') +param aksPrincipalId string + +@allowed([ + 'b24988ac-6180-42a0-ab88-20f7382dd24c' // Contributor + 'acdd72a7-3385-48ef-bd42-f606fba81ae7' // Reader +]) +param roleAcrPull string = 'b24988ac-6180-42a0-ab88-20f7382dd24c' + +resource acr 'Microsoft.ContainerRegistry/registries@2021-06-01-preview' = { + name: acrName + location: resourceGroup().location + sku: { + name: 'Standard' + } + properties: { + adminUserEnabled: true + } +} + +resource assignAcrPullToAks 'Microsoft.Authorization/roleAssignments@2020-04-01-preview' = { + name: guid(resourceGroup().id, acrName, aksPrincipalId, 'AssignAcrPullToAks') + scope: acr + properties: { + description: 'Assign AcrPull role to AKS' + principalId: aksPrincipalId + principalType: 'ServicePrincipal' + roleDefinitionId: '/subscriptions/${subscription().subscriptionId}/providers/Microsoft.Authorization/roleDefinitions/${roleAcrPull}' + } +} diff --git a/deployment/deploy.ps1 b/deployment/deploy-aks-dapr.ps1 similarity index 70% rename from deployment/deploy.ps1 rename to deployment/deploy-aks-dapr.ps1 index 717098c..db11e7e 100644 --- a/deployment/deploy.ps1 +++ b/deployment/deploy-aks-dapr.ps1 @@ -35,32 +35,23 @@ $r = (az deployment sub create --location $Location ` --template-file .\bicep\main.bicep --parameters applicationName=$ApplicationName ` --name "dep-$deploymentId" -o json) | ConvertFrom-Json +$acrName = $r.properties.outputs.acrName.value $aksName = $r.properties.outputs.aksName.value $resourceGroupName = $r.properties.outputs.resourceGroupName.value +# ----- Build and Push Containers +Write-Title("Build and Push Containers") +$deplymentDir = Get-Location +Set-Location -Path ../iotedge/Distributed.Azure.IoT.Edge +az acr build --image iothubintegrationmodule:$deploymentId --registry $acrName --file Distributed.Azure.IoT.Edge.IoTHubIntegrationModule/Dockerfile . +az acr build --image simulatedtemperaturesensormodule:$deploymentId --registry $acrName --file Distributed.Azure.IoT.Edge.SimulatedTemperatureSensorModule/Dockerfile . +Set-Location -Path $deplymentDir + # ----- Get Cluster Credentials Write-Title("Get AKS Credentials") az aks get-credentials --admin --name $aksName --resource-group $resourceGroupName --overwrite-existing -# ----- Enable Arc -Write-Title("Enable ARC") -az extension add --name connectedk8s -az provider register --namespace Microsoft.Kubernetes --wait -az provider register --namespace Microsoft.KubernetesConfiguration --wait -az provider register --namespace Microsoft.ExtendedLocation --wait - -# ----- Setup GitOps -Write-Title("Setup Gitops") -$gitUrl = (git config remote.origin.url) -az extension add --name k8s-configuration -az connectedk8s connect --name $aksName --resource-group $resourceGroupName -az k8s-configuration flux create -g $resourceGroupName ` - -c $aksName -t connectedClusters ` - -n edge-framework-ci-config --namespace edge-framework-ci-ns --scope cluster ` - -u $gitUrl --branch main ` - --kustomization name=flux-kustomization prune=true path=/deployment/flux - -# ----- Dapr +#----- Dapr Write-Title("Install Dapr") helm repo add dapr https://dapr.github.io/helm-charts/ helm repo update From 4acd9d08ca34881d0bf61f39868e7e22861a0b65 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dag=20K=C3=B6nig?= Date: Tue, 7 Dec 2021 15:29:57 +0100 Subject: [PATCH 3/9] fix helm chart --- deployment/deploy-aks-dapr.ps1 | 20 ++++++++++++++++--- .../templates/dapr/event-hub-pub-sub.yaml | 4 +++- .../system-modules/data-gateway-module.yaml | 3 ++- .../simulated-temperature-sensor-module.yaml | 5 +++-- .../helm/iot-edge-accelerator/values.yaml | 6 +++++- 5 files changed, 30 insertions(+), 8 deletions(-) diff --git a/deployment/deploy-aks-dapr.ps1 b/deployment/deploy-aks-dapr.ps1 index db11e7e..640b286 100644 --- a/deployment/deploy-aks-dapr.ps1 +++ b/deployment/deploy-aks-dapr.ps1 @@ -42,9 +42,9 @@ $resourceGroupName = $r.properties.outputs.resourceGroupName.value # ----- Build and Push Containers Write-Title("Build and Push Containers") $deplymentDir = Get-Location -Set-Location -Path ../iotedge/Distributed.Azure.IoT.Edge -az acr build --image iothubintegrationmodule:$deploymentId --registry $acrName --file Distributed.Azure.IoT.Edge.IoTHubIntegrationModule/Dockerfile . -az acr build --image simulatedtemperaturesensormodule:$deploymentId --registry $acrName --file Distributed.Azure.IoT.Edge.SimulatedTemperatureSensorModule/Dockerfile . +Set-Location -Path ../iotedge/Distributed.IoT.Edge +az acr build --image datagatewaymodule:$deploymentId --registry $acrName --file Distributed.IoT.Edge.DataGatewayModule/Dockerfile . +az acr build --image simulatedtemperaturesensormodule:$deploymentId --registry $acrName --file Distributed.IoT.Edge.SimulatedTemperatureSensorModule/Dockerfile . Set-Location -Path $deplymentDir # ----- Get Cluster Credentials @@ -61,6 +61,20 @@ helm upgrade --install dapr dapr/dapr ` --create-namespace ` --wait +#----- Redis +Write-Title("Install Redis") +helm repo add bitnami https://charts.bitnami.com/bitnami +helm repo update +helm install redis bitnami/redis --wait + +# ----- Run Helm +Write-Title("Install Pod/Containers with Helm in Cluster") +$datagatewaymoduleimage = $acrName + ".azurecr.io/datagatewaymodule:" + $deploymentId +$simtempimage = $acrName + ".azurecr.io/simulatedtemperaturesensormodule:" + $deploymentId +helm install iot-edge-accelerator ./helm/iot-edge-accelerator ` + --set-string images.datagatewaymodule="$datagatewaymoduleimage" ` + --set-string images.simulatedtemperaturesensormodule="$simtempimage" + # ----- Clean up if($DeleteResourceGroup) { diff --git a/deployment/helm/iot-edge-accelerator/templates/dapr/event-hub-pub-sub.yaml b/deployment/helm/iot-edge-accelerator/templates/dapr/event-hub-pub-sub.yaml index 984c009..0449e99 100644 --- a/deployment/helm/iot-edge-accelerator/templates/dapr/event-hub-pub-sub.yaml +++ b/deployment/helm/iot-edge-accelerator/templates/dapr/event-hub-pub-sub.yaml @@ -1,3 +1,4 @@ +{{ if ne .Values.dataGatewayModule.eventHubConnectionString "replace_with_real_key_at_deploy_time" }} apiVersion: dapr.io/v1alpha1 kind: Component metadata: @@ -26,4 +27,5 @@ spec: - name: allowedTopics value: "telemetry" scopes: -- data-gateway-module \ No newline at end of file +- data-gateway-module +{{ end }} \ No newline at end of file diff --git a/deployment/helm/iot-edge-accelerator/templates/system-modules/data-gateway-module.yaml b/deployment/helm/iot-edge-accelerator/templates/system-modules/data-gateway-module.yaml index 6479a1f..d759c8d 100644 --- a/deployment/helm/iot-edge-accelerator/templates/system-modules/data-gateway-module.yaml +++ b/deployment/helm/iot-edge-accelerator/templates/system-modules/data-gateway-module.yaml @@ -21,6 +21,7 @@ spec: spec: containers: - name: data-gateway-module - image: suneetnangia/distributed-az-iot-edge-datagatewaymodule:main-8db42cf6ce413a9676a24fb1f3aba083de1e6fe7 + image: {{ .Values.images.datagatewaymodule }} + #args: ["--recieverPubSubName", "iot-messages", "--recieverPubSubTopicName", "telemetry"] imagePullPolicy: Always restartPolicy: Always diff --git a/deployment/helm/iot-edge-accelerator/templates/system-modules/simulated-temperature-sensor-module.yaml b/deployment/helm/iot-edge-accelerator/templates/system-modules/simulated-temperature-sensor-module.yaml index 35af84e..b0eebf5 100644 --- a/deployment/helm/iot-edge-accelerator/templates/system-modules/simulated-temperature-sensor-module.yaml +++ b/deployment/helm/iot-edge-accelerator/templates/system-modules/simulated-temperature-sensor-module.yaml @@ -22,7 +22,8 @@ spec: spec: containers: - name: simulated-temperature-sensor-module - image: suneetnangia/distributed-az-iot-edge-simulatedtemperaturesensormodule:main-8db42cf6ce413a9676a24fb1f3aba083de1e6fe7 + image: "{{ .Values.images.simulatedtemperaturesensormodule }}" imagePullPolicy: Always - args: ["--feedIntervalInMilliseconds", "{{ .Values.simulatedTemperatureSensorFeedIntervalInMilliseconds }}"] + #args: ["--feedIntervalInMilliseconds", "{{ .Values.simulatedTemperatureSensorFeedIntervalInMilliseconds }}", "--senderPubSubName", "iot-messages", "--senderPubSubTopicName", "telemetry"] + args: ["--feedIntervalInMilliseconds", "{{ .Values.simulatedTemperatureSensorFeedIntervalInMilliseconds }}"] restartPolicy: Always diff --git a/deployment/helm/iot-edge-accelerator/values.yaml b/deployment/helm/iot-edge-accelerator/values.yaml index b470e8d..6cecb4a 100644 --- a/deployment/helm/iot-edge-accelerator/values.yaml +++ b/deployment/helm/iot-edge-accelerator/values.yaml @@ -5,4 +5,8 @@ simulatedTemperatureSensorFeedIntervalInMilliseconds: 1000 dataGatewayModule: eventHubConnectionString: "replace_with_real_key_at_deploy_time" storageAccountName: "replace_with_storage_account_name_at_deploy_time" - storageAccountKey: "replace_with_storage_account_key_at_deploy_time" \ No newline at end of file + storageAccountKey: "replace_with_storage_account_key_at_deploy_time" + +images: + datagatewaymodule: + simulatedtemperaturesensormodule: test \ No newline at end of file From 964d66b4046d3cd46d5deb1b73c95987a7caf71e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dag=20K=C3=B6nig?= Date: Tue, 7 Dec 2021 15:33:26 +0100 Subject: [PATCH 4/9] update vs code settings not ss --- .gitignore | 1 - 1 file changed, 1 deletion(-) diff --git a/.gitignore b/.gitignore index 5556efb..cf0403e 100644 --- a/.gitignore +++ b/.gitignore @@ -367,7 +367,6 @@ FodyWeavers.xsd # VS Code files for those working on multiple tools .vscode/* -!.vscode/settings.json !.vscode/tasks.json !.vscode/launch.json !.vscode/extensions.json From 9786c65d0083a7190591d33157333f507ccd9f3e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dag=20K=C3=B6nig?= Date: Tue, 7 Dec 2021 15:34:02 +0100 Subject: [PATCH 5/9] Delete settings.json --- .vscode/settings.json | 3 --- 1 file changed, 3 deletions(-) delete mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json deleted file mode 100644 index 681b0cd..0000000 --- a/.vscode/settings.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "workbench.colorTheme": "Tomorrow Night Blue" -} \ No newline at end of file From a741d5d0c4ab6b8769db35aa132aabba8d1dd1de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dag=20K=C3=B6nig?= Date: Wed, 8 Dec 2021 09:04:36 +0100 Subject: [PATCH 6/9] add document --- deployment/deploy-aks-dapr.md | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 deployment/deploy-aks-dapr.md diff --git a/deployment/deploy-aks-dapr.md b/deployment/deploy-aks-dapr.md new file mode 100644 index 0000000..62d1ac6 --- /dev/null +++ b/deployment/deploy-aks-dapr.md @@ -0,0 +1,23 @@ +# Setup an developer environment + +## Introduction +This environment is used to setup a fast developer environment, which means that Acr and Flux is not included +in the environment. + +## How to execute it +Go to the `development` folder and run `deploy-aks-dapr.ps1 -ApplicationName ` + +## The main functions in the script +1. Deploy infrastructure with Bicep + * AKS + * ACR + +2. Use `az acr build` to build and push images to the ACR + +3. Download AKS credentials + +4. Install Dapr with Helm in AKS + +5. Install Redis with Helm in AKS + +6. Install our components with Helm in AKS From 7a9f4884f98698d0d757153346658706bcdbbe9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dag=20K=C3=B6nig?= Date: Wed, 8 Dec 2021 10:00:43 +0100 Subject: [PATCH 7/9] removed comments --- .../templates/system-modules/data-gateway-module.yaml | 1 - .../system-modules/simulated-temperature-sensor-module.yaml | 1 - deployment/helm/iot-edge-accelerator/values.yaml | 2 +- 3 files changed, 1 insertion(+), 3 deletions(-) diff --git a/deployment/helm/iot-edge-accelerator/templates/system-modules/data-gateway-module.yaml b/deployment/helm/iot-edge-accelerator/templates/system-modules/data-gateway-module.yaml index d759c8d..7b8c9b0 100644 --- a/deployment/helm/iot-edge-accelerator/templates/system-modules/data-gateway-module.yaml +++ b/deployment/helm/iot-edge-accelerator/templates/system-modules/data-gateway-module.yaml @@ -22,6 +22,5 @@ spec: containers: - name: data-gateway-module image: {{ .Values.images.datagatewaymodule }} - #args: ["--recieverPubSubName", "iot-messages", "--recieverPubSubTopicName", "telemetry"] imagePullPolicy: Always restartPolicy: Always diff --git a/deployment/helm/iot-edge-accelerator/templates/system-modules/simulated-temperature-sensor-module.yaml b/deployment/helm/iot-edge-accelerator/templates/system-modules/simulated-temperature-sensor-module.yaml index b0eebf5..c25da9f 100644 --- a/deployment/helm/iot-edge-accelerator/templates/system-modules/simulated-temperature-sensor-module.yaml +++ b/deployment/helm/iot-edge-accelerator/templates/system-modules/simulated-temperature-sensor-module.yaml @@ -24,6 +24,5 @@ spec: - name: simulated-temperature-sensor-module image: "{{ .Values.images.simulatedtemperaturesensormodule }}" imagePullPolicy: Always - #args: ["--feedIntervalInMilliseconds", "{{ .Values.simulatedTemperatureSensorFeedIntervalInMilliseconds }}", "--senderPubSubName", "iot-messages", "--senderPubSubTopicName", "telemetry"] args: ["--feedIntervalInMilliseconds", "{{ .Values.simulatedTemperatureSensorFeedIntervalInMilliseconds }}"] restartPolicy: Always diff --git a/deployment/helm/iot-edge-accelerator/values.yaml b/deployment/helm/iot-edge-accelerator/values.yaml index 6cecb4a..84af30b 100644 --- a/deployment/helm/iot-edge-accelerator/values.yaml +++ b/deployment/helm/iot-edge-accelerator/values.yaml @@ -9,4 +9,4 @@ dataGatewayModule: images: datagatewaymodule: - simulatedtemperaturesensormodule: test \ No newline at end of file + simulatedtemperaturesensormodule: \ No newline at end of file From 212e41e128670df66ab7ebf479a30691cce54712 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dag=20K=C3=B6nig?= Date: Wed, 8 Dec 2021 14:46:32 +0100 Subject: [PATCH 8/9] added eventhub + grpc to data gateway --- deployment/bicep/main.bicep | 21 ++++++++ deployment/bicep/modules/azurestorage.bicep | 16 +++++++ deployment/bicep/modules/eventhub.bicep | 48 +++++++++++++++++++ deployment/deploy-aks-dapr.ps1 | 8 +++- .../system-modules/data-gateway-module.yaml | 1 + 5 files changed, 93 insertions(+), 1 deletion(-) create mode 100644 deployment/bicep/modules/azurestorage.bicep create mode 100644 deployment/bicep/modules/eventhub.bicep diff --git a/deployment/bicep/main.bicep b/deployment/bicep/main.bicep index 29d2ed9..4094093 100644 --- a/deployment/bicep/main.bicep +++ b/deployment/bicep/main.bicep @@ -20,6 +20,8 @@ var applicationNameWithoutDashes = '${replace(applicationName,'-','')}' var resourceGroupName = 'rg-${applicationNameWithoutDashes}' var aksName = '${take('aks-${applicationNameWithoutDashes}',20)}' var acrName = 'acr${applicationNameWithoutDashes}' +var storageAccountName = 'st${take(applicationNameWithoutDashes,14)}' +var eventHubNameSpaceName = 'evh${take(applicationNameWithoutDashes,14)}' resource rg 'Microsoft.Resources/resourceGroups@2020-10-01' = { name: resourceGroupName @@ -47,6 +49,25 @@ module acr 'modules/arc.bicep' = { ] } +module storage 'modules/azurestorage.bicep' = { + scope: resourceGroup(rg.name) + name: 'storageDeployment' + params: { + storageAccountName: storageAccountName + } +} + +module eventhub 'modules/eventhub.bicep' = { + scope: resourceGroup(rg.name) + name: 'eventHubDeployment' + params: { + eventHubNameSpaceName: eventHubNameSpaceName + } +} + output acrName string = acrName output aksName string = aks.outputs.aksName output resourceGroupName string = resourceGroupName +output storageKey string = storage.outputs.storageKey +output storageName string = storage.outputs.storageName +output eventHubConnectionString string = eventhub.outputs.eventHubConnectionString diff --git a/deployment/bicep/modules/azurestorage.bicep b/deployment/bicep/modules/azurestorage.bicep new file mode 100644 index 0000000..6da0115 --- /dev/null +++ b/deployment/bicep/modules/azurestorage.bicep @@ -0,0 +1,16 @@ +param storageAccountName string + +resource storageAccount 'Microsoft.Storage/storageAccounts@2021-04-01' = { + name: storageAccountName + location: resourceGroup().location + sku: { + name: 'Standard_LRS' + } + kind: 'StorageV2' + properties: { + accessTier: 'Hot' + } +} + +output storageKey string = storageAccount.listKeys().keys[0].value +output storageName string = storageAccountName diff --git a/deployment/bicep/modules/eventhub.bicep b/deployment/bicep/modules/eventhub.bicep new file mode 100644 index 0000000..9916336 --- /dev/null +++ b/deployment/bicep/modules/eventhub.bicep @@ -0,0 +1,48 @@ +// ------------------------------------------------------------ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License (MIT). See License.txt in the repo root for license information. +// ------------------------------------------------------------ +@maxLength(20) +@description('AKS Name') +param eventHubNameSpaceName string + +resource eventHubNamespace 'Microsoft.EventHub/namespaces@2021-01-01-preview' = { + name: eventHubNameSpaceName + location: resourceGroup().location + sku: { + name: 'Standard' + tier: 'Standard' + capacity: 1 + } + properties: { + zoneRedundant: false + } +} + +var eventHubName = '${eventHubNameSpaceName}hub' +resource eventHubNamespaceName_eventHubName 'Microsoft.EventHub/namespaces/eventhubs@2021-01-01-preview' = { + parent: eventHubNamespace + name: eventHubName + properties: { + messageRetentionInDays: 7 + partitionCount: 1 + } +} + +resource eventHubNamespaceName_eventHubName_ListenSend 'Microsoft.EventHub/namespaces/eventhubs/authorizationRules@2021-01-01-preview' = { + parent: eventHubNamespaceName_eventHubName + name: 'iot-edge' + properties: { + rights: [ + 'Listen' + 'Send' + ] + } + dependsOn: [ + eventHubNamespace + ] +} +var eventHubConnectionString = listKeys(eventHubNamespaceName_eventHubName_ListenSend.id, eventHubNamespaceName_eventHubName_ListenSend.apiVersion).primaryConnectionString + +output eventHubConnectionString string = eventHubConnectionString +output eventHubName string = eventHubName diff --git a/deployment/deploy-aks-dapr.ps1 b/deployment/deploy-aks-dapr.ps1 index 640b286..2afe61e 100644 --- a/deployment/deploy-aks-dapr.ps1 +++ b/deployment/deploy-aks-dapr.ps1 @@ -38,6 +38,9 @@ $r = (az deployment sub create --location $Location ` $acrName = $r.properties.outputs.acrName.value $aksName = $r.properties.outputs.aksName.value $resourceGroupName = $r.properties.outputs.resourceGroupName.value +$storageKey = $r.properties.outputs.storageKey.Value +$storageName = $r.properties.outputs.storageName.Value +$eventHubConnectionString = $r.properties.outputs.eventHubConnectionString.value # ----- Build and Push Containers Write-Title("Build and Push Containers") @@ -73,7 +76,10 @@ $datagatewaymoduleimage = $acrName + ".azurecr.io/datagatewaymodule:" + $deploym $simtempimage = $acrName + ".azurecr.io/simulatedtemperaturesensormodule:" + $deploymentId helm install iot-edge-accelerator ./helm/iot-edge-accelerator ` --set-string images.datagatewaymodule="$datagatewaymoduleimage" ` - --set-string images.simulatedtemperaturesensormodule="$simtempimage" + --set-string images.simulatedtemperaturesensormodule="$simtempimage" ` + --set-string dataGatewayModule.eventHubConnectionString="$eventHubConnectionString" ` + --set-string dataGatewayModule.storageAccountName="$storageName" ` + --set-string dataGatewayModule.storageAccountKey="$storageKey" # ----- Clean up if($DeleteResourceGroup) diff --git a/deployment/helm/iot-edge-accelerator/templates/system-modules/data-gateway-module.yaml b/deployment/helm/iot-edge-accelerator/templates/system-modules/data-gateway-module.yaml index 7b8c9b0..ac67c15 100644 --- a/deployment/helm/iot-edge-accelerator/templates/system-modules/data-gateway-module.yaml +++ b/deployment/helm/iot-edge-accelerator/templates/system-modules/data-gateway-module.yaml @@ -18,6 +18,7 @@ spec: dapr.io/enabled: "true" dapr.io/app-id: "data-gateway-module" dapr.io/app-port: "80" + dapr.io/app-protocol: "grpc" spec: containers: - name: data-gateway-module From 7d93d784ea7e764eb6bb1ef4e336031f85cb2150 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dag=20K=C3=B6nig?= Date: Thu, 9 Dec 2021 11:43:09 +0100 Subject: [PATCH 9/9] build and update images in k8s --- deployment/build-and-deploy-images.ps1 | 55 ++++++++++++++++++++++++++ deployment/deploy-aks-dapr.ps1 | 2 + 2 files changed, 57 insertions(+) create mode 100644 deployment/build-and-deploy-images.ps1 diff --git a/deployment/build-and-deploy-images.ps1 b/deployment/build-and-deploy-images.ps1 new file mode 100644 index 0000000..ec1a2a9 --- /dev/null +++ b/deployment/build-and-deploy-images.ps1 @@ -0,0 +1,55 @@ +# ------------------------------------------------------------ +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License (MIT). See License.txt in the repo root for license information. +# ------------------------------------------------------------ + +Param( + [string] + $ResourceGroupName +) + +if(!$env:RESOURCEGROUPNAME -and !$ResourceGroupName) +{ + Write-Error "Environment variable RESOURCEGROUPNAME is not set and ResourceGroupName parameter is not set" + Exit +} +if(!$ResourceGroupName) +{ + $ResourceGroupName = $env:RESOURCEGROUPNAME +} + +Function Write-Title ($text) { + $width = (Get-Host).UI.RawUI.WindowSize.Width + $title = "" + if($text.length -ne 0) + { + $title = "=[ " + $text + " ]=" + } + + Write-Host $title.PadRight($width, "=") -ForegroundColor green +} + +$deploymentId = Get-Random +$startTime = Get-Date +$acrName = (az acr list -g $ResourceGroupName --query [].name -o tsv) + +# ----- Build and Push Containers +Write-Title("Build and Push Containers") +$deplymentDir = Get-Location +Set-Location -Path ../iotedge/Distributed.IoT.Edge +az acr build --image datagatewaymodule:$deploymentId --registry $acrName --file Distributed.IoT.Edge.DataGatewayModule/Dockerfile . +az acr build --image simulatedtemperaturesensormodule:$deploymentId --registry $acrName --file Distributed.IoT.Edge.SimulatedTemperatureSensorModule/Dockerfile . +Set-Location -Path $deplymentDir + +# ----- Run Helm +Write-Title("Upgrade Pod/Containers with Helm in Cluster") +$datagatewaymoduleimage = $acrName + ".azurecr.io/datagatewaymodule:" + $deploymentId +$simtempimage = $acrName + ".azurecr.io/simulatedtemperaturesensormodule:" + $deploymentId +helm upgrade iot-edge-accelerator ./helm/iot-edge-accelerator ` + --set-string images.datagatewaymodule="$datagatewaymoduleimage" ` + --set-string images.simulatedtemperaturesensormodule="$simtempimage" ` + +$runningTime = New-TimeSpan -Start $startTime + +Write-Host "Tag: " $deploymentId -ForegroundColor Green +Write-Host "Running time:" $runningTime.ToString() -ForegroundColor Yellow \ No newline at end of file diff --git a/deployment/deploy-aks-dapr.ps1 b/deployment/deploy-aks-dapr.ps1 index 2afe61e..bd339b3 100644 --- a/deployment/deploy-aks-dapr.ps1 +++ b/deployment/deploy-aks-dapr.ps1 @@ -91,5 +91,7 @@ if($DeleteResourceGroup) } } +$env:RESOURCEGROUPNAME=$resourceGroupName + $runningTime = New-TimeSpan -Start $startTime Write-Host "Running time:" $runningTime.ToString() -ForegroundColor Yellow \ No newline at end of file