Obučavanje
Bicep Kubernetes extension (Preview)
The Kubernetes extension 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 manifest file.
Bilješka
The Kubernetes extension is not currently supported for private clusters:
resource AKS 'Microsoft.ContainerService/managedClusters@2024-02-01' = {
...
properties: {
apiServerAccessProfile: {
enablePrivateCluster: true
}
}
}
This preview feature can be enabled by configuring the bicepconfig.json:
{
"experimentalFeaturesEnabled": {
"extensibility": true
}
}
To safely pass secrets for the Kubernetes deployment, you must invoke the Kubernetes code with a Bicep module and pass the parameter as a secret. To import the Kubernetes extension, use the extension statement. After importing the extension, you can refactor the Bicep module file as usual, such as by using variables, parameters, and output. By contract, the Kubernetes manifest in YML doesn't include any programmability support.
The following sample imports the Kubernetes extension:
@secure()
param kubeConfig string
extension kubernetes with {
namespace: 'default'
kubeConfig: kubeConfig
} as k8s
- namespace: Specify the namespace of the extension.
- KubeConfig: Specify a base64 encoded value of the Kubernetes cluster admin credentials.
The following sample shows how to pass kubeConfig
value from a parent Bicep file:
resource aks 'Microsoft.ContainerService/managedClusters@2024-08-01' existing = {
name: 'demoAKSCluster'
}
module kubernetes './kubernetes.bicep' = {
name: 'buildbicep-deploy'
params: {
kubeConfig: aks.listClusterAdminCredential().kubeconfigs[0].value
}
}
The AKS cluster can be a new resource or an existing resource. The Import Kubernetes manifest
command from Visual Studio Code can automatically add the import snippet. For the details, see Import Kubernetes manifest command.
From Visual Studio Code, you can import Kubernetes manifest files to create Bicep module files. For more information, see Visual Studio Code.
- To walk through a quickstart, see Quickstart - Deploy Azure applications to Azure Kubernetes Services by using Bicep Kubernetes extension.
- To learn about how to use the Microsoft Graph extension, see Bicep templates for Microsoft Graph.
Dodatni resursi
Dokumentacija
-
Bicep modules - Azure Resource Manager
This article describes how to define a module in a Bicep file and how to use module scopes.
-
Parameters in Bicep files - Azure Resource Manager
Learn how to define and use parameters in a Bicep file.
-
Outputs in Bicep - Azure Resource Manager
Describes how to define output values in Bicep