Connect Crossplane to Microsoft Azure to create and manage cloud resources from Kubernetes with the Upbound Azure Provider.

This guide walks you through the steps required to get started with the Upbound Azure Provider. This includes installing Crossplane, configuring the provider to authenticate to Azure and creating a Managed Resource in Azure directly from your Kubernetes cluster.

Prerequisites

This quickstart requires:

  • a Kubernetes cluster with at least 3 GB of RAM
  • permissions to create pods and secrets in the Kubernetes cluster
  • [Helm] version v3.2.0 or later
  • an Azure account with permissions to create an Azure service principal and an Azure Resource Group
Tip
If you don’t have a Kubernetes cluster create one locally with minikube or kind.
Tip
All commands use the current kubeconfig context and configuration.

Install the Azure provider

Install the provider into the Kubernetes cluster with a Kubernetes configuration file.

1cat <<EOF | kubectl apply -f -
2apiVersion: pkg.crossplane.io/v1
3kind: Provider
4metadata:
5  name: upbound-provider-azure
6spec:
7  package: xpkg.upbound.io/upbound/provider-azure:v0.29.0
8EOF

The kind: Provider uses the Crossplane Provider Custom Resource Definition to connect your Kubernetes cluster to your cloud provider.

Verify the provider installed with kubectl get providers.

Tip
It may take up to five minutes for the provider to list HEALTHY as True.
1kubectl get providers 
2NAME                     INSTALLED   HEALTHY   PACKAGE                                          AGE
3upbound-provider-azure   True        True      xpkg.upbound.io/upbound/provider-azure:v0.29.0   3m3s

A provider installs their own Kubernetes Custom Resource Definitions (CRDs). These CRDs allow you to create Azure resources directly inside Kubernetes.

You can view the new CRDs with kubectl get crds. Every CRD maps to a unique Azure service Crossplane can provision and manage.

Tip
All the supported CRDs are also available in the Upbound Marketplace.

Create a Kubernetes secret for Azure

The provider requires credentials to create and manage Azure resources. Providers use a Kubernetes Secret to connect the credentials to the provider.

Tip
Other authentication methods exist and are beyond the scope of this guide. The Provider documentation contains information on alternative authentication methods.

First generate a Kubernetes Secret from your Azure JSON file and then configure the Provider to use it.

Install the Azure command-line

Generating an authentication file requires the Azure command-line.
Follow the documentation from Microsoft to Download and install the Azure command-line.

Log in to the Azure command-line.

az login

Create an Azure service principal

Follow the Azure documentation to find your Subscription ID from the Azure Portal.

Using the Azure command-line and provide your Subscription ID create a service principal and authentication file.

1az ad sp create-for-rbac \
2--sdk-auth \
3--role Owner \
4--scopes /subscriptions/<Subscription ID> 

Save your Azure JSON output as azure-credentials.json.

Tip
The Configuration section of the Provider documentation describes other authentication methods.

Create a Kubernetes secret with the Azure credentials

A Kubernetes generic secret has a name and contents. Use kubectl create secret to generate the secret object named azure-secret in the crossplane-system namespace.

Use the --from-file= argument to set the value to the contents of the azure-credentials.json file.

1kubectl create secret \
2generic azure-secret \
3-n crossplane-system \
4--from-file=creds=./azure-credentials.json

View the secret with kubectl describe secret

Tip
The size may be larger if there are extra blank spaces in your text file.
 1kubectl describe secret azure-secret -n crossplane-system
 2Name:         azure-secret
 3Namespace:    crossplane-system
 4Labels:       <none>
 5Annotations:  <none>
 6
 7Type:  Opaque
 8
 9Data
10====
11creds:  629 bytes

Create a ProviderConfig

A ProviderConfig customizes the settings of the Azure Provider.

Apply the ProviderConfig with the command:

 1cat <<EOF | kubectl apply -f -
 2apiVersion: azure.upbound.io/v1beta1
 3metadata:
 4  name: default
 5kind: ProviderConfig
 6spec:
 7  credentials:
 8    source: Secret
 9    secretRef:
10      namespace: crossplane-system
11      name: azure-secret
12      key: creds
13EOF

This attaches the Azure credentials, saved as a Kubernetes secret, as a secretRef .

The spec.credentials.secretRef.name value is the name of the Kubernetes secret containing the Azure credentials in the spec.credentials.secretRef.namespace .

Create a managed resource

A managed resource is anything Crossplane creates and manages outside of the Kubernetes cluster. This creates an Azure Resource group with Crossplane. The Resource group is a managed resource.

Tip
A resource group is one of the fastest Azure resources to provision.
 1cat <<EOF | kubectl apply -f -
 2apiVersion: azure.upbound.io/v1beta1
 3kind: ResourceGroup
 4metadata:
 5  name: example-rg
 6spec:
 7  forProvider:
 8    location: "East US"
 9  providerConfigRef:
10    name: default
11EOF

Notice the apiVersion and kind are from the Provider's CRDs.

The metadata.name value is the name of the created resource group in Azure.
This example uses the name example-rg.

The spec.forProvider.location tells Azure which Azure region to use when deploying resources. The region can be any Azure geography code.

Use kubectl get resourcegroup to verify Crossplane created the resource group.

1kubectl get ResourceGroup
2NAME         READY   SYNCED   EXTERNAL-NAME   AGE
3example-rg   True    True     example-rg      4m58s

Delete the managed resource

Before shutting down your Kubernetes cluster, delete the resource group just created.

Use kubectl delete resource-group to remove the bucket.

1kubectl delete resourcegroup example-rg
2resourcegroup.azure.upbound.io "example-rg" deleted

Next steps