Skip to content

Commit b46e26b

Browse files
authored
Merge pull request #15574 from sethmanheim/bicep
Adding Bicep support for AKS
2 parents 8d17b87 + 5fcf03b commit b46e26b

File tree

2 files changed

+202
-1
lines changed

2 files changed

+202
-1
lines changed

AKS-Hybrid/TOC.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,9 @@
4747
- name: Azure CLI
4848
href: aks-create-clusters-cli.md
4949
- name: Azure portal
50-
href: aks-create-clusters-portal.md
50+
href: aks-create-clusters-portal.md
51+
- name: Bicep
52+
href: create-clusters-bicep.md
5153
- name: Deploy to Azure using a quickstart template
5254
href: /samples/azure/azure-quickstart-templates/aks-on-ashci
5355
- name: Azure Resource Manager template

AKS-Hybrid/create-clusters-bicep.md

Lines changed: 199 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,199 @@
1+
---
2+
title: Create Kubernetes clusters using Bicep
3+
description: Learn how to create Kubernetes clusters in Azure Stack HCI using Bicep.
4+
ms.topic: how-to
5+
ms.custom: devx-track-azurecli
6+
ms.date: 07/26/2024
7+
author: sethmanheim
8+
ms.author: sethm
9+
ms.reviewer: haojiehang
10+
ms.lastreviewed: 07/24/2024
11+
12+
---
13+
14+
# Create Kubernetes clusters using Bicep
15+
16+
This article describes how to create Kubernetes clusters in Azure Stack HCI using Bicep. The workflow is as follows:
17+
18+
1. Create an SSH key pair
19+
1. Create a Kubernetes cluster in Azure Stack HCI 23H2 using Bicep. By default, the cluster is Azure Arc-connected.
20+
1. Validate the deployment and connect to the cluster.
21+
22+
## Before you begin
23+
24+
Before you begin, make sure you have the following prerequisites:
25+
26+
1. Get the following details from your on-premises infrastructure administrator:
27+
28+
- Azure subscription ID: the Azure subscription ID that uses Azure Stack HCI for deployment and registration.
29+
- Custom location name or ID: the Azure Resource Manager ID of the custom location. The custom location is configured during the Azure Stack HCI cluster deployment. Your infrastructure admin should give you the Resource Manager ID of the custom location. This parameter is required in order to create Kubernetes clusters. You can also get the Resource Manager ID using `az customlocation show --name "<custom location name>" --resource-group <azure resource group> --query "id" -o tsv`, if the infrastructure admin provides a custom location name and resource group name.
30+
- Logical network name or ID: the Azure Resource Manager ID of the Azure Stack HCI logical network that was created following these steps. Your admin should give you the ID of the logical network. This parameter is required in order to create Kubernetes clusters. You can also get the Azure Resource Manager ID using `az stack-hci-vm network lnet show --name "<lnet name>" --resource-group <azure resource group> --query "id" -o tsv` if you know the resource group in which the logical network was created.
31+
32+
1. Make sure you have the [latest version of Azure CLI](/cli/azure/install-azure-cli) on your development machine. You can also upgrade your Azure CLI version using `az upgrade`.
33+
1. Download and install **kubectl** on your development machine. The Kubernetes command-line tool, **kubectl**, enables you to run commands against Kubernetes clusters. You can use **kubectl** to deploy applications, inspect and manage cluster resources, and view logs.
34+
35+
## Create an SSH key pair
36+
37+
To create an SSH key pair (same as Azure AKS), use the following procedure:
38+
39+
1. [Open a Cloud Shell session](https://shell.azure.com) in your browser.
40+
1. Create an SSH key pair using the `az sshkey create` Azure CLI command or the `ssh-keygen` command:
41+
42+
```azurecli
43+
# Create an SSH key pair using Azure CLI
44+
az sshkey create --name "mySSHKey" --resource-group "myResourceGroup"
45+
```
46+
47+
Or, create an SSH key pair using `ssh-keygen`:
48+
49+
```bash
50+
ssh-keygen -t rsa -b 4096
51+
```
52+
53+
For more information about creating SSH keys, see [Create and manage SSH keys for authentication in Azure](/azure/virtual-machines/linux/create-ssh-keys-detailed).
54+
55+
## Update and review the Bicep scripts
56+
57+
This section shows the Bicep parameter and template files. These files are also available in an [Azure Quickstart template](https://github.com/Azure/azure-quickstart-templates).
58+
59+
### Bicep parameter file: aksarc.bicepparam
60+
61+
```bicep
62+
using 'main.bicep'
63+
param aksClusterName = 'aksarc-bicep-new'
64+
param aksControlPlaneIP = 'x.x.x.x'
65+
param sshPublicKey = 'ssh_public_key'
66+
param hciLogicalNetworkName = 'lnet_name'
67+
param hciCustomLocationName = 'cl_name'
68+
param aksNodePoolOSType = 'Linux'
69+
param aksNodePoolNodeCount = 1
70+
```
71+
72+
### Bicep template file: main.bicep
73+
74+
```bicep
75+
@description('The name of AKS Arc cluster resource')
76+
param aksClusterName string
77+
param location string = 'eastus'
78+
79+
// Default to 1 node CP
80+
@description('The name of AKS Arc cluster control plane IP, provide this parameter during deployment')
81+
param aksControlPlaneIP string
82+
param aksControlPlaneNodeSize string = 'Standard_A4_v2'
83+
param aksControlPlaneNodeCount int = 1
84+
85+
// Default to 1 node NP
86+
param aksNodePoolName string = 'nodepool1'
87+
param aksNodePoolNodeSize string = 'Standard_A4_v2'
88+
param aksNodePoolNodeCount int = 1
89+
@allowed(['Linux', 'Windows'])
90+
param aksNodePoolOSType string = 'Linux'
91+
92+
@description('SSH public key used for cluster creation, provide this parameter during deployment')
93+
param sshPublicKey string
94+
95+
// Build LNet ID from LNet name
96+
@description('The name of LNet resource, provide this parameter during deployment')
97+
param hciLogicalNetworkName string
98+
resource logicalNetwork 'Microsoft.AzureStackHCI/logicalNetworks@2023-09-01-preview' existing = {
99+
name: hciLogicalNetworkName
100+
}
101+
102+
// Build custom location ID from custom location name
103+
@description('The name of custom location resource, provide this parameter during deployment')
104+
param hciCustomLocationName string
105+
var customLocationId = resourceId('Microsoft.ExtendedLocation/customLocations', hciCustomLocationName)
106+
107+
// Create the connected cluster. This is the Arc representation of the AKS cluster, used to create a Managed Identity for the provisioned cluster.
108+
resource connectedCluster 'Microsoft.Kubernetes/ConnectedClusters@2024-01-01' = {
109+
location: location
110+
name: aksClusterName
111+
identity: {
112+
type: 'SystemAssigned'
113+
}
114+
kind: 'ProvisionedCluster'
115+
properties: {
116+
agentPublicKeyCertificate: ''
117+
aadProfile: {
118+
enableAzureRBAC: false
119+
}
120+
}
121+
}
122+
123+
// Create the provisioned cluster instance. This is the actual AKS cluster and provisioned on your HCI cluster via the Arc Resource Bridge.
124+
resource provisionedClusterInstance 'Microsoft.HybridContainerService/provisionedClusterInstances@2024-01-01' = {
125+
name: 'default'
126+
scope: connectedCluster
127+
extendedLocation: {
128+
type: 'CustomLocation'
129+
name: customLocationId
130+
}
131+
properties: {
132+
linuxProfile: {
133+
ssh: {
134+
publicKeys: [
135+
{
136+
keyData: sshPublicKey
137+
}
138+
]
139+
}
140+
}
141+
controlPlane: {
142+
count: aksControlPlaneNodeCount
143+
controlPlaneEndpoint: {
144+
hostIP: aksControlPlaneIP
145+
}
146+
vmSize: aksControlPlaneNodeSize
147+
}
148+
networkProfile: {
149+
loadBalancerProfile: {
150+
count: 0
151+
}
152+
networkPolicy: 'calico'
153+
}
154+
agentPoolProfiles: [
155+
{
156+
name: aksNodePoolName
157+
count: aksNodePoolNodeCount
158+
vmSize: aksNodePoolNodeSize
159+
osType: aksNodePoolOSType
160+
}
161+
]
162+
cloudProviderProfile: {
163+
infraNetworkProfile: {
164+
vnetSubnetIds: [
165+
logicalNetwork.id
166+
]
167+
}
168+
}
169+
storageProfile: {
170+
nfsCsiDriver: {
171+
enabled: true
172+
}
173+
smbCsiDriver: {
174+
enabled: true
175+
}
176+
}
177+
}
178+
}
179+
```
180+
181+
The **Microsoft.HybridContainerService/provisionedClusterInstances** resource is defined in the Bicep file. If you want to explore more properties, [see the API reference](/azure/templates/microsoft.hybridcontainerservice/provisionedclusterinstances?pivots=deployment-language-bicep).
182+
183+
## Deploy the Bicep file
184+
185+
1. Save the Bicep file as **main.bicep** to your local computer.
186+
1. Update the parameters defined in **aksarc.bicepparam** and save it to your local computer.
187+
1. Deploy the Bicep file using Azure CLI:
188+
189+
```azurecli
190+
az deployment group create --name BicepDeployment --resource-group myResourceGroupName --template-file main.bicep –-parameters aksarc.bicepparam
191+
```
192+
193+
## Validate the Bicep deployment and connect to the cluster
194+
195+
You can now connect to your Kubernetes cluster by running the `az connectedk8s proxy` command from your development machine. You can also use **kubectl** to see the node and pod status. Follow the same steps as described in [Connect to the Kubernetes cluster](aks-create-clusters-cli.md#connect-to-the-kubernetes-cluster).
196+
197+
## Next steps
198+
199+
[Create Kubernetes clusters using Azure CLI](aks-create-clusters-cli.md)

0 commit comments

Comments
 (0)