Pods scheduled to a node receive an IP address from the node's Pod CIDR range. At this point pods can not communicate with other pods running on different nodes due to missing network routes.
In this lab you will create a route for each worker node that maps the node's Pod CIDR range to the node's internal IP address.
There are other ways to implement the Kubernetes networking model.
In this section you will gather the information required to create routes in the kubernetes-the-hard-way
VPC network and use that to create route table entries.
In production workloads this functionality will be provided by CNI plugins like flannel, calico, amazon-vpc-cni-k8s. Doing this by hand makes it easier to understand what those plugins do behind the scenes.
Print the internal IP address and Pod CIDR range for each worker instance and create route table entries:
for instance in worker-0 worker-1 worker-2; do
instance_id_ip="$(aws ec2 describe-instances \
--filters "Name=tag:Name,Values=${instance}" \
--output text --query 'Reservations[].Instances[].[InstanceId,PrivateIpAddress]')"
instance_id="$(echo "${instance_id_ip}" | cut -f1)"
instance_ip="$(echo "${instance_id_ip}" | cut -f2)"
pod_cidr="$(aws ec2 describe-instance-attribute \
--instance-id "${instance_id}" \
--attribute userData \
--output text --query 'UserData.Value' \
| base64 --decode | tr "|" "\n" | grep "^pod-cidr" | cut -d'=' -f2)"
echo "${instance_ip} ${pod_cidr}"
aws ec2 create-route \
--route-table-id "${ROUTE_TABLE_ID}" \
--destination-cidr-block "${pod_cidr}" \
--instance-id "${instance_id}"
done
output
10.240.0.20 10.200.0.0/24
{
"Return": true
}
10.240.0.21 10.200.1.0/24
{
"Return": true
}
10.240.0.22 10.200.2.0/24
{
"Return": true
}
Validate network routes for each worker instance:
aws ec2 describe-route-tables \
--route-table-ids "${ROUTE_TABLE_ID}" \
--query 'RouteTables[].Routes'
output
[
[
{
"DestinationCidrBlock": "10.200.0.0/24",
"InstanceId": "i-0879fa49c49be1a3e",
"InstanceOwnerId": "107995894928",
"NetworkInterfaceId": "eni-0612e82f1247c6282",
"Origin": "CreateRoute",
"State": "active"
},
{
"DestinationCidrBlock": "10.200.1.0/24",
"InstanceId": "i-0db245a70483daa43",
"InstanceOwnerId": "107995894928",
"NetworkInterfaceId": "eni-0db39a19f4f3970f8",
"Origin": "CreateRoute",
"State": "active"
},
{
"DestinationCidrBlock": "10.200.2.0/24",
"InstanceId": "i-0b93625175de8ee43",
"InstanceOwnerId": "107995894928",
"NetworkInterfaceId": "eni-0cc95f34f747734d3",
"Origin": "CreateRoute",
"State": "active"
},
{
"DestinationCidrBlock": "10.240.0.0/24",
"GatewayId": "local",
"Origin": "CreateRouteTable",
"State": "active"
},
{
"DestinationCidrBlock": "0.0.0.0/0",
"GatewayId": "igw-00d618a99e45fa508",
"Origin": "CreateRoute",
"State": "active"
}
]
]