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
- Receive and respond to external requests by using the CLB.
- Add the CVM to the subnet of the VPC 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 outbound access.
Step 1: create a VPC and subnet
1. Create a VPC
- Log in to the VPC console and select VPC in the left sidebar.
- At the top of the “VPC” page, select a region, such as “North China (Beijing)”.
- Click +Create. 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.
2. 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 +Create and, 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
1. Create a NAT gateway
- In the VPC console, select NAT Gateway in the left sidebar.
- On the NAT Gateway page, click +Create.
- In the Create a 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 to complete the creation of the NAT gateway.
After the NAT gateway is created, you need to configure the routing rules on the route table page in the VPC console to redirect the subnet traffic to the NAT gateway.
2. Set the route table (key)
- In the VPC Console, select Route Table in the left sidebar.
- On the Route Table page, select the route table ID 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 ID created in Step 1.
- Click Create. Now, even without a public IP address, your CVM in this subnet 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 the NAT gateway IP as the static IP to access internet.
- Log in to the Auto Scaling console and select Scaling Groups in the left sidebar.
- On the Scaling Groups page, click Create.
- On the Create a Scaling Group page that pops up, enter the scaling group name, the created launch configuration, maximum scaling capacity, minimum scaling capacity, initial number of instances, and other information.
In Supported Network and Supported Subnet, select the VPC and subnet you just set up, as shown in the following figure:
This completes the configuration.