Skip to content

Commit 4c93798

Browse files
committed
update second article
1 parent 01cfcf5 commit 4c93798

File tree

1 file changed

+33
-140
lines changed

1 file changed

+33
-140
lines changed

articles/container-instances/container-instances-egress-ip-address.md

Lines changed: 33 additions & 140 deletions
Original file line numberDiff line numberDiff line change
@@ -11,127 +11,77 @@ Setting up a [container group](container-instances-container-groups.md) with an
1111

1212
This article provides steps to configure a container group in a [virtual network](container-instances-virtual-network-concepts.md) integrated with [Azure Firewall](../firewall/overview.md). By setting up a user-defined route to the container group and firewall rules, you can route and identify traffic to and from the container group. Container group ingress and egress use the public IP address of the firewall. A single egress IP address can be used by multiple container groups deployed in the virtual network's subnet delegated to Azure Container Instances.
1313

14-
In this article you use the Azure CLI to create the resources for this scenario:
14+
In this article, you use the Azure CLI to create the resources for this scenario:
1515

16-
* Container groups deployed on a delegated subnet [in the virtual network](container-instances-vnet.md)
16+
* Container groups deployed on a delegated subnet [in the virtual network](container-instances-vnet.md)
1717
* An Azure firewall deployed in the network with a static public IP address
1818
* A user-defined route on the container groups' subnet
1919
* A NAT rule for firewall ingress and an application rule for egress
2020

2121
You then validate ingress and egress from example container groups through the firewall.
2222

23-
## Deploy ACI in a virtual network
23+
[!INCLUDE [quickstarts-free-trial-note](../../includes/quickstarts-free-trial-note.md)]
2424

25-
In a typical case, you might already have an Azure virtual network in which to deploy a container group. For demonstration purposes, the following commands create a virtual network and subnet when the container group is created. The subnet is delegated to Azure Container Instances.
25+
[!INCLUDE [azure-cli-prepare-your-environment.md](../../includes/azure-cli-prepare-your-environment.md)]
2626

27-
The container group runs a small web app from the `aci-helloworld` image. As shown in other articles in the documentation, this image packages a small web app written in Node.js that serves a static HTML page.
27+
[!INCLUDE [cli-launch-cloud-shell-sign-in.md](../../includes/cli-launch-cloud-shell-sign-in.md)]
2828

29-
If you need one, first create an Azure resource group with the [az group create][az-group-create] command. For example:
29+
## Get started
3030

31-
```azurecli
32-
az group create --name myResourceGroup --location eastus
33-
```
31+
This tutorial makes use of a randomized variable. If you are using an existing resource group, modify the value of this variable appropriately.
3432

35-
To simplify the following command examples, use an environment variable for the resource group's name:
33+
:::code language="azurecli" source="~/azure_cli_scripts/container-instances/egress-ip-address.sh" id="variable":::
3634

37-
```console
38-
export RESOURCE_GROUP_NAME=myResourceGroup
39-
```
35+
**Azure resource group**: If you don't have an Azure resource group already, create a resource group with the [az group create][az-group-create] command. Modify the location value as appropriate.
36+
37+
:::code language="azurecli" source="~/azure_cli_scripts/container-instances/egress-ip-address.sh" id="creategroup":::
38+
39+
## Deploy ACI in a virtual network
40+
41+
In a typical case, you might already have an Azure virtual network in which to deploy a container group. For demonstration purposes, the following commands create a virtual network and subnet when the container group is created. The subnet is delegated to Azure Container Instances.
42+
43+
The container group runs a small web app from the `aci-helloworld` image. As shown in other articles in the documentation, this image packages a small web app written in Node.js that serves a static HTML page.
4044

4145
Create the container group with the [az container create][az-container-create] command:
4246

43-
```azurecli
44-
az container create \
45-
--name appcontainer \
46-
--resource-group $RESOURCE_GROUP_NAME \
47-
--image mcr.microsoft.com/azuredocs/aci-helloworld \
48-
--vnet aci-vnet \
49-
--vnet-address-prefix 10.0.0.0/16 \
50-
--subnet aci-subnet \
51-
--subnet-address-prefix 10.0.0.0/24
52-
```
47+
:::code language="azurecli" source="~/azure_cli_scripts/container-instances/egress-ip-address.sh" id="container":::
5348

5449
> [!TIP]
5550
> Adjust the value of `--subnet address-prefix` for the IP address space you need in your subnet. The smallest supported subnet is /29, which provides eight IP addresses. Some IP addresses are reserved for use by Azure.
5651
5752
For use in a later step, get the private IP address of the container group by running the [az container show][az-container-show] command:
5853

59-
```azurecli
60-
ACI_PRIVATE_IP="$(az container show --name appcontainer \
61-
--resource-group $RESOURCE_GROUP_NAME \
62-
--query ipAddress.ip --output tsv)"
63-
```
54+
:::code language="azurecli" source="~/azure_cli_scripts/container-instances/egress-ip-address.sh" id="privateip":::
6455

