kelseyhightower / kubernetes-the-hard-way

Bootstrap Kubernetes the hard way. No scripts.
Apache License 2.0
40.83k stars 13.98k forks source link

Kubernetes Workers pod-cidr / cluster-cidr range #500

Open devdattakulkarni opened 4 years ago

devdattakulkarni commented 4 years ago

In the Kubernetes workers section https://github.com/kelseyhightower/kubernetes-the-hard-way/blob/master/docs/03-compute-resources.md#kubernetes-workers

there is following line: "The Kubernetes cluster CIDR range is defined by the Controller Manager's --cluster-cidr flag. In this tutorial the cluster CIDR range will be set to 10.200.0.0/16, which supports 254 subnets."

Should the CIDR range be: 10.200.0.0/24 ?

Tethik commented 4 years ago

I don't think so. As I understood it each worker instance hosts it's own 10.200.X.0/24 subnet for containers. Later on in the guide we set up route tables having each worker as the router for it's subnet:

for i in 0 1 2; do
  gcloud compute routes create kubernetes-route-10-200-${i}-0-24 \
    --network kubernetes-the-hard-way \
    --next-hop-address 10.240.0.2${i} \
    --destination-range 10.200.${i}.0/24
done

Relevant section

I'm still learning though, so if anyone knows better please correct me :)

devdattakulkarni commented 4 years ago

May be you are correct. I still find the explanation in the Kubernetes Worker section bit confusing.

https://github.com/kelseyhightower/kubernetes-the-hard-way/blob/master/docs/03-compute-resources.md#kubernetes-workers

Specifically, two things:

  1. The section mentions --cluster-cidr flag. But it is not shown to be used anywhere.
  2. The CIDR range /16 will be 65536 subnets and not 254.
Tethik commented 4 years ago
  1. I had to dig a bit, but I found a reference to the --cluster-cidr flag in a systemd file. It's used when starting the kubernetes-controller-manager service: https://github.com/kelseyhightower/kubernetes-the-hard-way/blob/master/docs/08-bootstrapping-kubernetes-controllers.md#configure-the-kubernetes-controller-manager

  2. /16 is max 65536 subnets, but then you'd be using /31 subnets (?) which would be a bit odd. I guess what they mean here is 254 /24 subnets.

So the explanation does make sense, but could maybe be improved.