Skip to main content

Why is changing my Service from LoadBalancer to NodePort or ClusterIP rejected?

Syself support For release

The cloud controller manager writes the load balancer's address into spec.loadBalancerSourceRanges of every type: LoadBalancer Service. The API server allows that field only on LoadBalancer Services, so a change of the type alone is rejected:

plaintext
				spec.LoadBalancerSourceRanges: Forbidden: may only be used when type is 'LoadBalancer'
			

There are two ways to change the type.

Remove the field in the same request:

plaintext
				kubectl -n <namespace> patch service <name> --type merge \
  -p '{"spec":{"type":"ClusterIP","loadBalancerSourceRanges":null}}'
			

Or turn the restriction off first. The cloud controller manager removes its entry within about 10 seconds, and then the type change goes through, also with kubectl apply:

plaintext
				kubectl -n <namespace> annotate service <name> load-balancer.hetzner.cloud/restrict-node-port-source=false
			

If you added entries of your own to loadBalancerSourceRanges, remove them too.

In both cases the cloud controller manager deletes the Hetzner load balancer, and its address is gone unless it is a Primary IP.

For the background, see Limit the NodePort to the load balancer.

Still stuck?

Prepare your case, then email us.