Creating and Tagging the Subnets
In this section, you will create one private and one public subnet for each of the three availability zones, for a total of six subnets. Each availability zone requires one private and one public subnet to support high availability.
Each subnet must meet the following criteria:
- Each subnet comes from the VPC IP range.
- Subnets must not overlap one another.
All six subnets will be created in the same way. They will be distinguished based on the:
-
Route table
-
Internet gateway
-
NAT gateway attachments
Before proceeding, make sure you have completed your AWS worksheet with your subnet names, CIDRs, and availability zones.
Creating a Subnet
- Retrieve the availability zone names by running the following command:
# aws ec2 describe-availability-zones \
| jq -r '.AvailabilityZones[ ].ZoneName'
Example output:
eu-central-1a
eu-central-1b
eu-central-1c
- Create the first subnet by running the following command, which will output the subnet ID:
# aws ec2 create-subnet \
--availability-zone <availability zone> \
--cidr-block <CIDR> --vpc-id <VpcId> | jq -r '.Subnet.SubnetId'
For example:
# aws ec2 create-subnet \ --availability-zone eu-central-1a \ --cidr-block 10.0.1.0/24 \ --vpc-id vpc-0143197ca9bd9c117 | jq -r '.Subnet.SubnetId'
subnet-06a8caab19022c544
- Repeat Step 2 for all rows from the subnet planning table in the AWS worksheet.
You should now tag the new subnets to differentiate between public and private subnets, as well as tag the private subnets for load balancing.
Tagging the Subnets
- Tag each public subnet by running the following command for each public subnet:
- Tag each private subnet by running this command for each private subnet:
<public/private subnet id>:
The value from column Subnet ID in your planning table on the AWS worksheet.<public/private subnet name>:
The value from column Subnet name in your planning table on the AWS worksheet.
# aws ec2 create-tags \
--resources <public subnet id> \
--tags Key=Name,Value=<subnet name>
# aws ec2 create-tags \
--resources <private subnet id> \
--tags Key=Name,Value=<subnet name> Key=kubernetes.io/role/internal-elb,Value=1
Where:
For example:
# aws ec2 create-tags \ --resources subnet-06a8caab19022c544 \ --tags Key=Name,Value=srgdemo-public-subnet-1
# aws ec2 create-tags \ --resources subnet-0fb2ebb5882c061f0 \ --tags Key=Name,Value=srgdemo-private-subnet-1 Key=kubernetes.io/role/internal-elb,Value=1
Next Step: Creating the Internet Gateway