|
| 1 | +--- |
| 2 | +title: Relocate an Azure Container Registry to another region |
| 3 | +description: This article shows you how to relocate an Azure Container Registry to another region. |
| 4 | +ms.topic: concept |
| 5 | +ms.custom: devx-track-azurecli |
| 6 | +author: anaharris-ms |
| 7 | +ms.author: anaharris |
| 8 | +ms.date: 07/29/2024 |
| 9 | +ms.service: container-registry |
| 10 | +--- |
| 11 | + |
| 12 | +# Relocate an Azure Container Registry to another region |
| 13 | + |
| 14 | +This article shows you how to relocate Azure Container Registry resources to another region in the same subscription of the Active Directory tenant. |
| 15 | + |
| 16 | +[!INCLUDE [container-registry-geo-replication-include](../../includes/container-registry-geo-replication-include.md)] |
| 17 | + |
| 18 | +## Prerequisites |
| 19 | + |
| 20 | + |
| 21 | +- You can only relocate a registry within the same Active Directory tenant. This limitation applies to registries that are encrypted and unencrypted with a [customer-managed key](../container-registry/tutorial-enable-customer-managed-keys.md). |
| 22 | + |
| 23 | +- If the source registry has [availability zones](../reliability/availability-zones-overview.md) enabled, then the target region must also support availability zones. For more information on availability zone support for Azure Container Registry, see [Enable zone redundancy in Azure Container Registry](../container-registry/zone-redundancy.md). |
| 24 | + |
| 25 | + |
| 26 | + |
| 27 | +## Considerations for Service Endpoints |
| 28 | + |
| 29 | +The virtual network service endpoints for Azure Container Registry restrict access to a specified virtual network. The endpoints can also restrict access to a list of IPv4 (internet protocol version 4) address ranges. Any user connecting to the registry from outside those sources is denied access. If Service endpoints were configured in the source region for the registry resource, the same would need to be done in the target one. The steps for this scenario are mentioned below: |
| 30 | + |
| 31 | +- For a successful recreation of the registry to the target region, the VNet and Subnet must be created beforehand. If the move of these two resources is being carried out with the Azure Resource Mover tool, the service endpoints won’t be configured automatically and so you'll need to provide manual configuration. |
| 32 | + |
| 33 | +- Secondly, changes need to be made in the IaC of the Azure Container Registry. In `networkAcl` section, under `virtualNetworkRules`, add the rule for the target subnet. Ensure that the `ignoreMissingVnetServiceEndpoint` flag is set to False, so that the IaC fails to deploy the Azure Container Registry in case the service endpoint isn’t configured in the target region. This will ensure that the prerequisites in the target region are met |
| 34 | + |
| 35 | + |
| 36 | +[!INCLUDE [considerations-for-private-endpoint](includes/private-endpoint-include.md)] |
| 37 | + |
| 38 | + |
| 39 | +- Azure Container Registry must be configured in the target region with premium tier. |
| 40 | + |
| 41 | +- When public network access to a registry is disabled, registry access by certain trusted services - including Azure Security Center - requires enabling a network setting to bypass the network rules. |
| 42 | + |
| 43 | +- If the registry has an approved private endpoint and public network access is disabled, repositories and tags can’t be listed outside the virtual network using the Azure portal, Azure CLI, or other tools. |
| 44 | + |
| 45 | +- In case the case of a new replica, its imperative to manually add a new DNS record for the data endpoint in the target region. |
| 46 | + |
| 47 | +## Downtime |
| 48 | + |
| 49 | +To understand the possible downtimes involved, see [Cloud Adoption Framework for Azure: Select a relocation method](/azure/cloud-adoption-framework/relocate/select#select-a-relocation-method). |
| 50 | + |
| 51 | + |
| 52 | + |
| 53 | +## Prepare |
| 54 | + |
| 55 | +>[!NOTE] |
| 56 | +>If you only want to relocate a Container Registry that doesn't hold any client specific data and is to be moved alone, you can simply redeploy the registry by using [Bicep](/azure/templates/microsoft.containerregistry/registries?tabs=bicep&pivots=deployment-language-arm-template) or [JSON](/azure/templates/microsoft.containerregistry/registries?tabs=json&pivots=deployment-language-arm-template). |
| 57 | +> |
| 58 | +>To view other availability configuration templates, go to [Define resources with Bicep, ARM templates, and Terraform AzAPI provider](/azure/templates/) |
| 59 | +
|
| 60 | +**To prepare for relocation with data migration:** |
| 61 | + |
| 62 | +1. Create a dependency map with all the Azure services used by the registry. For the services that are in scope of the relocation, you must choose the appropriate relocation strategy. |
| 63 | + |
| 64 | +1. Identify the source networking layout for Azure Container Registry (ACR) like firewall and network isolation. |
| 65 | + |
| 66 | +1. Retrieve any required images from the source registry for import into the target registry. To retrieve the images, run the following command: |
| 67 | + |
| 68 | +```azurecli |
| 69 | +
|
| 70 | +Get-AzContainerRegistryRepository -RegistryName registry |
| 71 | +
|
| 72 | +``` |
| 73 | + |
| 74 | +1. Use [ACR Tasks](../container-registry/container-registry-tasks-overview.md) to retrieve automation configurations of the source registry for import into the target registry. |
| 75 | + |
| 76 | + |
| 77 | +### Export template |
| 78 | + |
| 79 | +To get started, export a Resource Manager template. This template contains settings that describe your Container Registry. For more information on how to use exported templates, see [Use exported template from the Azure portal](../azure-resource-manager/templates/template-tutorial-Azure portale.md) and the [template reference](/azure/templates/microsoft.containerregistry/registries). |
| 80 | + |
| 81 | + |
| 82 | +1. In the [Azure portal](https://portal.azure.com), navigate to your source registry. |
| 83 | +1. In the menu, under **Automation**, select **Export template** > **Download**. |
| 84 | + |
| 85 | + :::image type="content" source="media/relocation/container-registry/export-template.png" alt-text="Export template for container registry"::: |
| 86 | + |
| 87 | +1. Locate the .zip file that you downloaded from the portal, and unzip that file to a folder of your choice. |
| 88 | + |
| 89 | + This zip file contains the .json files that include the template and scripts to deploy the template. |
| 90 | + |
| 91 | + |
| 92 | +### Modify template |
| 93 | + |
| 94 | +Inspect the registry properties in the template JSON file you downloaded, and make necessary changes. At a minimum: |
| 95 | + |
| 96 | +- Change the registry name's `defaultValue` to the desired name of the target registry |
| 97 | +- Update the `location` to the desired Azure region for the target registry |
| 98 | + |
| 99 | +```json |
| 100 | +{ |
| 101 | + "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#", |
| 102 | + "contentVersion": "1.0.0.0", |
| 103 | + "parameters": { |
| 104 | + "registries_myregistry_name": { |
| 105 | + "defaultValue": "myregistry", |
| 106 | + "type": "String" |
| 107 | + } |
| 108 | + }, |
| 109 | + "variables": {}, |
| 110 | + "resources": [ |
| 111 | + { |
| 112 | + "type": "Microsoft.ContainerRegistry/registries", |
| 113 | + "apiVersion": "2020-11-01-preview", |
| 114 | + "name": "[parameters('myregistry_name')]", |
| 115 | + "location": "centralus", |
| 116 | + ... |
| 117 | + } |
| 118 | + ] |
| 119 | +} |
| 120 | +``` |
| 121 | + |
| 122 | +- Validate all the associated resources detail in the downloaded template such as Registry scopeMaps, replications configuration, Diagnostic settings like log analytics. |
| 123 | + |
| 124 | +- If the source registry is encrypted, then [encrypt the target registry using a customer-managed key](../container-registry/tutorial-enable-customer-managed-keys.md#enable-a-customer-managed-key-by-using-a-resource-manager-template) and update the template with settings for the required managed identity, key vault, and key. You can only enable the customer-managed key when you deploy the registry. |
| 125 | + |
| 126 | + |
| 127 | + |
| 128 | +### Create resource group |
| 129 | + |
| 130 | +Create a resource group for the target registry using the [az group create](/cli/azure/group#az-group-create). The following example creates a resource group named *myResourceGroup* in the *eastus* location. |
| 131 | + |
| 132 | +```azurecli |
| 133 | +az group create --name myResourceGroup --location eastus |
| 134 | +``` |
| 135 | + |
| 136 | +## Redeploy |
| 137 | + |
| 138 | +Use the [az deployment group create](/cli/azure/deployment/group#az-deployment-group-create) command to deploy the target registry, using the template: |
| 139 | + |
| 140 | +```azurecli |
| 141 | +az deployment group create --resource-group myResourceGroup \ |
| 142 | + --template-file template.json --name mydeployment |
| 143 | +``` |
| 144 | + |
| 145 | +> [!NOTE] |
| 146 | +> If you see errors during deployment, you might need to update certain configurations in the template file and retry the command. |
| 147 | +
|
| 148 | +### Import registry content in target registry |
| 149 | + |
| 150 | +After creating the registry in the target region: |
| 151 | + |
| 152 | +1. Use the [az acr import](/cli/azure/acr#az-acr-import) command, or the equivalent PowerShell command `Import-AzContainerImage`, to import images and other artifacts you want to preserve from the source registry to the target registry. For command examples, see [Import container images to a container registry](../container-registry/container-registry-import-images.md). |
| 153 | + |
| 154 | +1. Use the Azure CLI commands [az acr repository list](/cli/azure/acr/repository#az-acr-repository-list) and [az acr repository show-tags](/cli/azure/acr/repository#az-acr-repository-show-tags), or Azure PowerShell equivalents, to help enumerate the contents of your source registry. |
| 155 | + |
| 156 | +1. Run the import command for individual artifacts, or script it to run over a list of artifacts. |
| 157 | + |
| 158 | +The following sample Azure CLI script enumerates the source repositories and tags and then imports the artifacts to a target registry in the same Azure subscription. Modify as needed to import specific repositories or tags. To import from a registry in a different subscription or tenant, see examples in [Import container images to a container registry](../container-registry/container-registry-import-images.md). |
| 159 | + |
| 160 | +```azurecli |
| 161 | +#!/bin/bash |
| 162 | +# Modify registry names for your environment |
| 163 | +SOURCE_REG=myregistry |
| 164 | +TARGET_REG=targetregistry |
| 165 | +
|
| 166 | +# Get list of source repositories |
| 167 | +REPO_LIST=$(az acr repository list \ |
| 168 | + --name $SOURCE_REG --output tsv) |
| 169 | +
|
| 170 | +# Enumerate tags and import to target registry |
| 171 | +for repo in $REPO_LIST; do |
| 172 | + TAGS_LIST=$(az acr repository show-tags --name $SOURCE_REG --repository $repo --output tsv); |
| 173 | + for tag in $TAGS_LIST; do |
| 174 | + echo "Importing $repo:$tag"; |
| 175 | + az acr import --name $TARGET_REG --source $SOURCE_REG.azurecr.io/$repo":"$tag; |
| 176 | + done |
| 177 | +done |
| 178 | +``` |
| 179 | +1. Associate the dependent resources to the target Azure Container Registry such as log analytics workspace in Diagnostic settings. |
| 180 | + |
| 181 | +1. Configure Azure Container Registry integration with both type of AKS clusters, provisioned or yet to be provisioned by running the following command: |
| 182 | + |
| 183 | + |
| 184 | +```azurecli |
| 185 | +
|
| 186 | +Set-AzAksCluster -Name myAKSCluster -ResourceGroupName myResourceGroup -AcrNameToAttach <acr-name> |
| 187 | +
|
| 188 | +``` |
| 189 | + |
| 190 | +1. Make the necessary changes to the Kubernetes manifest file to integrate same with relocated Azure Container Registry (ACR). |
| 191 | + |
| 192 | +1. Update development and deployment systems to use the target registry instead of the source registry. |
| 193 | + |
| 194 | +1. Update any client firewall rules to allow access to the target registry. |
| 195 | + |
| 196 | + |
| 197 | +## Verify |
| 198 | + |
| 199 | +Confirm the following information in your target registry: |
| 200 | + |
| 201 | +* Registry settings such as the registry name, service tier, public access, and replications |
| 202 | +* Repositories and tags for content that you want to preserve. |
| 203 | + |
| 204 | + |
| 205 | +## Delete original registry |
| 206 | + |
| 207 | +After you have successfully deployed the target registry, migrated content, and verified registry settings, you may delete the source registry. |
| 208 | + |
| 209 | +## Related content |
| 210 | + |
| 211 | +- To move registry resources to a new resource group either in the same subscription or a [new subscription], see [Move Azure resources to a new resource group or subscription](../azure-resource-manager/management/move-resource-group-and-subscription.md). |
| 212 | + |
| 213 | + |
| 214 | +* Learn more about [importing container images](../container-registry/container-registry-import-images.md) to an Azure container registry from a public registry or another private registry. |
| 215 | + |
| 216 | +* See the [Resource Manager template reference](/azure/templates/microsoft.containerregistry/registries) for Azure Container Registry. |
0 commit comments