6556
## Deploy Azure Firewall in network
6657

6758
In the following sections, use the Azure CLI to deploy an Azure firewall in the virtual network. For background, see [Tutorial: Deploy and configure Azure Firewall using the Azure portal](../firewall/deploy-cli.md).
6859

6960
First, use the [az network vnet subnet create][az-network-vnet-subnet-create] to add a subnet named AzureFirewallSubnet for the firewall. AzureFirewallSubnet is the *required* name of this subnet.
7061

71-
```azurecli
72-
az network vnet subnet create \
73-
--name AzureFirewallSubnet \
74-
--resource-group $RESOURCE_GROUP_NAME \
75-
--vnet-name aci-vnet \
76-
--address-prefix 10.0.1.0/26
77-
```
62+
:::code language="azurecli" source="~/azure_cli_scripts/container-instances/egress-ip-address.sh" id="subnet":::
7863

7964
Use the following [Azure CLI commands](../firewall/deploy-cli.md) to create a firewall in the subnet.
8065

8166
If not already installed, add the firewall extension to the Azure CLI using the [az extension add][az-extension-add] command:
8267

83-
```azurecli
84-
az extension add --name azure-firewall
85-
```
68+
:::code language="azurecli" source="~/azure_cli_scripts/container-instances/egress-ip-address.sh" id="firewallext":::
8669

8770
Create the firewall resources:
8871

89-
```azurecli
90-
az network firewall create \
91-
--name myFirewall \
92-
--resource-group $RESOURCE_GROUP_NAME \
93-
--location eastus
94-
95-
az network public-ip create \
96-
--name fw-pip \
97-
--resource-group $RESOURCE_GROUP_NAME \
98-
--location eastus \
99-
--allocation-method static \
100-
--sku standard
101-
102-
az network firewall ip-config create \
103-
--firewall-name myFirewall \
104-
--name FW-config \
105-
--public-ip-address fw-pip \
106-
--resource-group $RESOURCE_GROUP_NAME \
107-
--vnet-name aci-vnet
108-
```
72+
:::code language="azurecli" source="~/azure_cli_scripts/container-instances/egress-ip-address.sh" id="firewallext":::
10973

11074
Update the firewall configuration using the [az network firewall update][az-network-firewall-update] command:
11175

112-
```azurecli
113-
az network firewall update \
114-
--name myFirewall \
115-
--resource-group $RESOURCE_GROUP_NAME
116-
```
76+
:::code language="azurecli" source="~/azure_cli_scripts/container-instances/egress-ip-address.sh" id="firewallupdate":::
11777

11878
Get the firewall's private IP address using the [az network firewall ip-config list][az-network-firewall-ip-config-list] command. This private IP address is used in a later command.
11979

80+
:::code language="azurecli" source="~/azure_cli_scripts/container-instances/egress-ip-address.sh" id="storeprivateip":::
12081

121-
```azurecli
122-
FW_PRIVATE_IP="$(az network firewall ip-config list \
123-
--resource-group $RESOURCE_GROUP_NAME \
124-
--firewall-name myFirewall \
125-
--query "[].privateIpAddress" --output tsv)"
126-
```
12782
Get the firewall's public IP address using the [az network public-ip show][az-network-public-ip-show] command. This public IP address is used in a later command.
12883

129-
```azurecli
130-
FW_PUBLIC_IP="$(az network public-ip show \
131-
--name fw-pip \
132-
--resource-group $RESOURCE_GROUP_NAME \
133-
--query ipAddress --output tsv)"
134-
```
84+
:::code language="azurecli" source="~/azure_cli_scripts/container-instances/egress-ip-address.sh" id="storepublicip":::
13585

13686
## Define user-defined route on ACI subnet
13787

@@ -141,85 +91,39 @@ Define a use-defined route on the ACI subnet, to divert traffic to the Azure fir
14191

14292
First, run the following [az network route-table create][az-network-route-table-create] command to create the route table. Create the route table in the same region as the virtual network.
14393

144-
```azurecli
145-
az network route-table create \
146-
--name Firewall-rt-table \
147-
--resource-group $RESOURCE_GROUP_NAME \
148-
--location eastus \
149-
--disable-bgp-route-propagation true
150-
```
94+
:::code language="azurecli" source="~/azure_cli_scripts/container-instances/egress-ip-address.sh" id="routetable":::
15195

15296
### Create route
15397

15498
Run [az network-route-table route create][az-network-route-table-route-create] to create a route in the route table. To route traffic to the firewall, set the next hop type to `VirtualAppliance`, and pass the firewall's private IP address as the next hop address.
15599

156-
```azurecli
157-
az network route-table route create \
158-
--resource-group $RESOURCE_GROUP_NAME \
159-
--name DG-Route \
160-
--route-table-name Firewall-rt-table \
161-
--address-prefix 0.0.0.0/0 \
162-
--next-hop-type VirtualAppliance \
163-
--next-hop-ip-address $FW_PRIVATE_IP
164-
```
100+
:::code language="azurecli" source="~/azure_cli_scripts/container-instances/egress-ip-address.sh" id="createroute":::
165101

