Skip to content

Commit

Permalink
ref(examples/aks-spring-music): update per arm mixin
Browse files Browse the repository at this point in the history
Signed-off-by: Vaughn Dice <[email protected]>
  • Loading branch information
vdice committed Jan 23, 2020
1 parent df7a833 commit 7613f75
Show file tree
Hide file tree
Showing 4 changed files with 234 additions and 11 deletions.
13 changes: 9 additions & 4 deletions examples/aks-spring-music/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

This bundle demonstrates advanced use cases for Porter.

The bundle leverages a base Dockerfile (cnab/app/Dockerfile.base) to customize the resulting invocation image for the bundle by first installing the `azure cli` so that it can be used by the `exec` mixin. It then uses 4 mixins to access your Azure subscription and deploy the app. These values need to be updated in the porter.yaml.
The bundle leverages a base Dockerfile (Dockerfile.tmpl) to customize the resulting invocation image for the bundle by first installing the `azure cli` so that it can be used by the `exec` mixin. It then uses 4 mixins to access your Azure subscription and deploy the app. These values need to be updated in the porter.yaml.

* The `azure` mixin is used to create an AKS cluster using ARM. This requires subscription and tenant info.
* The `arm` mixin is used to create an AKS cluster using ARM. This requires subscription and tenant info.
* The `exec` mixin uses an Azure Service Principal to access via the CLI and install Helm's Tiller into an AKS cluster.
* The `kubernetes` mixin applys RBAC policies for Helm
* The `helm` mixin deploys the chart into the AKS cluster.
Expand Down Expand Up @@ -37,7 +37,7 @@ The bundle will use the service principal created above to interact with Azure.
```

* Update params for your deployment
* change the `invocationImage` Docker repo to match your Docker Hub account (line 4)
* change the `tag` Docker repo to match your Docker Hub account (line 5)
* Cosmos and AKS names must be unique. You can either edit the `porter.yaml` file default values (starting on line 90) or you can supply the with the porter CLI as shown below.

* Build the innvocation image
Expand All @@ -50,5 +50,10 @@ The bundle will use the service principal created above to interact with Azure.

```bash
export INSTALL_ID=314
porter install -c azure --param app-resource-group=spring-music-demo-$INSTALL_ID --param aks-resource-group=spring-music-demo-$INSTALL_ID --param aks-cluster-name=briar-aks-spring-$INSTALL_ID --param cosmosdb-service-name=briarspringmusic$INSTALL_ID --param azure-location=eastus
porter install -c azure \
--param app-resource-group=spring-music-demo-$INSTALL_ID \
--param aks-resource-group=spring-music-demo-$INSTALL_ID \
--param aks-cluster-name=briar-aks-spring-$INSTALL_ID \
--param cosmosdb-service-name=briarspringmusic$INSTALL_ID \
--param azure-location=eastus
```
113 changes: 113 additions & 0 deletions examples/aks-spring-music/arm/aks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"clusterName": {
"type": "string",
"defaultValue": "[concat('cnab-aks-', uniqueString(resourceGroup().id))]",
"metadata": {
"description": "AKS cluster name. Defaults to cnab-aks-xxxxxxxxxxxxx, where xxx... is a unique string based of the hash of your resource group id."
}
},
"location": {
"type": "string",
"defaultValue": "[resourceGroup().location]",
"metadata": {
"description": "The location of the Managed Cluster resource."
}
},
"dnsPrefix": {
"type": "string",
"defaultValue": "[concat('cnab-aks-', uniqueString(resourceGroup().id))]",
"metadata": {
"description": "Optional DNS prefix to use with hosted Kubernetes API server FQDN."
}
},
"osDiskSizeGB": {
"type": "int",
"defaultValue": 0,
"metadata": {
"description": "Disk size (in GB) to provision for each of the agent pool nodes. This value ranges from 0 to 1023. Specifying 0 will apply the default disk size for that agentVMSize."
},
"minValue": 0,
"maxValue": 1023
},
"agentCount": {
"type": "int",
"defaultValue": 3,
"metadata": {
"description": "The number of nodes for the cluster."
},
"minValue": 1,
"maxValue": 50
},
"agentVMSize": {
"type": "string",
"defaultValue": "Standard_DS2_v2",
"metadata": {
"description": "The size of the Virtual Machine."
}
},
"servicePrincipalClientId": {
"metadata": {
"description": "Client ID (used by cloudprovider)"
},
"type": "securestring"
},
"servicePrincipalClientSecret": {
"metadata": {
"description": "The Service Principal Client Secret."
},
"type": "securestring"
},
"osType": {
"type": "string",
"defaultValue": "Linux",
"allowedValues": [
"Linux"
],
"metadata": {
"description": "The type of operating system."
}
},
"kubernetesVersion": {
"type": "string",
"defaultValue": "1.15.7",
"metadata": {
"description": "The version of Kubernetes."
}
}
},
"resources": [
{
"apiVersion": "2018-03-31",
"type": "Microsoft.ContainerService/managedClusters",
"location": "[parameters('location')]",
"name": "[parameters('clusterName')]",
"properties": {
"kubernetesVersion": "[parameters('kubernetesVersion')]",
"dnsPrefix": "[parameters('dnsPrefix')]",
"agentPoolProfiles": [
{
"name": "agentpool",
"osDiskSizeGB": "[parameters('osDiskSizeGB')]",
"count": "[parameters('agentCount')]",
"vmSize": "[parameters('agentVMSize')]",
"osType": "[parameters('osType')]",
"storageProfile": "ManagedDisks"
}
],
"servicePrincipalProfile": {
"clientId": "[parameters('servicePrincipalClientId')]",
"Secret": "[parameters('servicePrincipalClientSecret')]"
}
}
}
],
"outputs": {
"controlPlaneFQDN": {
"type": "string",
"value": "[reference(parameters('clusterName')).fqdn]"
}
}
}
94 changes: 94 additions & 0 deletions examples/aks-spring-music/arm/cosmosdb.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"name": {
"type": "string",
"defaultValue": "[concat('cnab-cosmos-', uniqueString(resourceGroup().id))]",
"metadata": {
"description": "Cosmos DB account name. Defaults to cnab-cosmos-xxxxxxxxxxxxx, where xxx... is a unique string based of the hash of your resource group id."
}
},
"location": {
"type": "string",
"defaultValue": "[resourceGroup().location]",
"metadata": {
"description": "Location for the Cosmos DB account. Defaults to the resource group location."
}
},
"apiVersion": {
"type": "string",
"defaultValue": "2016-03-31",
"metadata": {
"description": "API Version. Defaults to '2016-03-31'."
}
},
"kind": {
"type": "string",
"defaultValue": "MongoDB",
"metadata": {
"description": "The type/kind of API for the Cosmos Database. Defaults to MongoDB."
}
},
"mongoCapabilities": {
"type": "array",
"defaultValue": [
{
"name": "EnableAggregationPipeline"
},
{
"name": "MongoDBv3.4"
}
],
"metadata": {
"description": "MongoDB API capabilities that should be enabled by default."
}
},
"enableMongoCapabilities": {
"type": "array",
"defaultValue": "[if(equals(parameters('kind'), 'MongoDB'), parameters('mongoCapabilities'), '[]')]",
"metadata": {
"description": "Conditional to enable api specific capabilities if MongoDB is the API chosen."
}
}
},
"variables": {},
"resources": [
{
"apiVersion": "[parameters('apiVersion')]",
"kind": "[parameters('kind')]",
"type": "Microsoft.DocumentDB/databaseAccounts",
"name": "[parameters('name')]",
"location": "[parameters('location')]",
"properties": {
"databaseAccountOfferType": "Standard",
"locations": [
{
"id": "[concat(parameters('name'), '-', parameters('location'))]",
"failoverPriority": 0,
"locationName": "[parameters('location')]"
}
],
"enableMultipleWriteLocations": true,
"isVirtualNetworkFilterEnabled": false,
"virtualNetworkRules": [],
"dependsOn": [],
"capabilities": "[parameters('enableMongoCapabilities')]"
}
}
],
"outputs": {
"HOST": {
"type": "string",
"value": "[reference(parameters('name')).documentEndpoint]"
},
"primary_key": {
"type": "string",
"value": "[listKeys(resourceId('Microsoft.DocumentDb/databaseAccounts', parameters('name')), parameters('apiVersion')).primaryMasterKey]"
},
"connection_string": {
"type": "string",
"value": "[listConnectionStrings(resourceId('Microsoft.DocumentDb/databaseAccounts', parameters('name')), parameters('apiVersion')).connectionStrings[0].connectionString]"
}
}
}
25 changes: 18 additions & 7 deletions examples/aks-spring-music/porter.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@ tag: getporter/aks-spring-music:v0.1.0
mixins:
- exec
- helm
- azure
- arm
- kubernetes

install:
- azure:
- arm:
description: "Create AKS"
type: aks
type: arm
template: "arm/aks.json"
name: "{{ bundle.parameters.aks-cluster-name }}"
resourceGroup: "{{ bundle.parameters.aks-resource-group }}"
parameters:
Expand All @@ -35,6 +36,15 @@ install:
- "--tenant"
- "{{ bundle.credentials.TENANT_ID}}"

- exec:
description: "Azure CLI set subscription"
command: "az"
arguments:
- "account"
- "set"
- "-s"
- "{{ bundle.credentials.SUBSCRIPTION_ID}}"

- exec:
description: "Azure CLI AKS get-credentials"
command: "az"
Expand All @@ -61,9 +71,10 @@ install:
- "tiller"
- "--upgrade"

- azure:
- arm:
description: "Create Azure Cosmos DB"
type: cosmosdb
type: arm
template: "arm/cosmosdb.json"
name: aks-spring-music-cosmos
resourceGroup: "{{ bundle.parameters.app-resource-group }}"
parameters:
Expand All @@ -81,10 +92,10 @@ install:
- helm:
description: "Helm Install Spring Music Demo App"
name: aks-spring-music-helm
chart: /cnab/app/charts/aks-spring-music
chart: /cnab/app/charts/spring-music
replace: true
set:
deploy.cosmosConnectString: $COSMOSDB_CONNECTION_STRING
deploy.cosmosConnectString: "{{ bundle.outputs.COSMOSDB_CONNECTION_STRING }}"

uninstall:
- exec:
Expand Down

0 comments on commit 7613f75

Please sign in to comment.