Mapy konfigurace pro službu Azure Container Instances (Preview)
Článek 11/19/2024
1 přispěvatel
Váš názor
V tomto článku
Konfigurační mapa je vlastnost, kterou lze použít k použití konfigurací kontejnerů podobně jako proměnné prostředí a svazky tajných kódů. Na rozdíl od použití proměnných prostředí nebo tajných svazků, kde je vyžadováno restartování podu pro použití nastavení, ale použití nastavení pomocí konfigurační mapy nevyžaduje žádné restartování, aby se změny projevily.
Službu Azure Container Instances je možné vytvořit pomocí konfiguračních map nebo bez těchto map a je možné je aktualizovat v libovolném okamžiku po vytvoření pomocí konfiguračních map. Aktualizace konfiguračních map ve stávající spuštěné skupině kontejnerů se dá rychle provést bez ohrožení doby provozu kontejneru.
Jak to funguje
Konfigurační mapu lze zahrnout do vlastností kontejneru nebo do profilu skupiny kontejnerů. Vytvoření profilu skupiny kontejnerů pomocí nastavení mapy konfigurace usnadňuje a usnadňuje automatizaci těchto nastavení.
Vytvoření profilu skupiny kontejnerů s nastavením mapy konfigurace
Vytvořte profil skupiny kontejnerů s nastavením mapování konfigurace pomocí příkazu az container container-group-profile create .
az container container-group-profile create \
--resource-group myResourceGroup \
--name myContainerGroupProfile \
--location WestCentralUS \
--image nginx \
--os-type Linux \
--ip-address Public \
--ports 8000 \
--cpu 1 \
--memory 1.5 \
--restart-policy never \
--config-map key1=value1 key2=value2
Vytvořte profil skupiny kontejnerů s nastavením mapování konfigurace pomocí rutiny New-AzContainerInstanceContainerGroupProfile .
$port1 = New-AzContainerInstancePortObject -Port 8000 -Protocol TCP
$port2 = New-AzContainerInstancePortObject -Port 8001 -Protocol TCP
$container = New-AzContainerInstanceObject -Name myContainer -Image nginx -RequestCpu 1 -RequestMemoryInGb 1.5 -Port @($port1, $port2) -ConfigMapKeyValuePair @{"key1"="value1"}
New-AzContainerInstanceContainerGroupProfile `
-ResourceGroupName myResourceGroup `
-Name myContainerGroupProfile `
-Location WestCentralUS `
-Container $container `
-OsType Linux `
-RestartPolicy "Never" `
-IpAddressType Public
Vytvořte profil skupiny kontejnerů s nastavením mapování a nasaďte šablonu pomocí příkazu az deployment group create nebo New-AzResourceGroupDeployment .
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"resources": [
{
"type": "Microsoft.ContainerInstance/containerGroups",
"apiVersion": "2024-05-01-preview",
"name": "[parameters('profileName')]",
"location": "[parameters('location')]",
"properties": {
"containers": [
{
"name": "myContainer",
"properties": {
"image": "[parameters('containerImage')]",
"ports": [
{
"port": 8000
}
],
"resources": {
"requests": {
"cpu": 1,
"memoryInGB": 1.5
}
},
"command": [],
"configMap": {
"keyValuePairs": {
"key1": "value1",
"key2": "value2"
}
"environmentVariables": []
}
}
],
"osType": "Linux",
"ipAddress": {
"type": "Public",
"ports": [
{
"protocol": "TCP",
"port": 8000
}
]
},
"imageRegistryCredentials": [],
"sku": "Standard"
}
}
],
"parameters": {
"profileName": {
"type": "string",
"defaultValue": "myContainerGroupProfile",
"metadata": {
"description": "Name of the container profile"
}
},
"location": {
"type": "string",
"defaultValue": "West Central US",
"metadata": {
"description": "Location for the resource"
}
},
"containerImage": {
"type": "string",
"defaultValue": "mcr.microsoft.com/azuredocs/aci-helloworld:latest",
"metadata": {
"description": "The container image used"
}
}
}
}
Vytvořte profil skupiny kontejnerů s nastavením mapování konfigurace pomocí příkazu Vytvořit nebo Aktualizovat .
PUT https://management.azure.com/subscriptions/{SubscriptionID}/resourceGroups/myResourceGroup/providers/Microsoft.ContainerInstance/containerGroupProfiles/myContainerGroupProfile?api-version=2024-05-01-preview
Request Body
{
"location": "West Central US",
"properties":{
"containers": [
{
"name":"myContainerGroupProfile",
"properties": {
"command":[],
"configMap": {
"keyValuePairs": {
"key1": "value1",
"key2": "value2"
}
},
"environmentVariables":[],
"image":"mcr.microsoft.com/azuredocs/aci-helloworld:latest",
"ports":[
{
"port":8000
}
],
"resources": {
"requests": {
"cpu":1,
"memoryInGB":1.5
}
}
}
}
],
"imageRegistryCredentials":[],
"ipAddress":{
"ports":[
{
"protocol":"TCP",
"port":8000
}
],
"type":"Public"
},
"osType":"Linux",
"sku":"Standard"
}
}
Použití nastavení mapování konfigurace pomocí profilu skupiny kontejnerů
Použití nastavení mapování konfigurace uloženého v profilu skupiny kontejnerů vyžaduje aktualizaci kontejneru a zadání profilu skupiny kontejnerů, který by měl být přidružen k aktualizaci.
Pomocí příkazu az container create použijte nastavení mapování konfigurace uložené v profilu skupiny kontejnerů.
az container create
--resource-group myResourceGroup \
--name myContainer \
--location WestCentralUS \
--container-group-profile-id "/subscriptions/{SubscriptionID}/resourceGroups/myResourceGroup/providers/Microsoft.ContainerInstance/containerGroupProfiles/myContainerGroupProfile" \
--container-group-profile-revision 1
Použijte nastavení mapování konfigurace uložené v profilu skupiny kontejnerů pomocí rutiny New-AzContainerGroup .
$container = New-AzContainerInstancenoDefaultObject -Name myContainer
New-AzContainerGroup `
-ResourceGroupName myResourceGroup `
-Name myContainer`
-Container $container `
-Location WestCentralUS `
-ContainerGroupProfileId "/subscriptions/{SubscriptionID}/resourceGroups/myResourceGroup/providers/Microsoft.ContainerInstance/containerGroupProfiles/myContainerGroupProfile" `
-ContainerGroupProfileRevision 1
Použijte nastavení mapování konfigurace uložené v profilu skupiny kontejnerů pomocí příkazu az deployment group create nebo New-AzResourceGroupDeployment .
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"subscriptionId": {
"type": "string",
"metadata": {
"description": "The subscription ID."
}
},
"resourceGroup": {
"type": "string",
"metadata": {
"description": "The name of the resource group."
}
},
"location": {
"type": "string",
"metadata": {
"description": "Location for the resource."
},
"defaultValue": "West Central US"
},
"containerGroupName": {
"type": "string",
"metadata": {
"description": "The name of the container group."
}
},
},
"containerGroupProfileName": {
"type": "string",
"metadata": {
"description": "The name of the container group profile."
}
},
"newKey": {
"type": "string",
"metadata": {
"description": "The new key for the config map."
}
},
"newValue": {
"type": "string",
"metadata": {
"description": "The new value for the config map."
}
},
"revisionNumber": {
"type": "int",
"metadata": {
"description": "The revision number for the container group profile."
}
}
},
"resources": [
{
"type": "Microsoft.ContainerInstance/containerGroups",
"apiVersion": "2024-05-01-preview",
"name": "[parameters('containerGroupName')]",
"location": "[parameters('location')]",
"properties": {
"containerGroupProfile": {
"id": "[concat('/subscriptions/', parameters('subscriptionId'), '/resourceGroups/', parameters('resourceGroup'), '/providers/Microsoft.ContainerInstance/containerGroupProfiles/', parameters('containerGroupProfileName'))]",
"revision": "[parameters('revisionNumber')]"
},
"containers": [
{
"name": "[parameters('myContainerProfile')]",
"properties": {
"configMap": {
"keyValuePairs": {
"[parameters('newKey')]": "[parameters('newValue')]"
}
}
}
}
]
}
}
],
"outputs": {
"containerGroupId": {
"type": "string",
"value": "[resourceId('Microsoft.ContainerInstance/containerGroups', parameters('containerGroupName'))]"
}
}
}
Použijte nastavení mapování konfigurace uložené v profilu skupiny kontejnerů pomocí příkazu Vytvořit nebo Aktualizovat .
PUT
https://management.azure.com/subscriptions/{SubscriptionID}/resourceGroups/myResourceGroup/providers/Microsoft.ContainerInstance/containerGroups/myContainerGroup?api-version=2024-05-01-preview
Request Body
{
"location": "{location}",
"properties": {
"containerGroupProfile": {
"id": "/subscriptions/{subscriptionId}/resourceGroups/myResourceGroup/providers/Microsoft.ContainerInstance/containerGroupProfiles/myContainerGroupProfile",
"revision": {revisionNumber}
},
"containers": [
{
"name": "{myContainerGroupProfile}",
"properties": {
}
}
]
}
}
Použití nastavení mapování konfigurace bez profilu skupiny kontejnerů
Nastavení mapy konfigurace lze také použít přímo na instanci zadáním nastavení mapy konfigurace v příkazech create.
Použijte nastavení konfigurační mapy pomocí příkazu az container create .
az container create \
--resource-group myResourceGroup \
--name myContainer \
--location WestCentralUS \
--config-map key1=value1 key2=value2
Použijte nastavení mapy konfigurace pomocí New-AzContainerGrouop .
$container = New-AzContainerInstancenoDefaultObject -Name myContainer -ConfigMapKeyValuePair @{"key1"="value1"}
New-AzContainerGroup `
-ResourceGroupName myResourceGroup `
-Name myContainerGroup `
-Container $container `
-Location WestCentralUS
Použijte nastavení konfigurační mapy pomocí příkazu az deployment group create nebo New-AzResourceGroupDeployment .
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"subscriptionId": {
"type": "string",
"metadata": {
"description": "The subscription ID."
}
},
"resourceGroup": {
"type": "string",
"metadata": {
"description": "The name of the resource group."
}
},
"location": {
"type": "string",
"metadata": {
"description": "Location for the resource."
},
"defaultValue": "West Central US"
},
"containerGroupName": {
"type": "string",
"metadata": {
"description": "The name of the container group."
}
},
"myContainerProfile": {
"type": "string",
"metadata": {
"description": "The name of the container profile."
}
},
"newKey": {
"type": "string",
"metadata": {
"description": "The new key for the config map."
}
},
"newValue": {
"type": "string",
"metadata": {
"description": "The new value for the config map."
}
},
},
"resources": [
{
"type": "Microsoft.ContainerInstance/containerGroups",
"apiVersion": "2024-05-01-preview",
"name": "[parameters('containerGroupName')]",
"location": "[parameters('location')]",
"properties": {
"containers": [
{
"name": "[parameters('myContainerProfile')]",
"properties": {
"configMap": {
"keyValuePairs": {
"[parameters('newKey')]": "[parameters('newValue')]"
}
}
}
}
]
}
}
],
"outputs": {
"containerGroupId": {
"type": "string",
"value": "[resourceId('Microsoft.ContainerInstance/containerGroups', parameters('containerGroupName'))]"
}
}
}
Použijte nastavení mapy konfigurace pomocí příkazu Vytvořit nebo Aktualizovat .
PUT
https://management.azure.com/subscriptions/{SubscriptionID}/resourceGroups/myResourceGroup/providers/Microsoft.ContainerInstance/containerGroups/myContainerGroup?api-version=2024-05-01-preview
Request Body
{
"location": "{location}",
"properties": {
"containers": [
{
"name": "{myContainerGroupProfile}",
"properties": {
"configMap": {
"keyValuePairs": {
"{newKey}": "{newValue}"
}
}
}
}
]
}
}
Po instalaci aktualizace do existujícího kontejneru se zobrazí hodnoty připojené v kontejneru bez nutnosti restartování.
/mnt/configmap/<containername>/key1 with value as “value1”
/mnt/configmap/<containername>/key2 with value as “value2”
Další kroky
Zjistěte, jak pomocí konfiguračních map s pohotovostními fondy zvýšit škálování a dostupnost.