Bicep extensibility Kubernetes provider (Preview)

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 manifest file.

Note

Kubernetes provider is not currently supported for private clusters:

resource AKS 'Microsoft.ContainerService/managedClusters@2023-01-02-preview' = {
 ...
 properties: {
  apiServerAccessProfile: {
    enablePrivateCluster: true
  }
 }
}

Enable the preview feature

This preview feature can be enabled by configuring the bicepconfig.json:

{
  "experimentalFeaturesEnabled": {
    "extensibility": true
  }
}

Import Kubernetes provider

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 provider, use the import statement. After importing the provider, 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 provider:

@secure()
param kubeConfig string

import 'kubernetes@1.0.0' with {
  namespace: 'default'
  kubeConfig: kubeConfig
} as k8s

The following sample shows how to pass kubeConfig value from a parent Bicep file:

resource aks 'Microsoft.ContainerService/managedClusters@2022-05-02-preview' 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.

Visual Studio Code import

From Visual Studio Code, you can import Kubernetes manifest files to create Bicep module files. For more information, see Visual Studio Code.

Next steps