166102
### Associate route table to ACI subnet
167103

168104
Run the [az network vnet subnet update][az-network-vnet-subnet-update] command to associate the route table with the subnet delegated to Azure Container Instances.
169105

170-
```azurecli
171-
az network vnet subnet update \
172-
--name aci-subnet \
173-
--resource-group $RESOURCE_GROUP_NAME \
174-
--vnet-name aci-vnet \
175-
--address-prefixes 10.0.0.0/24 \
176-
--route-table Firewall-rt-table
177-
```
106+
:::code language="azurecli" source="~/azure_cli_scripts/container-instances/egress-ip-address.sh" id="associateroute":::
178107

179108
## Configure rules on firewall
180109

181-
By default, Azure Firewall denies (blocks) inbound and outbound traffic.
110+
By default, Azure Firewall denies (blocks) inbound and outbound traffic.
182111

183112
### Configure NAT rule on firewall to ACI subnet
184113

185114
Create a [NAT rule](../firewall/rule-processing.md) on the firewall to translate and filter inbound internet traffic to the application container you started previously in the network. For details, see [Filter inbound Internet traffic with Azure Firewall DNAT](../firewall/tutorial-firewall-dnat.md)
186115

187116
Create a NAT rule and collection by using the [az network firewall nat-rule create][az-network-firewall-nat-rule-create] command:
188117

189-
```azurecli
190-
az network firewall nat-rule create \
191-
--firewall-name myFirewall \
192-
--collection-name myNATCollection \
193-
--action dnat \
194-
--name myRule \
195-
--protocols TCP \
196-
--source-addresses '*' \
197-
--destination-addresses $FW_PUBLIC_IP \
198-
--destination-ports 80 \
199-
--resource-group $RESOURCE_GROUP_NAME \
200-
--translated-address $ACI_PRIVATE_IP \
201-
--translated-port 80 \
202-
--priority 200
203-
```
118+
:::code language="azurecli" source="~/azure_cli_scripts/container-instances/egress-ip-address.sh" id="natrule":::
204119

205120
Add NAT rules as needed to filter traffic to other IP addresses in the subnet. For example, other container groups in the subnet could expose IP addresses for inbound traffic, or other internal IP addresses could be assigned to the container group after a restart.
206121

207122
### Create outbound application rule on the firewall
208123

209124
Run the following [az network firewall application-rule create][az-network-firewall-application-rule-create] command to create an outbound rule on the firewall. This sample rule allows access from the subnet delegated to Azure Container Instances to the FQDN `checkip.dyndns.org`. HTTP access to the site is used in a later step to confirm the egress IP address from Azure Container Instances.
210125

211-
```azurecli
212-
az network firewall application-rule create \
213-
--collection-name myAppCollection \
214-
--firewall-name myFirewall \
215-
--name Allow-CheckIP \
216-
--protocols Http=80 Https=443 \
217-
--resource-group $RESOURCE_GROUP_NAME \
218-
--target-fqdns checkip.dyndns.org \
219-
--source-addresses 10.0.0.0/24 \
220-
--priority 200 \
221-
--action Allow
222-
```
126+
:::code language="azurecli" source="~/azure_cli_scripts/container-instances/egress-ip-address.sh" id="outboundrule":::
223127

224128
## Test container group access through the firewall
225129

@@ -229,9 +133,7 @@ The following sections verify that the subnet delegated to Azure Container Insta
229133

230134
Test inbound access to the *appcontainer* running in the virtual network by browsing to the firewall's public IP address. Previously, you stored the public IP address in variable $FW_PUBLIC_IP:
231135

232-
```bash
233-
echo $FW_PUBLIC_IP
234-
```
136+
:::code language="azurecli" source="~/azure_cli_scripts/container-instances/egress-ip-address.sh" id="echo":::
235137

236138
Output is similar to:
237139

@@ -248,16 +150,7 @@ If the NAT rule on the firewall is configured properly, you see the following wh
248150

249151
Deploy the following sample container into the virtual network. When it runs, it sends a single HTTP request to `http://checkip.dyndns.org`, which displays the IP address of the sender (the egress IP address). If the application rule on the firewall is configured properly, the firewall's public IP address is returned.
250152

251-
```azurecli
252-
az container create \
253-
--resource-group $RESOURCE_GROUP_NAME \
254-
--name testegress \
255-
--image mcr.microsoft.com/azuredocs/aci-tutorial-sidecar \
256-
--command-line "curl -s http://checkip.dyndns.org" \
257-
--restart-policy OnFailure \
258-
--vnet aci-vnet \
259-
--subnet aci-subnet
260-
```
153+
:::code language="azurecli" source="~/azure_cli_scripts/container-instances/egress-ip-address.sh" id="egress":::
261154

262155
View the container logs to confirm the IP address is the same as the public IP address of the firewall.
263156

0 commit comments

Comments
 (0)