在本快速入門中,您使用 Azure Resource Manager (ARM) 範本建立新的 Azure Kubernetes Service (AKS) 叢集,以及 Azure 防火牆 Premium for Azure 防火牆 for Containers。 該範本同時設定受管理身份、防火牆政策及網路路由。
預設情況下,範本僅部署 Azure 資源。 接著,您接著安裝 Azure 防火牆 Controller,並依照範本的 README 附加範例安全政策。 一個可選參數同時用於安裝控制器、範例政策及測試 Pod。
Azure Resource Manager 模板 是一個 JavaScript 物件符號(JSON)檔案,用來定義你專案的基礎架構與設定。 範本使用宣告式語法。 您可以描述預期的部署,而不需要撰寫程式設計命令順序來建立部署。
Important
Azure 防火牆 for Containers 目前處於公開預覽階段。 請參閱Microsoft Azure 預覽的補充使用條款,以了解適用於 Azure 測試版、預覽版或其他尚未正式發布的功能的法律條款。
如果您的環境符合先決條件,請選擇部署至 Azure。 範本會在 Azure 入口網站的自訂部署頁面開啟。
Prerequisites
- 一個有有效訂閱的 Azure 帳號。 免費建立帳戶。
- 在受支援的預覽區域中存取 Azure 防火牆 for Containers。
-
在訂閱中註冊的
Microsoft.ContainerService和Microsoft.Network資源提供者。 - 在資源群組中建立 AKS、網路資源、受管理身份及角色指派的權限。 建立角色指派需要在指派範圍內具備適當的角色,例如角色型 存取控制 系統管理員。
- 所選 AKS 節點虛擬機器大小的容量與配額。 預設部署使用兩個大小為
Standard_DS3_v2的節點;此大小必須在您所選的區域中可用。 - 部署後步驟所需的 Azure CLI、kubectl 和 Helm。
使用隔離的評估環境。 範本會建立一個新的叢集,並將 AKS 子網路的出站流量透過防火牆路由。
若要將範本的 Location 參數維持為預設,請在下列預覽區域之一選取或建立資源群組:
| Region | Azure 區域值 |
|---|---|
| 美國中部 EUAP | centraluseuap |
| 美國東部 2 EUAP | eastus2euap |
| 美國中西部 | westcentralus |
| 東亞 | eastasia |
| 英國南部 | uksouth |
| Central US | centralus |
檢閱範本
這個範本來自 Azure Quickstart Templates。
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"metadata": {
"_generator": {
"name": "bicep",
"version": "0.48.1.52935",
"templateHash": "16236338146850503249"
}
},
"parameters": {
"location": {
"type": "string",
"defaultValue": "[resourceGroup().location]",
"metadata": {
"description": "Location for all resources. Must be an Azure Firewall for Containers preview region (centraluseuap, eastus2euap, westcentralus, eastasia, uksouth, centralus)."
}
},
"namePrefix": {
"type": "string",
"defaultValue": "afc",
"maxLength": 12,
"metadata": {
"description": "Prefix used to name the resources."
}
},
"nodeVmSize": {
"type": "string",
"defaultValue": "Standard_DS3_v2",
"metadata": {
"description": "VM size for the AKS nodes. Must be available in the selected region."
}
},
"nodeCount": {
"type": "int",
"defaultValue": 2,
"minValue": 1,
"maxValue": 10,
"metadata": {
"description": "Number of AKS nodes."
}
},
"controllerVersion": {
"type": "string",
"defaultValue": "20261103.2",
"metadata": {
"description": "Azure Firewall for Containers controller Helm chart version."
}
},
"controllerNamespace": {
"type": "string",
"defaultValue": "firewall-namespace",
"metadata": {
"description": "Kubernetes namespace for the controller. Used in the workload identity federated credential subject."
}
},
"deployControllerAndSample": {
"type": "bool",
"defaultValue": false,
"metadata": {
"description": "false (default): deploy Azure resources only; the outputs contain the remaining commands. true: also run a deployment script that installs the controller and applies a sample security policy, attachment, and test pods. The script needs a storage account with shared key access, so it fails where Azure Policy denies shared key access."
}
},
"azCliVersion": {
"type": "string",
"defaultValue": "2.61.0",
"metadata": {
"description": "Azure CLI version used by the deployment script."
}
},
"utcValue": {
"type": "string",
"defaultValue": "[utcNow()]",
"metadata": {
"description": "Unique suffix that forces the deployment script to rerun on each deployment. Leave the default."
}
}
},
"variables": {
"$fxv#0": "#!/bin/bash\n# Runs inside Microsoft.Resources/deploymentScripts (Azure CLI container, signed in with the script identity).\n# Installs the Azure Firewall for Containers controller and applies a sample policy, attachment, and test pods.\nset -euo pipefail\n\necho \"Getting cluster credentials for ${CLUSTER_NAME}\"\naz aks get-credentials --resource-group \"$RESOURCE_GROUP\" --name \"$CLUSTER_NAME\" --admin --file ./kubeconfig --overwrite-existing --only-show-errors\nchmod 600 ./kubeconfig\nexport KUBECONFIG=\"$PWD/kubeconfig\"\n\ndownload() { # url dest; the Azure CLI container image may not include curl\n if command -v curl >/dev/null 2>&1; then curl -fsSL \"$1\" -o \"$2\"\n elif command -v wget >/dev/null 2>&1; then wget -qO \"$2\" \"$1\"\n else python3 -c \"import sys, urllib.request; urllib.request.urlretrieve(sys.argv[1], sys.argv[2])\" \"$1\" \"$2\"\n fi\n}\n\necho \"Installing kubectl and helm\"\naz aks install-cli --install-location /usr/local/bin/kubectl --kubelogin-install-location /usr/local/bin/kubelogin --only-show-errors >/dev/null\ndownload https://get.helm.sh/helm-v3.16.2-linux-amd64.tar.gz /tmp/helm.tar.gz\ntar -xzf /tmp/helm.tar.gz -C /tmp\ninstall /tmp/linux-amd64/helm /usr/local/bin/helm\n\necho \"Installing controller ${CONTROLLER_VERSION}\"\nhelm upgrade --install azfw-controller \\\n oci://mcr.microsoft.com/firewall/charts/azurefirewall-controller \\\n --namespace \"$CONTROLLER_NAMESPACE\" \\\n --create-namespace \\\n --version \"$CONTROLLER_VERSION\" \\\n --set \"azfwController.podIdentity.clientID=${CONTROLLER_CLIENT_ID}\" \\\n --wait --timeout 10m\nkubectl wait --for=condition=Available deploy --all --namespace \"$CONTROLLER_NAMESPACE\" --timeout=10m\nkubectl wait --for=condition=Established crd/securitypolicyattachments.firewall.networking.azure.io --timeout=5m\n\necho \"Applying sample security policy and attachment\"\nkubectl apply -f - <<EOF\napiVersion: firewall.networking.azure.io/v1alpha1\nkind: SecurityPolicy\nmetadata:\n name: example-securitypolicy-rules\n namespace: default\nspec:\n applicationRuleCollections:\n - name: test-application-rules\n refs:\n - podSelector:\n matchLabels:\n role: developer\n action: Allow\n egress:\n - name: allow-test-destinations\n toPortProtocol:\n - protocolType: HTTPS\n port: 443\n to:\n - fqdn:\n - \"*.microsoft.com\"\n - \"*.google.com\"\n---\napiVersion: firewall.networking.azure.io/v1alpha1\nkind: SecurityPolicyAttachment\nmetadata:\n name: example-attachment\n namespace: default\nspec:\n securityPolicyRefs:\n - name: example-securitypolicy-rules\n namespace: default\n firewallRef:\n id: ${FIREWALL_ID}\n aksWorkloadSubnets:\n - ${AKS_SUBNET_ID}\nEOF\n\necho \"Waiting for the attachment to deploy\"\nkubectl wait --for=jsonpath='{.status.conditions[?(@.type==\"Deployment\")].reason}'=Ready \\\n securitypolicyattachment/example-attachment --namespace default --timeout=40m\nkubectl get securitypolicyattachment example-attachment --namespace default \\\n -o jsonpath='{range .status.conditions[*]}{.type}={.status} {.reason}{\"\\n\"}{end}'\n\necho \"Creating test pods\"\nkubectl apply -f - <<'EOF'\napiVersion: v1\nkind: Pod\nmetadata:\n name: developer-pod\n namespace: default\n labels:\n role: developer\nspec:\n containers:\n - name: developer\n image: mcr.microsoft.com/azure-cli:latest\n command: [\"sleep\", \"infinity\"]\n---\napiVersion: v1\nkind: Pod\nmetadata:\n name: other-pod\n namespace: default\n labels:\n role: other\nspec:\n containers:\n - name: other\n image: mcr.microsoft.com/azure-cli:latest\n command: [\"sleep\", \"infinity\"]\nEOF\nkubectl wait --for=condition=Ready pod/developer-pod pod/other-pod --namespace default --timeout=10m\n\nATTACH_STATUS=$(kubectl get securitypolicyattachment example-attachment --namespace default \\\n -o jsonpath='{.status.conditions[?(@.type==\"Deployment\")].reason}')\ncat > \"$AZ_SCRIPTS_OUTPUT_PATH\" <<EOF\n{\"controllerVersion\": \"${CONTROLLER_VERSION}\", \"attachmentDeployment\": \"${ATTACH_STATUS}\"}\nEOF\necho \"Done\"\n",
"vnetName": "[format('{0}-vnet', parameters('namePrefix'))]",
"aksSubnetName": "aks-subnet",
"vnetAddressPrefix": "10.224.0.0/12",
"aksSubnetPrefix": "10.224.0.0/16",
"firewallSubnetPrefix": "10.225.0.0/26",
"firewallMgmtSubnetPrefix": "10.225.1.0/26",
"clusterName": "[format('{0}-aks', parameters('namePrefix'))]",
"firewallName": "[format('{0}-firewall', parameters('namePrefix'))]",
"firewallPolicyName": "[format('{0}-firewall-policy', parameters('namePrefix'))]",
"routeTableName": "[format('{0}-aks-rt', parameters('namePrefix'))]",
"controllerServiceAccount": "azurefirewall-controller-sa",
"networkContributorRoleId": "[subscriptionResourceId('Microsoft.Authorization/roleDefinitions', '4d97b98b-1d4f-4787-a291-c67834d212e7')]",
"aksClusterAdminRoleId": "[subscriptionResourceId('Microsoft.Authorization/roleDefinitions', '0ab0b1a8-8aac-4efd-b8c2-3ee1fb270be8')]",
"aksSubnetId": "[format('{0}/subnets/{1}', resourceId('Microsoft.Network/virtualNetworks', variables('vnetName')), variables('aksSubnetName'))]"
},
"resources": [
{
"type": "Microsoft.ManagedIdentity/userAssignedIdentities",
"apiVersion": "2024-11-30",
"name": "[format('{0}-aks-identity', parameters('namePrefix'))]",
"location": "[parameters('location')]"
},
{
"type": "Microsoft.ManagedIdentity/userAssignedIdentities",
"apiVersion": "2024-11-30",
"name": "[format('{0}-controller-identity', parameters('namePrefix'))]",
"location": "[parameters('location')]"
},
{
"type": "Microsoft.Network/virtualNetworks",
"apiVersion": "2025-05-01",
"name": "[variables('vnetName')]",
"location": "[parameters('location')]",
"properties": {
"addressSpace": {
"addressPrefixes": [
"[variables('vnetAddressPrefix')]"
]
},
"subnets": [
{
"name": "[variables('aksSubnetName')]",
"properties": {
"addressPrefix": "[variables('aksSubnetPrefix')]",
"defaultOutboundAccess": false
}
},
{
"name": "AzureFirewallSubnet",
"properties": {
"addressPrefix": "[variables('firewallSubnetPrefix')]",
"defaultOutboundAccess": false
}
},
{
"name": "AzureFirewallManagementSubnet",
"properties": {
"addressPrefix": "[variables('firewallMgmtSubnetPrefix')]",
"defaultOutboundAccess": false
}
}
]
}
},
{
"type": "Microsoft.Authorization/roleAssignments",
"apiVersion": "2022-04-01",
"scope": "[resourceId('Microsoft.Network/virtualNetworks', variables('vnetName'))]",
"name": "[guid(resourceId('Microsoft.Network/virtualNetworks', variables('vnetName')), resourceId('Microsoft.ManagedIdentity/userAssignedIdentities', format('{0}-aks-identity', parameters('namePrefix'))), variables('networkContributorRoleId'))]",
"properties": {
"roleDefinitionId": "[variables('networkContributorRoleId')]",
"principalId": "[reference(resourceId('Microsoft.ManagedIdentity/userAssignedIdentities', format('{0}-aks-identity', parameters('namePrefix'))), '2024-11-30').principalId]",
"principalType": "ServicePrincipal"
},
"dependsOn": [
"[resourceId('Microsoft.ManagedIdentity/userAssignedIdentities', format('{0}-aks-identity', parameters('namePrefix')))]",
"[resourceId('Microsoft.Network/virtualNetworks', variables('vnetName'))]"
]
},
{
"type": "Microsoft.Network/publicIPAddresses",
"apiVersion": "2025-05-01",
"name": "[format('{0}-fw-ip', parameters('namePrefix'))]",
"location": "[parameters('location')]",
"sku": {
"name": "Standard"
},
"properties": {
"publicIPAllocationMethod": "Static",
"publicIPAddressVersion": "IPv4"
}
},
{
"type": "Microsoft.Network/publicIPAddresses",
"apiVersion": "2025-05-01",
"name": "[format('{0}-fw-mgmt-ip', parameters('namePrefix'))]",
"location": "[parameters('location')]",
"sku": {
"name": "Standard"
},
"properties": {
"publicIPAllocationMethod": "Static",
"publicIPAddressVersion": "IPv4"
}
},
{
"type": "Microsoft.Network/firewallPolicies",
"apiVersion": "2025-05-01",
"name": "[variables('firewallPolicyName')]",
"location": "[parameters('location')]",
"properties": {
"sku": {
"tier": "Premium"
},
"threatIntelMode": "Alert"
}
},
{
"type": "Microsoft.Network/firewallPolicies/ruleCollectionGroups",
"apiVersion": "2025-05-01",
"name": "[format('{0}/{1}', variables('firewallPolicyName'), 'default-allow-aks-controlplane')]",
"properties": {
"priority": 100,
"ruleCollections": [
{
"ruleCollectionType": "FirewallPolicyFilterRuleCollection",
"name": "AllowAksControlPlaneNetwork",
"priority": 100,
"action": {
"type": "Allow"
},
"rules": [
{
"ruleType": "NetworkRule",
"name": "Allow_AKS_ControlPlane_Network",
"ipProtocols": [
"TCP"
],
"sourceAddresses": [
"*"
],
"destinationAddresses": [
"AzureKubernetesService"
],
"destinationPorts": [
"443"
]
}
]
},
{
"ruleCollectionType": "FirewallPolicyFilterRuleCollection",
"name": "AllowAksControlPlaneApp",
"priority": 101,
"action": {
"type": "Allow"
},
"rules": [
{
"ruleType": "ApplicationRule",
"name": "Allow_AKS_ControlPlane_App",
"sourceAddresses": [
"*"
],
"fqdnTags": [
"AzureKubernetesService"
],
"protocols": [
{
"protocolType": "Https",
"port": 443
}
]
},
{
"ruleType": "ApplicationRule",
"name": "Allow_AFC_Service",
"sourceAddresses": [
"*"
],
"targetFqdns": [
"*.afc.azure.com"
],
"protocols": [
{
"protocolType": "Https",
"port": 443
}
]
}
]
}
]
},
"dependsOn": [
"[resourceId('Microsoft.Network/firewallPolicies', variables('firewallPolicyName'))]"
]
},
{
"type": "Microsoft.Network/azureFirewalls",
"apiVersion": "2025-05-01",
"name": "[variables('firewallName')]",
"location": "[parameters('location')]",
"properties": {
"sku": {
"name": "AZFW_VNet",
"tier": "Premium"
},
"firewallPolicy": {
"id": "[resourceId('Microsoft.Network/firewallPolicies', variables('firewallPolicyName'))]"
},
"ipConfigurations": [
{
"name": "data-ipconfig",
"properties": {
"subnet": {
"id": "[resourceId('Microsoft.Network/virtualNetworks/subnets', variables('vnetName'), 'AzureFirewallSubnet')]"
},
"publicIPAddress": {
"id": "[resourceId('Microsoft.Network/publicIPAddresses', format('{0}-fw-ip', parameters('namePrefix')))]"
}
}
}
],
"managementIpConfiguration": {
"name": "mgmt-ipconfig",
"properties": {
"subnet": {
"id": "[resourceId('Microsoft.Network/virtualNetworks/subnets', variables('vnetName'), 'AzureFirewallManagementSubnet')]"
},
"publicIPAddress": {
"id": "[resourceId('Microsoft.Network/publicIPAddresses', format('{0}-fw-mgmt-ip', parameters('namePrefix')))]"
}
}
}
},
"dependsOn": [
"[resourceId('Microsoft.Network/firewallPolicies/ruleCollectionGroups', variables('firewallPolicyName'), 'default-allow-aks-controlplane')]",
"[resourceId('Microsoft.Network/publicIPAddresses', format('{0}-fw-mgmt-ip', parameters('namePrefix')))]",
"[resourceId('Microsoft.Network/firewallPolicies', variables('firewallPolicyName'))]",
"[resourceId('Microsoft.Network/publicIPAddresses', format('{0}-fw-ip', parameters('namePrefix')))]",
"[resourceId('Microsoft.Network/virtualNetworks', variables('vnetName'))]"
]
},
{
"type": "Microsoft.ContainerService/managedClusters",
"apiVersion": "2025-07-01",
"name": "[variables('clusterName')]",
"location": "[parameters('location')]",
"identity": {
"type": "UserAssigned",
"userAssignedIdentities": {
"[format('{0}', resourceId('Microsoft.ManagedIdentity/userAssignedIdentities', format('{0}-aks-identity', parameters('namePrefix'))))]": {}
}
},
"properties": {
"dnsPrefix": "[variables('clusterName')]",
"agentPoolProfiles": [
{
"name": "nodepool1",
"mode": "System",
"count": "[parameters('nodeCount')]",
"vmSize": "[parameters('nodeVmSize')]",
"osType": "Linux",
"type": "VirtualMachineScaleSets",
"vnetSubnetID": "[variables('aksSubnetId')]"
}
],
"networkProfile": {
"networkPlugin": "azure",
"outboundType": "loadBalancer",
"loadBalancerSku": "standard",
"serviceCidr": "10.240.0.0/16",
"dnsServiceIP": "10.240.0.10"
},
"oidcIssuerProfile": {
"enabled": true
},
"securityProfile": {
"workloadIdentity": {
"enabled": true
}
}
},
"dependsOn": [
"[resourceId('Microsoft.ManagedIdentity/userAssignedIdentities', format('{0}-aks-identity', parameters('namePrefix')))]",
"[extensionResourceId(resourceId('Microsoft.Network/virtualNetworks', variables('vnetName')), 'Microsoft.Authorization/roleAssignments', guid(resourceId('Microsoft.Network/virtualNetworks', variables('vnetName')), resourceId('Microsoft.ManagedIdentity/userAssignedIdentities', format('{0}-aks-identity', parameters('namePrefix'))), variables('networkContributorRoleId')))]",
"[resourceId('Microsoft.Network/virtualNetworks', variables('vnetName'))]"
]
},
{
"type": "Microsoft.Authorization/roleAssignments",
"apiVersion": "2022-04-01",
"name": "[guid(resourceGroup().id, resourceId('Microsoft.ManagedIdentity/userAssignedIdentities', format('{0}-controller-identity', parameters('namePrefix'))), variables('networkContributorRoleId'))]",
"properties": {
"roleDefinitionId": "[variables('networkContributorRoleId')]",
"principalId": "[reference(resourceId('Microsoft.ManagedIdentity/userAssignedIdentities', format('{0}-controller-identity', parameters('namePrefix'))), '2024-11-30').principalId]",
"principalType": "ServicePrincipal"
},
"dependsOn": [
"[resourceId('Microsoft.ManagedIdentity/userAssignedIdentities', format('{0}-controller-identity', parameters('namePrefix')))]"
]
},
{
"type": "Microsoft.ManagedIdentity/userAssignedIdentities/federatedIdentityCredentials",
"apiVersion": "2024-11-30",
"name": "[format('{0}/{1}', format('{0}-controller-identity', parameters('namePrefix')), 'azurefirewall-controller')]",
"properties": {
"issuer": "[reference(resourceId('Microsoft.ContainerService/managedClusters', variables('clusterName')), '2025-07-01').oidcIssuerProfile.issuerURL]",
"subject": "[format('system:serviceaccount:{0}:{1}', parameters('controllerNamespace'), variables('controllerServiceAccount'))]",
"audiences": [
"api://AzureADTokenExchange"
]
},
"dependsOn": [
"[resourceId('Microsoft.ContainerService/managedClusters', variables('clusterName'))]",
"[resourceId('Microsoft.ManagedIdentity/userAssignedIdentities', format('{0}-controller-identity', parameters('namePrefix')))]"
]
},
{
"type": "Microsoft.Network/routeTables",
"apiVersion": "2025-05-01",
"name": "[variables('routeTableName')]",
"location": "[parameters('location')]",
"properties": {
"routes": [
{
"name": "to-firewall",
"properties": {
"addressPrefix": "0.0.0.0/0",
"nextHopType": "VirtualAppliance",
"nextHopIpAddress": "[reference(resourceId('Microsoft.Network/azureFirewalls', variables('firewallName')), '2025-05-01').ipConfigurations[0].properties.privateIPAddress]"
}
}
]
},
"dependsOn": [
"[resourceId('Microsoft.Network/azureFirewalls', variables('firewallName'))]"
]
},
{
"type": "Microsoft.Network/virtualNetworks/subnets",
"apiVersion": "2025-05-01",
"name": "[format('{0}/{1}', variables('vnetName'), variables('aksSubnetName'))]",
"properties": {
"addressPrefix": "[variables('aksSubnetPrefix')]",
"defaultOutboundAccess": false,
"routeTable": {
"id": "[resourceId('Microsoft.Network/routeTables', variables('routeTableName'))]"
}
},
"dependsOn": [
"[resourceId('Microsoft.ContainerService/managedClusters', variables('clusterName'))]",
"[resourceId('Microsoft.Network/routeTables', variables('routeTableName'))]",
"[resourceId('Microsoft.Network/virtualNetworks', variables('vnetName'))]"
]
},
{
"condition": "[parameters('deployControllerAndSample')]",
"type": "Microsoft.ManagedIdentity/userAssignedIdentities",
"apiVersion": "2024-11-30",
"name": "[format('{0}-script-identity', parameters('namePrefix'))]",
"location": "[parameters('location')]"
},
{
"condition": "[parameters('deployControllerAndSample')]",
"type": "Microsoft.Authorization/roleAssignments",
"apiVersion": "2022-04-01",
"scope": "[resourceId('Microsoft.ContainerService/managedClusters', variables('clusterName'))]",
"name": "[guid(resourceId('Microsoft.ContainerService/managedClusters', variables('clusterName')), format('{0}-script-identity', parameters('namePrefix')), variables('aksClusterAdminRoleId'))]",
"properties": {
"roleDefinitionId": "[variables('aksClusterAdminRoleId')]",
"principalId": "[reference(resourceId('Microsoft.ManagedIdentity/userAssignedIdentities', format('{0}-script-identity', parameters('namePrefix'))), '2024-11-30').principalId]",
"principalType": "ServicePrincipal"
},
"dependsOn": [
"[resourceId('Microsoft.ContainerService/managedClusters', variables('clusterName'))]",
"[resourceId('Microsoft.ManagedIdentity/userAssignedIdentities', format('{0}-script-identity', parameters('namePrefix')))]"
]
},
{
"condition": "[parameters('deployControllerAndSample')]",
"type": "Microsoft.Resources/deploymentScripts",
"apiVersion": "2023-08-01",
"name": "[format('{0}-install-controller', parameters('namePrefix'))]",
"location": "[parameters('location')]",
"kind": "AzureCLI",
"identity": {
"type": "UserAssigned",
"userAssignedIdentities": {
"[format('{0}', resourceId('Microsoft.ManagedIdentity/userAssignedIdentities', format('{0}-script-identity', parameters('namePrefix'))))]": {}
}
},
"properties": {
"azCliVersion": "[parameters('azCliVersion')]",
"timeout": "PT1H",
"retentionInterval": "P1D",
"cleanupPreference": "OnSuccess",
"forceUpdateTag": "[parameters('utcValue')]",
"environmentVariables": [
{
"name": "RESOURCE_GROUP",
"value": "[resourceGroup().name]"
},
{
"name": "CLUSTER_NAME",
"value": "[variables('clusterName')]"
},
{
"name": "CONTROLLER_VERSION",
"value": "[parameters('controllerVersion')]"
},
{
"name": "CONTROLLER_NAMESPACE",
"value": "[parameters('controllerNamespace')]"
},
{
"name": "CONTROLLER_CLIENT_ID",
"value": "[reference(resourceId('Microsoft.ManagedIdentity/userAssignedIdentities', format('{0}-controller-identity', parameters('namePrefix'))), '2024-11-30').clientId]"
},
{
"name": "FIREWALL_ID",
"value": "[resourceId('Microsoft.Network/azureFirewalls', variables('firewallName'))]"
},
{
"name": "AKS_SUBNET_ID",
"value": "[variables('aksSubnetId')]"
}
],
"scriptContent": "[variables('$fxv#0')]"
},
"dependsOn": [
"[resourceId('Microsoft.ContainerService/managedClusters', variables('clusterName'))]",
"[resourceId('Microsoft.Network/virtualNetworks/subnets', variables('vnetName'), variables('aksSubnetName'))]",
"[resourceId('Microsoft.ManagedIdentity/userAssignedIdentities/federatedIdentityCredentials', format('{0}-controller-identity', parameters('namePrefix')), 'azurefirewall-controller')]",
"[resourceId('Microsoft.ManagedIdentity/userAssignedIdentities', format('{0}-controller-identity', parameters('namePrefix')))]",
"[resourceId('Microsoft.Authorization/roleAssignments', guid(resourceGroup().id, resourceId('Microsoft.ManagedIdentity/userAssignedIdentities', format('{0}-controller-identity', parameters('namePrefix'))), variables('networkContributorRoleId')))]",
"[resourceId('Microsoft.Network/azureFirewalls', variables('firewallName'))]",
"[extensionResourceId(resourceId('Microsoft.ContainerService/managedClusters', variables('clusterName')), 'Microsoft.Authorization/roleAssignments', guid(resourceId('Microsoft.ContainerService/managedClusters', variables('clusterName')), format('{0}-script-identity', parameters('namePrefix')), variables('aksClusterAdminRoleId')))]",
"[resourceId('Microsoft.ManagedIdentity/userAssignedIdentities', format('{0}-script-identity', parameters('namePrefix')))]",
"[resourceId('Microsoft.Network/virtualNetworks', variables('vnetName'))]"
]
}
],
"outputs": {
"clusterName": {
"type": "string",
"value": "[variables('clusterName')]"
},
"firewallId": {
"type": "string",
"value": "[resourceId('Microsoft.Network/azureFirewalls', variables('firewallName'))]"
},
"firewallPrivateIp": {
"type": "string",
"value": "[reference(resourceId('Microsoft.Network/azureFirewalls', variables('firewallName')), '2025-05-01').ipConfigurations[0].properties.privateIPAddress]"
},
"firewallPolicyId": {
"type": "string",
"value": "[resourceId('Microsoft.Network/firewallPolicies', variables('firewallPolicyName'))]"
},
"aksSubnetId": {
"type": "string",
"value": "[variables('aksSubnetId')]"
},
"controllerIdentityClientId": {
"type": "string",
"value": "[reference(resourceId('Microsoft.ManagedIdentity/userAssignedIdentities', format('{0}-controller-identity', parameters('namePrefix'))), '2024-11-30').clientId]"
},
"getCredentialsCommand": {
"type": "string",
"value": "[format('az aks get-credentials --resource-group {0} --name {1}', resourceGroup().name, variables('clusterName'))]"
},
"helmInstallCommand": {
"type": "string",
"value": "[format('helm install azfw-controller oci://mcr.microsoft.com/firewall/charts/azurefirewall-controller --namespace {0} --create-namespace --version {1} --set azfwController.podIdentity.clientID={2}', parameters('controllerNamespace'), parameters('controllerVersion'), reference(resourceId('Microsoft.ManagedIdentity/userAssignedIdentities', format('{0}-controller-identity', parameters('namePrefix'))), '2024-11-30').clientId)]"
},
"attachmentFirewallRef": {
"type": "string",
"value": "[format('firewallRef: {{ id: {0} }}', resourceId('Microsoft.Network/azureFirewalls', variables('firewallName')))]"
},
"controllerAndSampleInstalled": {
"type": "bool",
"value": "[parameters('deployControllerAndSample')]"
}
}
}
範本會建立以下資源:
| 資源 | Purpose |
|---|---|
| 虛擬網路和子網路 | 提供 AKS 子網路,AzureFirewallSubnet,且 AzureFirewallManagementSubnet |
| AKS 群集 | 使用 Azure CNI、OIDC 發行器及工作負載識別來執行工作負載 |
| Azure 防火牆 Premium 與公用 IP 位址 | 檢查叢集的出口流量 |
| 防火牆原則與規則集合群組 | 允許所需的 AKS 外寄流量及 HTTPS 至 *.afc.azure.com |
| 路由表與子網路關聯 | 將 AKS 子網路的出站流量透過防火牆路由 |
| 受管理身份、角色指派及聯合身份認證 | 為 AKS 網路與 Azure 防火牆 控制器設定授權 |
| 可選的部署腳本及其身分識別 | 當部署控制器與範例為 true 時,安裝控制器、範例原則、附件及測試 pod |
部署範本
除非您的環境允許選擇性部署腳本,否則請將 Deploy Controller And Sample 設為 false 。
在介紹末尾選擇「部署至 Azure」並登入 Azure。 入口網站會開啟 自訂部署 頁面。
配置以下設定:
Setting Value 訂閱 選擇評估所需的訂閱 資源群組 選擇或建立資源群組;新的專用資源群組讓清理更安全 地區 使用先決條件中列出的預覽區域 名稱前綴 請使用預設值 afc,或輸入資源名稱前綴節點 VM 大小 僅在所選區域可用時使用 Standard_DS3_v2;否則請輸入可用大小部署控制器與範例 保留 false 以僅部署 Azure 資源,然後依照 README 的安裝步驟操作。 僅當部署腳本允許共用金鑰存取時,才設定 true 。 Note
在 Deploy Controller And Sample 設定為
true時,範本會執行一個部署腳本,該腳本需要具備共享金鑰存取權的儲存帳戶。 如果內建的 Azure 原則 儲存體帳戶應防止共用金鑰存取 是以 拒絕 效果指派,則部署將失敗。 請保留預設值(false),並依照安裝步驟操作,或查看 範本說明 文件以檢查政策並申請豁免。其他參數保持預設值。 選擇 「檢視 + 建立 」並檢視驗證結果。
選擇創建。
Azure 資源部署大約需要 10-15 分鐘;如果將 Deploy Controller And Sample 設為 true,則約需要 30-45 分鐘。 部署時間可能有所不同。
檢閱已部署的資源
在 Azure 入口網站中,開啟資源群組並選擇「部署」。 開啟範本部署並確認其成功。
檢視已部署的 AKS 叢集、Azure 防火牆、防火牆政策、虛擬網路、路由及身份。 選擇 「輸出」 以尋找叢集名稱、防火牆資源 ID 及後續步驟的指令。
完成您的部署選項的控制器與原則設定:
部署選項 下一步行動 部署控制器與樣本 為 false 依照「 安裝控制器並附加政策」操作。 請使用 getCredentialsCommand和helmInstallCommand部署輸出,而非 README 範例指令。 建立範例防火牆參考與政策附件時,請使用輸出中的資源 ID。部署控制器與樣本 為 true 部署腳本會安裝控制器、範例原則、附件及測試 Pod。 執行 getCredentialsCommand以從您自己的環境連線。 跳過 README 控制器的安裝與 Pod 建立指令,以免重複建立現有資源
在執行 Azure CLI 指令之前,請先登入並選擇本次部署所使用的訂閱。 如果您更改 了名稱前綴,請使用部署輸出,例如 clusterName、 firewallId、 aksSubnetId和 controllerIdentityClientId ,而非 README 預設的資源名稱。
使用 README 的 流量測試 來驗證範例政策的允許與拒絕行為。 如果部署腳本已經建立了測試 pod,請使用這些現有 pod 的測試指令。 僅僅成功的 Azure 部署並不會驗證流量過濾。
清理資源
如果您是專門為此快速入門建立資源群組,請在完成部署評估後將其刪除:
- 在 Azure 入口網站中,開啟資源群組並檢視其資源。 確認其中沒有你需要保留的資源。
- 選擇 刪除資源群組。
- 輸入資源群組名稱並確認刪除。
刪除資源群組會移除該群組中的所有資源。 如果您重複使用了資源群組,請不要刪除該群組。 只移除您為此評估建立的資源。 若需要移除個別政策或附件,請依照 控制項目清理指引 操作。