kubernetes-the-hard-way/docs/08-network.md

62 lines
2.0 KiB
Markdown
Raw Normal View History

2016-07-07 22:23:30 +03:00
# Managing the Container Network Routes
2016-07-07 22:43:10 +03:00
Now that each worker node is online we need to add routes to make sure that Pods running on different machines can talk to each other. In this lab we are not going to provision any overlay networks and instead rely on Layer 3 networking. That means we need to add routes to our router. In GCP each network has a router that can be configured. If this was an on-prem datacenter then ideally you would need to add the routes to your local router.
2016-07-07 22:41:32 +03:00
2016-09-11 17:18:44 +03:00
## Container Subnets
2017-03-25 21:50:26 +03:00
The IP addresses for each pod will be allocated from the `podCIDR` range assigned to each Kubernetes worker through the node registration process. The `podCIDR` will be allocated from the cluster cidr range as configured on the Kubernetes Controller Manager with the following flag:
2016-09-11 17:18:44 +03:00
```
--cluster-cidr=10.200.0.0/16
```
Based on the above configuration each node will receive a `/24` subnet. For example:
```
10.200.0.0/24
10.200.1.0/24
10.200.2.0/24
...
```
2016-07-07 22:43:47 +03:00
## Get the Routing Table
2016-07-07 22:23:30 +03:00
2016-07-07 22:41:32 +03:00
The first thing we need to do is gather the information required to populate the router table. We need the Internal IP address and Pod Subnet for each of the worker nodes.
Use `kubectl` to print the `InternalIP` and `podCIDR` for each worker node:
2016-07-07 22:23:30 +03:00
```
kubectl get nodes \
2016-07-07 22:41:32 +03:00
--output=jsonpath='{range .items[*]}{.status.addresses[?(@.type=="InternalIP")].address} {.spec.podCIDR} {"\n"}{end}'
2016-07-07 22:23:30 +03:00
```
2016-07-07 22:41:32 +03:00
Output:
2016-07-07 22:23:30 +03:00
```
2016-09-27 15:23:35 +03:00
10.240.0.20 10.200.0.0/24
10.240.0.21 10.200.1.0/24
10.240.0.22 10.200.2.0/24
2016-07-07 22:23:30 +03:00
```
2016-09-11 14:08:38 +03:00
## Create Routes
2016-07-07 22:23:30 +03:00
```
2016-07-08 20:26:32 +03:00
gcloud compute routes create kubernetes-route-10-200-0-0-24 \
2017-03-25 21:50:26 +03:00
--network kubernetes-the-hard-way \
2016-09-27 15:23:35 +03:00
--next-hop-address 10.240.0.20 \
2016-07-07 22:23:30 +03:00
--destination-range 10.200.0.0/24
2016-07-07 22:41:32 +03:00
```
```
2016-07-08 20:26:32 +03:00
gcloud compute routes create kubernetes-route-10-200-1-0-24 \
2017-03-25 21:50:26 +03:00
--network kubernetes-the-hard-way \
2016-09-27 15:23:35 +03:00
--next-hop-address 10.240.0.21 \
2016-07-07 22:41:32 +03:00
--destination-range 10.200.1.0/24
```
```
2016-07-08 20:26:32 +03:00
gcloud compute routes create kubernetes-route-10-200-2-0-24 \
2017-03-25 21:50:26 +03:00
--network kubernetes-the-hard-way \
2016-09-27 15:23:35 +03:00
--next-hop-address 10.240.0.22 \
2016-07-07 22:41:32 +03:00
--destination-range 10.200.2.0/24
2017-03-26 00:20:31 +03:00
```