├── .gitignore
├── diagram.png
├── CHANGELOG.md
├── main.parameters.sample.json
├── CODE_OF_CONDUCT.md
├── .github
├── CODE_OF_CONDUCT.md
├── ISSUE_TEMPLATE.md
└── PULL_REQUEST_TEMPLATE.md
├── LICENSE.md
├── README.md
├── aci-availability-zones.sh
├── main.bicep
└── CONTRIBUTING.md
/.gitignore:
--------------------------------------------------------------------------------
1 | *.parameters.json
--------------------------------------------------------------------------------
/diagram.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Azure-Samples/aci-availability-zones/main/diagram.png
--------------------------------------------------------------------------------
/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | ## [project-title] Changelog
2 |
3 |
4 | # x.y.z (yyyy-mm-dd)
5 |
6 | *Features*
7 | * ...
8 |
9 | *Bug Fixes*
10 | * ...
11 |
12 | *Breaking Changes*
13 | * ...
14 |
--------------------------------------------------------------------------------
/main.parameters.sample.json:
--------------------------------------------------------------------------------
1 | {
2 | "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#",
3 | "contentVersion": "1.0.0.0",
4 | "parameters": {
5 | "containerGroupBaseName": {
6 | "value": "REPLACE WITH YOUR BASE NAME"
7 | },
8 | "trafficManagerName": {
9 | "value": "REPLACE WITH YOUR TRAFFIC MANAGER NAME"
10 | }
11 | }
12 | }
--------------------------------------------------------------------------------
/CODE_OF_CONDUCT.md:
--------------------------------------------------------------------------------
1 | # Microsoft Open Source Code of Conduct
2 |
3 | This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/).
4 |
5 | Resources:
6 |
7 | - [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/)
8 | - [Microsoft Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/)
9 | - Contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with questions or concerns
--------------------------------------------------------------------------------
/.github/CODE_OF_CONDUCT.md:
--------------------------------------------------------------------------------
1 | # Microsoft Open Source Code of Conduct
2 |
3 | This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/).
4 |
5 | Resources:
6 |
7 | - [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/)
8 | - [Microsoft Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/)
9 | - Contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with questions or concerns
10 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE.md:
--------------------------------------------------------------------------------
1 |
4 | > Please provide us with the following information:
5 | > ---------------------------------------------------------------
6 |
7 | ### This issue is for a: (mark with an `x`)
8 | ```
9 | - [ ] bug report -> please search issues before submitting
10 | - [ ] feature request
11 | - [ ] documentation issue or request
12 | - [ ] regression (a behavior that used to work and stopped in a new release)
13 | ```
14 |
15 | ### Minimal steps to reproduce
16 | >
17 |
18 | ### Any log messages given by the failure
19 | >
20 |
21 | ### Expected/desired behavior
22 | >
23 |
24 | ### OS and Version?
25 | > Windows 7, 8 or 10. Linux (which distribution). macOS (Yosemite? El Capitan? Sierra?)
26 |
27 | ### Versions
28 | >
29 |
30 | ### Mention any other details that might be useful
31 |
32 | > ---------------------------------------------------------------
33 | > Thanks! We'll be in touch soon.
34 |
--------------------------------------------------------------------------------
/.github/PULL_REQUEST_TEMPLATE.md:
--------------------------------------------------------------------------------
1 | ## Purpose
2 |
3 | * ...
4 |
5 | ## Does this introduce a breaking change?
6 |
7 | ```
8 | [ ] Yes
9 | [ ] No
10 | ```
11 |
12 | ## Pull Request Type
13 | What kind of change does this Pull Request introduce?
14 |
15 |
16 | ```
17 | [ ] Bugfix
18 | [ ] Feature
19 | [ ] Code style update (formatting, local variables)
20 | [ ] Refactoring (no functional changes, no api changes)
21 | [ ] Documentation content changes
22 | [ ] Other... Please describe:
23 | ```
24 |
25 | ## How to Test
26 | * Get the code
27 |
28 | ```
29 | git clone [repo-address]
30 | cd [repo-name]
31 | git checkout [branch-name]
32 | npm install
33 | ```
34 |
35 | * Test the code
36 |
37 | ```
38 | ```
39 |
40 | ## What to Check
41 | Verify that the following are valid
42 | * ...
43 |
44 | ## Other Information
45 |
--------------------------------------------------------------------------------
/LICENSE.md:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) Microsoft Corporation.
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # ACI Availability Zone (Preview)
2 |
3 | ## Deploy an Azure Container Instances (ACI) container group in an availability zone (preview)
4 |
5 | An availability zone is a physically separate zone in an Azure region. You can
6 | use availability zones to protect your containerized applications from an
7 | unlikely failure or loss of an entire data center. Azure Container Instances
8 | (ACI) supports zonal container group deployments, meaning the instance is pinned
9 | to a specific, self-selected availability zone. The availability zone is
10 | specified at the container group level. Containers within a container group
11 | cannot have unique availability zones. To change your container group's
12 | availability zone, you must delete the container group and create another
13 | container group with the new availability zone.
14 |
15 | ## Components
16 |
17 | 
18 |
19 | ## Prerequisites
20 |
21 | The following tools are required before using this example:
22 |
23 | - Azure CLI, version 2.30.0 or later
24 |
25 | Login to `az` and select your subscription (if necessary):
26 |
27 | ```sh
28 | az login
29 | az account set --subscription "YOUR_SUBSCRIPTION_ID"
30 | ```
31 |
32 | ## Deploy with Bicep
33 |
34 | First, copy the `main.parameters.sample.json` file to `main.parameters.json`.
35 | Then, update the values of `containerGroupBaseName` and `trafficManagerName` to
36 | something unique.
37 |
38 | Next, create the resource group that you will be deploying into:
39 |
40 | ```sh
41 | # Change location and resource-group to your preferred values
42 | az group create --location eastus --resource-group rg-your-resource-group-name
43 | ```
44 |
45 | Finally, deploy the bicep template with `az`:
46 |
47 | ```sh
48 | az deployment group create -n DeployingAciToMultipleAvailabilityZones --resource-group rg-your-resource-group-name --template-file main.bicep --parameters main.parameters.json
49 | ```
50 |
51 | Wait for the deployment to finish, then check the Azure Portal for the status of
52 | the resources.
53 |
54 | ## Deploy using Bash script
55 |
56 | Open a bash session and execute the following steps
57 |
58 | - Open the file `aci-availability-zones.sh` edit all the variables with your
59 | unique values.
60 | - Save and close.
61 |
62 | ```sh
63 | #Run the following command
64 | sh aci-availability-zones.sh
65 | ```
66 |
67 | Wait for the deployment to finish, then check the Azure Portal for the status of
68 | the resources.
69 |
70 | ## More Information
71 |
72 | For more information, see the following Microsoft Docs:
73 |
74 | - [Deploy an Azure Container Instances (ACI) container group in an availability zone (preview)](https://docs.microsoft.com/azure/container-instances/availability-zones)
75 |
--------------------------------------------------------------------------------
/aci-availability-zones.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | # Copyright (c) Microsoft Corporation.
4 | # Licensed under the MIT license.
5 |
6 | #
7 | # Route traffic for high availability of applications
8 |
9 | # Variables for Contrainer Intances Group and Traffic Manager resources
10 | resourceGroup="aci-az"
11 | location="eastus"
12 | container1="container-aci-az-1"
13 | container2="container-aci-az-2"
14 | dnsNameLabelZone1="aci-az-dns-eastuszone1"
15 | dnsNameLabelZone2="aci-az-dns-eastuszone2"
16 | trafficManagerProfile="traffic-manager-profile-aci-az"
17 | uniqueDnsName="uniqie-dns-name-aci-az"
18 |
19 | # Create a resource resourceGroupName
20 | echo "Creating Resource Group $resourceGroup in $location..."
21 | az group create \
22 | --name $resourceGroup \
23 | --location $location
24 |
25 | # Create the first Container group in availibility zone 1
26 | echo "Creating first Contrainer Group $container1 in $location in zone 1..."
27 | az container create \
28 | --resource-group $resourceGroup \
29 | --name $container1 \
30 | --image mcr.microsoft.com/azuredocs/aci-helloworld \
31 | --dns-name-label $dnsNameLabelZone1 \
32 | --location $location --zone 1
33 |
34 | # Create the first Container group in availibility zone 2
35 | echo "Creating first Contrainer Group $container2 in $location in zone 2..."
36 | az container create \
37 | --resource-group $resourceGroup \
38 | --name $container2 \
39 | --image mcr.microsoft.com/azuredocs/aci-helloworld \
40 | --dns-name-label $dnsNameLabelZone2 \
41 | --location $location --zone 2
42 |
43 |
44 | #Create an Azure Traffic Manager resource with endpoints for Zone 1 and Zone 2
45 | echo "Creating Azure Traffic Manager resource..."
46 | az network traffic-manager profile create\
47 | --resource-group $resourceGroup \
48 | --name $trafficManagerProfile \
49 | --routing-method Priority \
50 | --unique-dns-name $uniqueDnsName \
51 | --ttl 10 --interval 10 --max-failures 3 --timeout 5
52 |
53 | echo "Creating Azure Traffic Manager endpoint for $location Zone 1..."
54 | az network traffic-manager endpoint create \
55 | --resource-group $resourceGroup \
56 | --name zonalendpoint1 \
57 | --profile-name $trafficManagerProfile \
58 | --type externalEndpoints \
59 | --priority 1 \
60 | --target $dnsNameLabelZone1.$location.azurecontainer.io
61 |
62 | echo "Creating Azure Traffic Manager endpoint for $location Zone 2..."
63 | az network traffic-manager endpoint create \
64 | --resource-group $resourceGroup \
65 | --name zonalendpoint2 \
66 | --profile-name $trafficManagerProfile \
67 | --type externalEndpoints \
68 | --priority 2 \
69 | --target $dnsNameLabelZone2.$location.azurecontainer.io
70 | #
71 |
72 | # echo "Deleting all resources"
73 | # az group delete --name $resourceGroup -y
--------------------------------------------------------------------------------
/main.bicep:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation.
2 | // Licensed under the MIT license.
3 |
4 | // Parameters
5 | ////////////////////////////////////////////////////////////////////////////////
6 |
7 | @description('Location for all resources.')
8 | param location string = resourceGroup().location
9 |
10 | @description('The base name to be used for container groups.')
11 | param containerGroupBaseName string
12 |
13 | @description('The number of zones to deploy to (1-3).')
14 | @allowed([
15 | 1
16 | 2
17 | 3
18 | ])
19 | param containerGroupNumberOfZones int = 2
20 |
21 | @description('Container image to deploy. Should be of the form repoName/imagename:tag for images stored in public Docker Hub, or a fully qualified URI for other registries. Images from private registries require additional registry credentials.')
22 | param containerImage string = 'mcr.microsoft.com/azuredocs/aci-helloworld'
23 |
24 | @description('Port to open on the container and the public IP address.')
25 | param containerPort int = 80
26 |
27 | @description('The behavior of Azure runtime if container has stopped.')
28 | @allowed([
29 | 'Always'
30 | 'Never'
31 | 'OnFailure'
32 | ])
33 | param containerRestartPolicy string = 'Always'
34 |
35 | @description('The name to be used for traffic manager.')
36 | param trafficManagerName string
37 |
38 | // Resources
39 | ////////////////////////////////////////////////////////////////////////////////
40 |
41 | // Create the container group resources by looping through our config variable
42 | resource containerGroups 'Microsoft.ContainerInstance/containerGroups@2021-09-01' = [for i in range(1, containerGroupNumberOfZones): {
43 | name: '${containerGroupBaseName}-zone${i}'
44 | location: location
45 | zones: [
46 | string(i)
47 | ]
48 | properties: {
49 | containers: [
50 | {
51 | name: '${containerGroupBaseName}-zone${i}'
52 | properties: {
53 | image: containerImage
54 | ports: [
55 | {
56 | port: containerPort
57 | protocol: 'TCP'
58 | }
59 | ]
60 | resources: {
61 | requests: {
62 | cpu: 1
63 | memoryInGB: 2
64 | }
65 | }
66 | }
67 | }
68 | ]
69 | osType: 'Linux'
70 | restartPolicy: containerRestartPolicy
71 | ipAddress: {
72 | type: 'Public'
73 | dnsNameLabel: '${containerGroupBaseName}-zone${i}'
74 | ports: [
75 | {
76 | port: containerPort
77 | protocol: 'TCP'
78 | }
79 | ]
80 | }
81 | }
82 | }]
83 |
84 | // Create a traffic manager instance to route traffic to the container groups
85 | resource trafficManagerProfile 'Microsoft.Network/trafficManagerProfiles@2018-04-01' = {
86 | name: trafficManagerName
87 | location: 'global'
88 | properties: {
89 | profileStatus: 'Enabled'
90 | trafficRoutingMethod: 'Priority'
91 | dnsConfig: {
92 | relativeName: trafficManagerName
93 | ttl: 10
94 | }
95 | monitorConfig: {
96 | protocol: 'HTTP'
97 | port: 80
98 | path: '/'
99 | intervalInSeconds: 10
100 | toleratedNumberOfFailures: 3
101 | timeoutInSeconds: 5
102 | }
103 | endpoints: [for i in range(1, containerGroupNumberOfZones): {
104 | name: '${containerGroupBaseName}-zone${i}'
105 | type: 'Microsoft.Network/trafficManagerProfiles/externalEndpoints'
106 | properties: {
107 | target: containerGroups[i - 1].properties.ipAddress.fqdn
108 | priority: i
109 | }
110 | }]
111 | }
112 | }
113 |
--------------------------------------------------------------------------------
/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 | # Contributing to aci-availability-zones
2 |
3 | This project welcomes contributions and suggestions. Most contributions require you to agree to a
4 | Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us
5 | the rights to use your contribution. For details, visit https://cla.opensource.microsoft.com.
6 |
7 | When you submit a pull request, a CLA bot will automatically determine whether you need to provide
8 | a CLA and decorate the PR appropriately (e.g., status check, comment). Simply follow the instructions
9 | provided by the bot. You will only need to do this once across all repos using our CLA.
10 |
11 | This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/).
12 | For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or
13 | contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments.
14 |
15 | - [Code of Conduct](#coc)
16 | - [Issues and Bugs](#issue)
17 | - [Feature Requests](#feature)
18 | - [Submission Guidelines](#submit)
19 |
20 | ## Code of Conduct
21 | Help us keep this project open and inclusive. Please read and follow our [Code of Conduct](https://opensource.microsoft.com/codeofconduct/).
22 |
23 | ## Found an Issue?
24 | If you find a bug in the source code or a mistake in the documentation, you can help us by
25 | [submitting an issue](#submit-issue) to the GitHub Repository. Even better, you can
26 | [submit a Pull Request](#submit-pr) with a fix.
27 |
28 | ## Want a Feature?
29 | You can *request* a new feature by [submitting an issue](#submit-issue) to the GitHub
30 | Repository. If you would like to *implement* a new feature, please submit an issue with
31 | a proposal for your work first, to be sure that we can use it.
32 |
33 | * **Small Features** can be crafted and directly [submitted as a Pull Request](#submit-pr).
34 |
35 | ## Submission Guidelines
36 |
37 | ### Submitting an Issue
38 | Before you submit an issue, search the archive, maybe your question was already answered.
39 |
40 | If your issue appears to be a bug, and hasn't been reported, open a new issue.
41 | Help us to maximize the effort we can spend fixing issues and adding new
42 | features, by not reporting duplicate issues. Providing the following information will increase the
43 | chances of your issue being dealt with quickly:
44 |
45 | * **Overview of the Issue** - if an error is being thrown a non-minified stack trace helps
46 | * **Version** - what version is affected (e.g. 0.1.2)
47 | * **Motivation for or Use Case** - explain what are you trying to do and why the current behavior is a bug for you
48 | * **Browsers and Operating System** - is this a problem with all browsers?
49 | * **Reproduce the Error** - provide a live example or a unambiguous set of steps
50 | * **Related Issues** - has a similar issue been reported before?
51 | * **Suggest a Fix** - if you can't fix the bug yourself, perhaps you can point to what might be
52 | causing the problem (line of code or commit)
53 |
54 | You can file new issues by providing the above information at the corresponding repository's issues link: https://github.com/[organization-name]/[repository-name]/issues/new].
55 |
56 | ### Submitting a Pull Request (PR)
57 | Before you submit your Pull Request (PR) consider the following guidelines:
58 |
59 | * Search the repository (https://github.com/Azure-Samples/aci-availability-zones/pulls) for an open or closed PR
60 | that relates to your submission. You don't want to duplicate effort.
61 |
62 | * Make your changes in a new git fork:
63 |
64 | * Commit your changes using a descriptive commit message
65 | * Push your fork to GitHub:
66 | * In GitHub, create a pull request
67 | * If we suggest changes then:
68 | * Make the required updates.
69 | * Rebase your fork and force push to your GitHub repository (this will update your Pull Request):
70 |
71 | ```shell
72 | git rebase master -i
73 | git push -f
74 | ```
75 |
76 | That's it! Thank you for your contribution!
77 |
--------------------------------------------------------------------------------