This document shows how to set a static IP address for outbound access of a cluster.
This solution is applicable when clusters in your scaling group have all the three requirements below:
- To receive requests from CLB
- To initiate outbound access
- To use a static public IP address for outbound access
See the following content for details.
- Receive and respond to external requests by using the CLB.
- Add the CVM to the VPC subnet and direct the route table to the NAT Gateway so that all outbound access requests are delivered via the public IP address of the NAT Gateway.
- The network attribute of the scaling group is set as this subnet, so that all CVMs created for scale-out will use the NAT Gateway for the outbound access.
Step 1: create a VPC and subnet
Create a VPC
- Log in to the VPC console and select Virtual Private Cloud in the left sidebar.
- At the top of the VPC page, select a region, such as “North China (Beijing)”.
- Click +New. In the Create VPC window that pops up, enter the names and CIDR blocks of the VPC and subnet, and choose the availability zone of the subnet.
- Click OK to create the VPC.
Create a subnet
- In the VPC console, select Subnet in the left sidebar.
- At the top of the Subnet page, select the region and VPC, as shown in the following figure:
- Click +New. In the Create a Subnet window that pops up, enter the subnet name, CIDR block, availability zone, and associated route table.
- Click Create. After completing creation, you can purchase CVMs and add them to this subnet.
Step 2: create a NAT Gateway
Create a NAT Gateway
- In the VPC console, select NAT Gateway in the left sidebar.
- On the NAT Gateway page, click +New.
- In the Create NAT Gateway window that pops up, input or confirm the following parameters in sequence:
- Gateway name
- Gateway type (which can be modified after creation)
- VPC of the NAT gateway (the VPC created in Step 1).
- Assign an EIP for the NAT Gateway. (This IP address is the static IP address for your CVM’s outbound access.)
- After completing the configuration, click Create.
After the NAT Gateway is created, you need to configure the routing policy on the route table page in the VPC console to redirect the subnet traffic to the NAT Gateway.
Set the route table (key step)
- In the VPC console, select Route Tables in the left sidebar.
- On the Route table page, select theID/Name of the route table associated with the subnet that needs to access the Internet. The details page of the route table will be displayed.
- Click + New routing policies. In the Add a route window that pops up, complete the configuration, as shown in the following figure:
- Destination: in this case, you can enter
- Next hop type: select NAT Gateway and select the NAT Gateway created in Step 1.
- Click Create. Now, your CVM in this subnet which does not have a public IP address can also access internet through the static IP of the NAT Gateway.
Even if you purchase a CVM without any public IP addresses and with a bandwidth of zero, you still can enjoy active external access, as shown in the following figure:
The scaling group needs to identify this subnet and ensure that all the CVMs are created on this subnet.
Step 3: set up the scaling group
This step aims to direct the subnet information to the scaling group so that the newly created CVMs of the scaling group can be deployed in this subnet. In this way, the newly created CVMs will use the NAT Gateway IP as the static IP to access internet.
- Log in to the Auto Scaling console and click Scaling group in the left sidebar.
- On the Scaling group page, click Create.
- On the Create scaling group page that pops up, enter the scaling group name, the created launch configuration, max capacity, min capacity, initial capacity, and other information.
In Supported Networks and Support subnet, select the VPC and subnet you just set up, as shown in the following figure:
Click Next to complete the configuration.