Skip to content

Commit f0c6c88

Browse files
committed
use code blocks from new file
1 parent 3847995 commit f0c6c88

File tree

1 file changed

+34
-76
lines changed

1 file changed

+34
-76
lines changed

articles/container-instances/container-instances-nat-gateway.md

Lines changed: 34 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -17,130 +17,88 @@ This article provides steps to configure a container group in a [virtual network
1717

1818
In this article you use the Azure CLI to create the resources for this scenario:
1919

20-
* Container groups deployed on a delegated subnet [in the virtual network](container-instances-vnet.md)
20+
* Container groups deployed on a delegated subnet [in the virtual network](container-instances-vnet.md)
2121
* A NAT gateway deployed in the network with a static public IP address
2222

2323
You then validate egress from example container groups through the NAT gateway.
2424

2525
> [!NOTE]
26-
> The ACI service recommends integrating with a NAT gateway for containerized workoads that have static egress but not static ingress requirements. For ACI architecture that supports both static ingress and egress, please see the following tutorial: [Use Azure Firewall for ingress and egress](container-instances-egress-ip-address.md).
27-
## Before you begin
28-
You must satisfy the following requirements to complete this tutorial:
26+
> The ACI service recommends integrating with a NAT gateway for containerized workloads that have static egress but not static ingress requirements. For ACI architecture that supports both static ingress and egress, please see the following tutorial: [Use Azure Firewall for ingress and egress](container-instances-egress-ip-address.md).
2927
30-
**Azure CLI**: You must have Azure CLI version installed on your local computer. If you need to install or upgrade, see [Install the Azure CLI][azure-cli-install]
28+
[!INCLUDE [quickstarts-free-trial-note](../../includes/quickstarts-free-trial-note.md)]
29+
30+
[!INCLUDE [azure-cli-prepare-your-environment.md](../../includes/azure-cli-prepare-your-environment.md)]
31+
32+
[!INCLUDE [cli-launch-cloud-shell-sign-in.md](../../includes/cli-launch-cloud-shell-sign-in.md)]
33+
34+
## Get started
35+
36+
:::code language="azurecli" source="~/azure_cli_scripts/container-instances/nat-gateway.sh" id="variable":::
37+
38+
This tutorial will make use of this randomized variable value going forward. If you are using an existing resource group, modify this value of this variable.
39+
40+
**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.
41+
42+
:::code language="azurecli" source="~/azure_cli_scripts/container-instances/nat-gateway.sh" id="creategroup":::
3143

32-
**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. Below is an example.
33-
```azurecli
34-
az group create --name myResourceGroup --location eastus
35-
```
3644
## Deploy ACI in a virtual network
3745

38-
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.
46+
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.
3947

4048
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.
4149

42-
> [!TIP]
43-
> To simplify the following command examples, use an environment variable for the resource group's name:
44-
> ```console
45-
> export RESOURCE_GROUP_NAME=myResourceGroup
46-
> ```
47-
> This tutorial will make use of the environment variable going forward.
4850
Create the container group with the [az container create][az-container-create] command:
4951

50-
```azurecli
51-
az container create \
52-
--name appcontainer \
53-
--resource-group $RESOURCE_GROUP_NAME \
54-
--image mcr.microsoft.com/azuredocs/aci-helloworld \
55-
--vnet aci-vnet \
56-
--vnet-address-prefix 10.0.0.0/16 \
57-
--subnet aci-subnet \
58-
--subnet-address-prefix 10.0.0.0/24
59-
```
52+
:::code language="azurecli" source="~/azure_cli_scripts/container-instances/nat-gateway.sh" id="container":::
6053

6154
> [!NOTE]
62-
> 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, which you can read more about [here](../virtual-network/ip-services/private-ip-addresses.md).
55+
> 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, which you can read more about [here](../virtual-network/ip-services/private-ip-addresses.md).
56+
6357
## Create a public IP address
6458

6559
In the following sections, use the Azure CLI to deploy an Azure NAT gateway in the virtual network. For background, see [Tutorial: Create a NAT gateway using Azure CLI](../virtual-network/nat-gateway/tutorial-create-nat-gateway-cli.md).
6660

67-
First, use the [az network vnet public-ip create][az-network-public-ip-create] to create a public IP address for the NAT gateway. This will be used to access the Internet. You will receive a warning about an upcoming breaking change where Standard SKU IP addresses will be availability zone aware by default. You can learn more about the use of availability zones and public IP addresses [here](../virtual-network/ip-services/virtual-network-network-interface-addresses.md).
61+
First, use the [az network vnet public-ip create][az-network-public-ip-create] to create a public IP address for the NAT gateway. This will be used to access the Internet. You will receive a warning about an upcoming breaking change where Standard SKU IP addresses will be availability zone aware by default. You can learn more about the use of availability zones and public IP addresses [here](../virtual-network/ip-services/virtual-network-network-interface-addresses.md).
6862

69-
```azurecli
70-
az network public-ip create \
71-
--name myPublicIP \
72-
--resource-group $RESOURCE_GROUP_NAME \
73-
--sku standard \
74-
--allocation static
75-
```
63+
:::code language="azurecli" source="~/azure_cli_scripts/container-instances/nat-gateway.sh" id="publicip":::
7664

77-
Store the public IP address in a variable. We will use this later during the validation step.
65+
Store the public IP address in a variable. We will use this later during the validation step.
7866

79-
```azurecli
80-
NG_PUBLIC_IP="$(az network public-ip show \
81-
--name myPublicIP \
82-
--resource-group $RESOURCE_GROUP_NAME \
83-
--query ipAddress --output tsv)"
84-
```
67+
:::code language="azurecli" source="~/azure_cli_scripts/container-instances/nat-gateway.sh" id="storeip":::
8568

8669
## Deploy a NAT gateway into a virtual network
8770

8871
Use the following [az network nat gateway create][az-network-nat-gateway-create] to create a NAT gateway that uses the public IP you created in the previous step.
8972

90-
```azurecli
91-
az network nat gateway create \
92-
--resource-group $RESOURCE_GROUP_NAME \
93-
--name myNATgateway \
94-
--public-ip-addresses myPublicIP \
95-
--idle-timeout 10
96-
```
73+
:::code language="azurecli" source="~/azure_cli_scripts/container-instances/nat-gateway.sh" id="natgateway":::
74+
9775
## Configure NAT service for source subnet
9876

99-
We'll configure the source subnet **aci-subnet** to use a specific NAT gateway resource **myNATgateway** with [az network vnet subnet update][az-network-vnet-subnet-update]. This command will activate the NAT service on the specified subnet.
77+
We'll configure the source subnet **aci-subnet** to use a specific NAT gateway resource **myNATgateway** with [az network vnet subnet update][az-network-vnet-subnet-update]. This command will activate the NAT service on the specified subnet.
10078

101-
```azurecli
102-
az network vnet subnet update \
103-
--resource-group $RESOURCE_GROUP_NAME \
104-
--vnet-name aci-vnet \
105-
--name aci-subnet \
106-
--nat-gateway myNATgateway
107-
```
79+
:::code language="azurecli" source="~/azure_cli_scripts/container-instances/nat-gateway.sh" id="subnet":::
10880

10981
## Test egress from a container group
11082

11183
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 $NG_PUBLIC_IP
11284

11385
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.
11486

115-
```azurecli
116-
az container create \
117-
--resource-group $RESOURCE_GROUP_NAME \
118-
--name testegress \
119-
--image mcr.microsoft.com/azuredocs/aci-tutorial-sidecar \
120-
--command-line "curl -s http://checkip.dyndns.org" \
121-
--restart-policy OnFailure \
122-
--vnet aci-vnet \
123-
--subnet aci-subnet
124-
```
87+
:::code language="azurecli" source="~/azure_cli_scripts/container-instances/nat-gateway.sh" id="sidecar":::
12588

12689
View the container logs to confirm the IP address is the same as the public IP address we created in the first step of the tutorial.
12790

128-
```azurecli
129-
az container logs \
130-
--resource-group $RESOURCE_GROUP_NAME \
131-
--name testegress
132-
```
91+
:::code language="azurecli" source="~/azure_cli_scripts/container-instances/nat-gateway.sh" id="viewlogs":::
13392

13493
Output is similar to:
13594

13695
```console
13796
<html><head><title>Current IP Check</title></head><body>Current IP Address: 52.142.18.133</body></html>
13897
```
139-
This IP address should match the public IP address created in the first step of the tutorial.
14098

141-
```Bash
142-
echo $NG_PUBLIC_IP
143-
```
99+
This IP address should match the public IP address created in the first step of the tutorial.
100+
101+
:::code language="azurecli" source="~/azure_cli_scripts/container-instances/nat-gateway.sh" id="echo":::
144102

145103
## Next steps
146104

0 commit comments

Comments
 (0)