Service CIDR and ClusterIP Allocation

You create a Service with no clusterIP set, and it still gets a virtual IP no other Service holds. Who picks it, what stops two Services from landing on one address, and what happens when the range fills up?

Play the animation 4 steps, animated, plays on a computer or a tablet

Service CIDR and ClusterIP Allocation diagram: Service CIDR and ClusterIP allocation, where one ServiceCIDR object declares the Service

Service CIDR and ClusterIP Allocation, step by step

  1. One ServiceCIDR object declares the whole Service range, here 10.96.0.0/16, and the allocator reads it as two bands. Automatic allocation takes the high dynamic band first and the low static band only once that runs out. The low band is for addresses picked by hand, so the two in it are not reserved, only unlikely to be taken.

    Play from step 1
  2. A new Service web is created with an empty clusterIP field, so the API server hands the request to the ClusterIP allocator. The allocator looks in the high dynamic band, which is tried first for every automatic address, and takes a free one, here 10.96.137.42.

    Play from step 2
  3. Allocating means writing an object. The allocator creates an IPAddress object named 10.96.137.42 that points back at the Service, and only once that object exists is the clusterIP field set. Two Services cannot end up on one address, because two objects cannot share one name.

    Play from step 3
  4. When the range fills up, the old fix was to widen the service-cluster-ip-range flag and restart the API server, which was disruptive. Now you add a second ServiceCIDR object, here 10.97.0.0/16, which gives the allocator a second range to draw from, and the Service IP space grows with nothing restarted.

    Play from step 4

Sources