Skip to content

Commit 0357001

Browse files
committed
Adding Bicep support to AKS
1 parent bf12065 commit 0357001

File tree

2 files changed

+199
-1
lines changed

2 files changed

+199
-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: 196 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,196 @@
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 in which Azure Stack HCI is used 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+
- Logic 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 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. Go to `https://shell.azure.com` to open a Cloud Shell session 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+
# Or, create an SSH key pair using ssh-keygen
47+
ssh-keygen -t rsa -b 4096
48+
```
49+
50+
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).
51+
52+
## Update and review the Bicep scripts
53+
54+
This section shows the Bicep parameter and template files. They are also available in an [Azure Quickstart template](https://github.com/Azure/azure-quickstart-templates).
55+
56+
### Bicep parameter file: aksarc.bicepparam
57+
58+
```bicep
59+
using 'main.bicep'
60+
param aksClusterName = 'aksarc-bicep-new'
61+
param aksControlPlaneIP = 'x.x.x.x'
62+
param sshPublicKey = 'ssh_public_key'
63+
param hciLogicalNetworkName = 'lnet_name'
64+
param hciCustomLocationName = 'cl_name'
65+
param aksNodePoolOSType = 'Linux'
66+
param aksNodePoolNodeCount = 1
67+
```
68+
69+
### Bicep template file: main.bicep
70+
71+
```bicep
72+
@description('The name of AKS Arc cluster resource')
73+
param aksClusterName string
74+
param location string = 'eastus'
75+
76+
// Default to 1 node CP
77+
@description('The name of AKS Arc cluster control plane IP, please provide this parameter during deployment')
78+
param aksControlPlaneIP string
79+
param aksControlPlaneNodeSize string = 'Standard_A4_v2'
80+
param aksControlPlaneNodeCount int = 1
81+
82+
// Default to 1 node NP
83+
param aksNodePoolName string = 'nodepool1'
84+
param aksNodePoolNodeSize string = 'Standard_A4_v2'
85+
param aksNodePoolNodeCount int = 1
86+
@allowed(['Linux', 'Windows'])
87+
param aksNodePoolOSType string = 'Linux'
88+
89+
@description('SSH public key used for cluster creation, please provide this parameter during deployment')
90+
param sshPublicKey string
91+
92+
// Build LNet ID from LNet name
93+
@description('The name of LNet resource, please provide this parameter during deployment')
94+
param hciLogicalNetworkName string
95+
resource logicalNetwork 'Microsoft.AzureStackHCI/logicalNetworks@2023-09-01-preview' existing = {
96+
name: hciLogicalNetworkName
97+
}
98+
99+
// Build custom location ID from custom location name
100+
@description('The name of custom location resource, please provide this parameter during deployment')
101+
param hciCustomLocationName string
102+
var customLocationId = resourceId('Microsoft.ExtendedLocation/customLocations', hciCustomLocationName)
103+
104+
// Create the connected cluster - this is the Arc representation of the AKS cluster, used to create a Managed Identity for the provisioned cluster
105+
resource connectedCluster 'Microsoft.Kubernetes/ConnectedClusters@2024-01-01' = {
106+
location: location
107+
name: aksClusterName
108+
identity: {
109+
type: 'SystemAssigned'
110+
}
111+
kind: 'ProvisionedCluster'
112+
properties: {
113+
agentPublicKeyCertificate: ''
114+
aadProfile: {
115+
enableAzureRBAC: false
116+
}
117+
}
118+
}
119+
120+
// Create the provisioned cluster instance - this is the actual AKS cluster and provisioned on your HCI cluster via the Arc Resource Bridge
121+
resource provisionedClusterInstance 'Microsoft.HybridContainerService/provisionedClusterInstances@2024-01-01' = {
122+
name: 'default'
123+
scope: connectedCluster
124+
extendedLocation: {
125+
type: 'CustomLocation'
126+
name: customLocationId
127+
}
128+
properties: {
129+
linuxProfile: {
130+
ssh: {
131+
publicKeys: [
132+
{
133+
keyData: sshPublicKey
134+
}
135+
]
136+
}
137+
}
138+
controlPlane: {
139+
count: aksControlPlaneNodeCount
140+
controlPlaneEndpoint: {
141+
hostIP: aksControlPlaneIP
142+
}
143+
vmSize: aksControlPlaneNodeSize
144+
}
145+
networkProfile: {
146+
loadBalancerProfile: {
147+
count: 0
148+
}
149+
networkPolicy: 'calico'
150+
}
151+
agentPoolProfiles: [
152+
{
153+
name: aksNodePoolName
154+
count: aksNodePoolNodeCount
155+
vmSize: aksNodePoolNodeSize
156+
osType: aksNodePoolOSType
157+
}
158+
]
159+
cloudProviderProfile: {
160+
infraNetworkProfile: {
161+
vnetSubnetIds: [
162+
logicalNetwork.id
163+
]
164+
}
165+
}
166+
storageProfile: {
167+
nfsCsiDriver: {
168+
enabled: true
169+
}
170+
smbCsiDriver: {
171+
enabled: true
172+
}
173+
}
174+
}
175+
}
176+
```
177+
178+
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).
179+
180+
## Deploy the Bicep file
181+
182+
1. Save the Bicep file as **main.bicep** to your local computer.
183+
1. Update the parameters defined in **aksarc.bicepparam** and save it to your local computer.
184+
1. Deploy the Bicep file using Azure CLI:
185+
186+
```azurecli
187+
az deployment group create --name BicepDeployment --resource-group myResourceGroupName --template-file main.bicep –-parameters aksarc.bicepparam
188+
```
189+
190+
## Validate the Bicep deployment and connect to the cluster
191+
192+
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).
193+
194+
## Next steps
195+
196+
[Create Kubernetes clusters using Azure CLI](aks-create-clusters-cli.md)

0 commit comments

Comments
 (0)