|
| 1 | +--- |
| 2 | +title: Create a Service Fabric cluster using Bicep |
| 3 | +description: In this quickstart, you will create an Azure Service Fabric test cluster using Bicep. |
| 4 | +author: schaffererin |
| 5 | +ms.author: v-eschaffer |
| 6 | +ms.date: 06/22/2022 |
| 7 | +ms.topic: quickstart |
| 8 | +ms.service: service-fabric |
| 9 | +ms.custom: devx-track-azurepowershell, subject-armqs, mode-arm |
| 10 | +--- |
| 11 | + |
| 12 | +# Quickstart: Create a Service Fabric cluster using Bicep |
| 13 | + |
| 14 | +Azure Service Fabric is a distributed systems platform that makes it easy to package, deploy, and manage scalable and reliable microservices and containers. A Service Fabric *cluster* is a network-connected set of virtual machines into which your microservices are deployed and managed. This article describes how to deploy a Service Fabric test cluster in Azure using Bicep. |
| 15 | + |
| 16 | +[!INCLUDE [About Bicep](../../includes/resource-manager-quickstart-bicep-introduction.md)] |
| 17 | + |
| 18 | +This five-node Windows cluster is secured with a self-signed certificate and thus only intended for instructional purposes (rather than production workloads). We'll use Azure PowerShell to deploy the Bicep file. |
| 19 | + |
| 20 | +## Prerequisites |
| 21 | + |
| 22 | +If you don't have an Azure subscription, create a [free](https://azure.microsoft.com/free/) account before you begin. |
| 23 | + |
| 24 | +### Install Service Fabric SDK and PowerShell modules |
| 25 | + |
| 26 | +To complete this quickstart, you'll need to install the [Service Fabric SDK and PowerShell module](service-fabric-get-started.md). |
| 27 | + |
| 28 | +### Download the sample Bicep file and certificate helper script |
| 29 | + |
| 30 | +Clone or download the [Azure Resource Manager Quickstart Templates](https://github.com/Azure/azure-quickstart-templates) repo. Alternatively, copy down locally the following files we'll be using from the *service-fabric-secure-cluster-5-node-1-nodetype* folder: |
| 31 | + |
| 32 | +* [New-ServiceFabricClusterCertificate.ps1](https://raw.githubusercontent.com/Azure/azure-quickstart-templates/master/quickstarts/microsoft.servicefabric/service-fabric-secure-cluster-5-node-1-nodetype/scripts/New-ServiceFabricClusterCertificate.ps1) |
| 33 | +* [main.bicep](https://raw.githubusercontent.com/Azure/azure-quickstart-templates/master/quickstarts/microsoft.servicefabric/service-fabric-secure-cluster-5-node-1-nodetype/main.bicep) |
| 34 | +* [azuredeploy.parameters.json](https://raw.githubusercontent.com/Azure/azure-quickstart-templates/master/quickstarts/microsoft.servicefabric/service-fabric-secure-cluster-5-node-1-nodetype/azuredeploy.parameters.json) |
| 35 | + |
| 36 | +### Sign in to Azure |
| 37 | + |
| 38 | +Sign in to Azure and designate the subscription to use for creating your Service Fabric cluster. |
| 39 | + |
| 40 | +```powershell |
| 41 | +# Sign in to your Azure account |
| 42 | +Login-AzAccount -SubscriptionId "<subscription ID>" |
| 43 | +``` |
| 44 | + |
| 45 | +### Create a self-signed certificate stored in Key Vault |
| 46 | + |
| 47 | +Service Fabric uses X.509 certificates to [secure a cluster](./service-fabric-cluster-security.md) and provide application security features, and [Key Vault](../key-vault/general/overview.md) to manage those certificates. Successful cluster creation requires a cluster certificate to enable node-to-node communication. For the purpose of creating this quickstart test cluster, we'll create a self-signed certificate for cluster authentication. Production workloads require certificates created using a correctly configured Windows Server certificate service or one from an approved certificate authority (CA). |
| 48 | + |
| 49 | +```powershell |
| 50 | +# Designate unique (within cloudapp.azure.com) names for your resources |
| 51 | +$resourceGroupName = "SFQuickstartRG" |
| 52 | +$keyVaultName = "SFQuickstartKV" |
| 53 | +
|
| 54 | +# Create a new resource group for your Key Vault and Service Fabric cluster |
| 55 | +New-AzResourceGroup -Name $resourceGroupName -Location SouthCentralUS |
| 56 | +
|
| 57 | +# Create a Key Vault enabled for deployment |
| 58 | +New-AzKeyVault -VaultName $keyVaultName -ResourceGroupName $resourceGroupName -Location SouthCentralUS -EnabledForDeployment |
| 59 | +
|
| 60 | +# Generate a certificate and upload it to Key Vault |
| 61 | +.\scripts\New-ServiceFabricClusterCertificate.ps1 |
| 62 | +``` |
| 63 | + |
| 64 | +The script will prompt you for the following (be sure to modify *CertDNSName* and *KeyVaultName* from the example values below): |
| 65 | + |
| 66 | +* **Password:** Password!1 |
| 67 | +* **CertDNSName:** *sfquickstart*.southcentralus.cloudapp.azure.com |
| 68 | +* **KeyVaultName:** *SFQuickstartKV* |
| 69 | +* **KeyVaultSecretName:** clustercert |
| 70 | + |
| 71 | +Upon completion, the script will provide the parameter values needed for deployment. Be sure to store these in the following variables, as they will be needed for deployment: |
| 72 | + |
| 73 | +```powershell |
| 74 | +$sourceVaultId = "<Source Vault Resource Id>" |
| 75 | +$certUrlValue = "<Certificate URL>" |
| 76 | +$certThumbprint = "<Certificate Thumbprint>" |
| 77 | +``` |
| 78 | + |
| 79 | +## Review the Bicep file |
| 80 | + |
| 81 | +The Bicep file used in this quickstart is from [Azure Quickstart Templates](https://azure.microsoft.com/resources/templates/service-fabric-secure-cluster-5-node-1-nodetype/). |
| 82 | + |
| 83 | +:::code language="bicep" source="~/quickstart-templates/quickstarts/microsoft.servicefabric/service-fabric-secure-cluster-5-node-1-nodetype/main.bicep"::: |
| 84 | + |
| 85 | +Multiple Azure resources are defined in the Bicep file: |
| 86 | + |
| 87 | +* [Microsoft.Storage/storageAccounts](/azure/templates/microsoft.storage/storageaccounts) |
| 88 | +* [Microsoft.Network/virtualNetworks](/azure/templates/microsoft.network/virtualnetworks) |
| 89 | +* [Microsoft.Network/publicIPAddresses](/azure/templates/microsoft.network/publicipaddresses) |
| 90 | +* [Microsoft.Network/loadBalancers](/azure/templates/microsoft.network/loadbalancers) |
| 91 | +* [Microsoft.Compute/virtualMachineScaleSets](/azure/templates/microsoft.compute/virtualmachinescalesets) |
| 92 | +* [Microsoft.ServiceFabric/clusters](/azure/templates/microsoft.servicefabric/clusters) |
| 93 | + |
| 94 | +### Customize the parameters file |
| 95 | + |
| 96 | +Open *azuredeploy.parameters.json* and edit the parameter values so that: |
| 97 | + |
| 98 | +* **clusterName** matches the value you supplied for *CertDNSName* when creating your cluster certificate |
| 99 | +* **adminUserName** is some value other than the default *GEN-UNIQUE* token |
| 100 | +* **adminPassword** is some value other than the default *GEN-PASSWORD* token |
| 101 | +* **certificateThumbprint**, **sourceVaultResourceId**, and **certificateUrlValue** are all empty string (`""`) |
| 102 | + |
| 103 | +For example: |
| 104 | + |
| 105 | +```json |
| 106 | +{ |
| 107 | + "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#", |
| 108 | + "contentVersion": "1.0.0.0", |
| 109 | + "parameters": { |
| 110 | + "clusterName": { |
| 111 | + "value": "sfquickstart" |
| 112 | + }, |
| 113 | + "adminUsername": { |
| 114 | + "value": "testadm" |
| 115 | + }, |
| 116 | + "adminPassword": { |
| 117 | + "value": "Password#1234" |
| 118 | + }, |
| 119 | + "certificateThumbprint": { |
| 120 | + "value": "" |
| 121 | + }, |
| 122 | + "sourceVaultResourceId": { |
| 123 | + "value": "" |
| 124 | + }, |
| 125 | + "certificateUrlValue": { |
| 126 | + "value": "" |
| 127 | + } |
| 128 | + } |
| 129 | +} |
| 130 | +``` |
| 131 | + |
| 132 | +## Deploy the Bicep file |
| 133 | + |
| 134 | +Store the paths of your Bicep file and parameter file in variables, then deploy the Bicep file. |
| 135 | + |
| 136 | +```powershell |
| 137 | +$templateFilePath = "<full path to main.bicep>" |
| 138 | +$parameterFilePath = "<full path to azuredeploy.parameters.json>" |
| 139 | +
|
| 140 | +New-AzResourceGroupDeployment ` |
| 141 | + -ResourceGroupName $resourceGroupName ` |
| 142 | + -TemplateFile $templateFilePath ` |
| 143 | + -TemplateParameterFile $parameterFilePath ` |
| 144 | + -CertificateThumbprint $certThumbprint ` |
| 145 | + -CertificateUrlValue $certUrlValue ` |
| 146 | + -SourceVaultResourceId $sourceVaultId ` |
| 147 | + -Verbose |
| 148 | +``` |
| 149 | + |
| 150 | +## Review deployed resources |
| 151 | + |
| 152 | +Once the deployment completes, find the `managementEndpoint` value in the output and open the address in a web browser to view your cluster in [Service Fabric Explorer](./service-fabric-visualizing-your-cluster.md). |
| 153 | + |
| 154 | + |
| 155 | + |
| 156 | +You can also find the Service Fabric Explorer endpoint from your Service Explorer resource blade in Azure portal. |
| 157 | + |
| 158 | + |
| 159 | + |
| 160 | +## Clean up resources |
| 161 | + |
| 162 | +When no longer needed, use the Azure portal, Azure CLI, or Azure PowerShell to delete the resource group and its resources. |
| 163 | + |
| 164 | +# [CLI](#tab/CLI) |
| 165 | + |
| 166 | +```azurecli-interactive |
| 167 | +az group delete --name exampleRG |
| 168 | +``` |
| 169 | + |
| 170 | +# [PowerShell](#tab/PowerShell) |
| 171 | + |
| 172 | +```azurepowershell-interactive |
| 173 | +Remove-AzResourceGroup -Name exampleRG |
| 174 | +``` |
| 175 | + |
| 176 | +--- |
| 177 | + |
| 178 | +Next, remove the cluster certificate from your local store. List installed certificates to find the thumbprint for your cluster: |
| 179 | + |
| 180 | +```powershell |
| 181 | +Get-ChildItem Cert:\CurrentUser\My\ |
| 182 | +``` |
| 183 | + |
| 184 | +Then remove the certificate: |
| 185 | + |
| 186 | +```powershell |
| 187 | +Get-ChildItem Cert:\CurrentUser\My\{THUMBPRINT} | Remove-Item |
| 188 | +``` |
| 189 | + |
| 190 | +## Next steps |
| 191 | + |
| 192 | +To learn how to create Bicep files with Visual Studio Code, see: |
| 193 | + |
| 194 | +> [!div class="nextstepaction"] |
| 195 | +> [Quickstart: Create Bicep files with Visual Studio Code](../azure-resource-manager/bicep/quickstart-create-bicep-use-visual-studio-code.md) |
0 commit comments