Udostępnij przez


Wdrażanie obciążeń z obsługą Arc w rozszerzonej strefie: PostgreSQL

W tym artykule dowiesz się, jak wdrożyć serwer PostgreSQL z obsługą usługi Arc w strefie rozszerzonej. Zapoznaj się z tematem Co to są strefy rozszerzone platformy Azure? | Usługi dla obecnie obsługiwanych obciążeń PaaS.

Wymagania wstępne

Uwaga / Notatka

Użyj zamierzonej lokalizacji rozszerzonej jako zmiennej lokalizacji.

Wprowadzenie

Jeśli znasz już temat, możesz pominąć ten akapit. Poniżej przedstawiono ważne tematy, które warto przeczytać przed kontynuowaniem tworzenia:

Tworzenie serwera PostgreSQL z obsługą usługi Azure Arc w strefach rozszerzonych

Po utworzeniu klastra usługi AKS z obsługą usługi Arc możemy przejść do użycia następującego skryptu programu PowerShell, aby utworzyć serwer PostgreSQL w klastrze usługi AKS w strefie rozszerzonej i połączyć go z platformą Kubernetes z włączoną usługą Azure Arc.

Uwaga / Notatka

Upewnij się, że parametry z Arc-enabled AKS są poprawnie przenoszone do skryptu.

. "./CreateArcEnabledAksOnEZ"

function CreatePostgreSqlOnArcEnabledAksEz {
    param(
        [string] $SubscriptionId,
        [string] $AKSClusterResourceGroupName,
        [string] $location = "westus",
        [string] $AKSName,
        [string] $edgeZone,
        [int] $nodeCount = 2,
        [string] $vmSize = "standard_nv12ads_a10_v5",
        [string] $ArcResourceGroupName,
        [string] $DataControllerName,
        [string] $CustomLocationName,
        [string] $Namespace,
        [string] $DataControllerConfigProfile,
        [string] $KeyVaultName,
        [string] $VaultSecretUser,
        [string] $VaultSecretPass,
        [string] $PostgreSqlName,
        [switch] $Debug
    )

    try {
        # Set the subscription
        az account set --subscription $SubscriptionId

        # Create the Arc-enabled EZ AKS cluster
        createArcEnabledAksOnEz -SubscriptionId $SubscriptionId -AKSClusterResourceGroupName $AKSClusterResourceGroupName -location $location -AKSName $AKSName -edgeZone $edgeZone -nodeCount $nodeCount -vmSize $vmSize -ArcResourceGroupName $ArcResourceGroupName -Debug:$Debug
        
        # Define name of the connected cluster resource
        $CLUSTER_NAME = "$ArcResourceGroupName-cluster"

        # Create a key vault and store login
        $AZDATA_USERNAME = az keyvault secret show --vault-name $KeyVaultName --name $VaultSecretUser --query value -o tsv
        $AZDATA_PASSWORD = az keyvault secret show --vault-name $KeyVaultName --name $VaultSecretPass --query value -o tsv
        
        # Define login for data controller and metrics
        $ENV:AZDATA_LOGSUI_USERNAME = $AZDATA_USERNAME
        $ENV:AZDATA_LOGSUI_PASSWORD = $AZDATA_PASSWORD
        $ENV:AZDATA_METRICSUI_USERNAME = $AZDATA_USERNAME
        $ENV:AZDATA_METRICSUI_PASSWORD = $AZDATA_PASSWORD

        $ENV:AZDATA_USERNAME = $AZDATA_USERNAME
        $ENV:AZDATA_PASSWORD = $AZDATA_PASSWORD

        # Define the connected cluster and extension for the custom location
        $CONNECTED_CLUSTER_ID=$(az connectedk8s show --resource-group $ArcResourceGroupName --name $CLUSTER_NAME --query id --output tsv)
        $EXTENSION_ID=$(az k8s-extension show `
        --cluster-type connectedClusters `
        --name 'my-data-controller-custom-location-ext' `
        --cluster-name $CLUSTER_NAME `
        --resource-group $ArcResourceGroupName `
        --query id `
        --output tsv)

        # Create a custom location for the data controller
        Write-Output "Creating data controller custom location..."
        az customlocation create `
        --resource-group $ArcResourceGroupName `
        --name $CustomLocationName `
        --host-resource-id $CONNECTED_CLUSTER_ID `
        --namespace $Namespace `
        --cluster-extension-ids $EXTENSION_ID

        # Create data controller on Arc-enabled AKS cluster
        Write-Output "Creating Arc Data Controller..."
        az arcdata dc create --name $DataControllerName --subscription $SubscriptionId --cluster-name $CLUSTER_NAME --resource-group $ArcResourceGroupName --connectivity-mode direct --custom-location $CustomLocationName --profile-name $DataControllerConfigProfile

        # Create PostgreSQL server on Arc-enabled AKS cluster
        Write-Output "Creating PostgreSQL server..."
        az postgres server-arc create --name $PostgreSqlName --k8s-namespace $Namespace --use-k8s
    }
    catch {
        # Catch any error
        Write-Error "An error occurred"
        Write-Error $Error[0]
    }

}

CreatePostgreSqlOnArcEnabledAksEz -SubscriptionId "<your subscription>" `
                        -AKSClusterResourceGroupName "my-aks-cluster-group" `
                        -location "westus" `
                        -AKSName "my-aks-cluster" `
                        -edgeZone "losangeles" `
                        -nodeCount 2 `
                        -vmSize "standard_nv12ad-DataControllerConfigProfiles_a10_v5" `
                        -ArcResourceGroupName "myArcResourceGroup" `
                        -DataControllerName "myDataController" `
                        -CustomLocationName "dc-custom-location" `
                        -Namespace "my-data-controller-custom-location" `
                        -DataControllerConfigProfile "azure-arc-aks-premium-storage" `
                        -KeyVaultName "ezDataControllerConfig" `
                        -VaultSecretUser "AZDATA-USERNAME" `
                        -VaultSecretPass "AZDATA-PASSWORD" `
                        -PostgreSqlName "my-postgresql"

Uprzątnij zasoby

Gdy grupa zasobów my-aks-cluster-group nie będzie już potrzebna, usuń ją i wszystkie zawarte w niej zasoby za pomocą polecenia az group delete .

az group delete --name my-aks-cluster-group