The Kubernetes provider allows you to create Kubernetes resources directly with Bicep. Bicep can deploy anything that can be deployed with the Kubernetes command-line client (kubectl) and a Kubernetes
Enable the preview feature
This preview feature can be enabled by configuring the bicepconfig.json👍
The following sample imports the Kubernetes provider:
@secure()param kubeConfig stringimport'kubernetes@1.0.0'with { namespace: 'default' kubeConfig: kubeConfig} as k8s
Take this example:
@description('The name of the Managed Cluster resource.')param clusterName string = 'aks101cluster'@description('The location of the Managed Cluster resource.')param location string = resourceGroup().location@description('Optional DNS prefix to use with hosted Kubernetes API server FQDN.')param dnsPrefix string@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)param osDiskSizeGB int = 0@description('The number of nodes for the cluster.')@minValue(1)@maxValue(50)param agentCount int = 3@description('The size of the Virtual Machine.')param agentVMSize string = 'standard_d2s_v3'@description('User name for the Linux Virtual Machines.')param linuxAdminUsername string@description('Configure all linux machines with the SSH RSA public key string. Your key should include three parts, for example \'ssh-rsa AAAAB...snip...UcyupgH azureuser@linuxvm\'')
param sshRSAPublicKey stringresource aks 'Microsoft.ContainerService/managedClusters@2022-05-02-preview' = { name: clusterName location: location identity: { type: 'SystemAssigned' } properties: { dnsPrefix: dnsPrefix agentPoolProfiles: [ { name: 'agentpool' osDiskSizeGB: osDiskSizeGB count: agentCount vmSize: agentVMSize osType: 'Linux' mode: 'System' } ] linuxProfile: { adminUsername: linuxAdminUsername ssh: { publicKeys: [ { keyData: sshRSAPublicKey } ] } } }}output controlPlaneFQDN string = aks.properties.fqdn
Add the application definition:
Create a file named azure-vote.yaml in the same folder as main.bicep with the following YAML definition: