sigs.k8s.io/cluster-api-provider-azure@v1.14.3/docs/book/src/topics/custom-vm-extensions.md (about) 1 # Custom VM Extensions 2 3 ## Overview 4 CAPZ allows you to specify custom extensions for your Azure resources. This is useful for running custom scripts or installing custom software on your machines. You can specify custom extensions for the following resources: 5 - AzureMachine 6 - AzureMachinePool 7 8 ## Discovering available extensions 9 The user is responsible for ensuring that the custom extension is compatible with the underlying image. Many VM extensions are available for use with Azure VMs. To see a complete list, use the Azure CLI command `az vm extension image list`. 10 11 ```bash 12 $ az vm extension image list --location westus --output table 13 ``` 14 15 ## Warning 16 VM extensions are specific to the operating system of the VM. For example, a Linux extension will not work on a Windows VM and vice versa. See the Azure documentation for more information. 17 - [Virtual machine extensions and features for Linux](https://learn.microsoft.com/en-us/azure/virtual-machines/extensions/features-linux?tabs=azure-cli) 18 - [Virtual machine extensions and features for Windows](https://learn.microsoft.com/en-us/azure/virtual-machines/extensions/features-windows?tabs=azure-cli) 19 20 ## Custom extensions for AzureMachine 21 To specify custom extensions for AzureMachines, you can add them to the `spec.template.spec.vmExtensions` field of your `AzureMachineTemplate`. The following fields are available: 22 - `name` (required): The name of the extension. 23 - `publisher` (required): The name of the extension publisher. 24 - `version` (required): The version of the extension. 25 - `settings` (optional): A set of key-value pairs containing settings for the extension. 26 - `protectedSettings` (optional): A set of key-value pairs containing protected settings for the extension. The information in this field is encrypted and decrypted only on the VM itself. 27 28 For example, the following `AzureMachineTemplate` spec specifies a custom extension that installs the `CustomScript` extension on the machine: 29 30 ```yaml 31 apiVersion: infrastructure.cluster.x-k8s.io/v1beta1 32 kind: AzureMachineTemplate 33 metadata: 34 name: test-machine-template 35 namespace: default 36 spec: 37 template: 38 spec: 39 vmExtensions: 40 - name: CustomScript 41 publisher: Microsoft.Azure.Extensions 42 version: '2.1' 43 settings: 44 fileUris: https://raw.githubusercontent.com/me/project/hello.sh 45 protectedSettings: 46 commandToExecute: ./hello.sh 47 ``` 48 49 ## Custom extensions for AzureMachinePool 50 Similarly, to specify custom extensions for AzureMachinePools, you can add them to the `spec.template.vmExtensions` field of your `AzureMachinePool`. For example, the following `AzureMachinePool` spec specifies a custom extension that installs the `CustomScript` extension on the machine: 51 52 ```yaml 53 apiVersion: infrastructure.cluster.x-k8s.io/v1beta1 54 kind: AzureMachinePool 55 metadata: 56 name: test-machine-pool 57 namespace: default 58 spec: 59 template: 60 vmExtensions: 61 - name: CustomScript 62 publisher: Microsoft.Azure.Extensions 63 version: '2.1' 64 settings: 65 fileUris: https://raw.githubusercontent.com/me/project/hello.sh 66 protectedSettings: 67 commandToExecute: ./hello.sh 68 ```